comparison test/parser.tst @ 28583:96e7dc4c2214

improve Matlab compatibility for binary and hexadecimal constants * parser.tst: Update tests for new parsing rules for hex and binary integer literals. * lex.h, lex.ll (handle_number): Now a template with three specializations (binary, decimal, hexadecimal). Eliminate IMAG argument. (HANDLE_NUMBER): New macro. Use it to process binary, decimal, and hexadecimal constants with separate lexer patterns. (Im): Delete pattern macro. (EXPON, NUMBIN, NUMHEX, NUMREAL, NUMBER): Replace with DECIMAL_DIGITS, EXPONENT, REAL_DECIMAL, IMAG_DECIMAL, and DECIMAL_NUMBER for matching decimal numbers and SIZE_SUFFIX, BINARY_BITS, BINARY_NUMBER, HEXADECIMAL_BITS, and HEXADECIMAL_NUMBER for matching binary and hexadecimal numbers. ({NUMBER}{Im}): Delete rule. ({BINARY_NUMBER}, {HEXADECIMAL_NUMBER}): New rules. ({DECIMAL_DIGITS}/\.[\*/\\^\']|{DECIMAL_NUMBER}): New rule to replace {D}{D_}*/\.[\*/\\^\']|{NUMBER}. (make_integer_value): New static function. NEWS: Note change.
author John W. Eaton <jwe@octave.org>
date Thu, 16 Jul 2020 18:27:39 -0400
parents bd51beb6205e
children ec591c500fa4
comparison
equal deleted inserted replaced
28582:dc8de424fc72 28583:96e7dc4c2214
284 284
285 ## Test extended number format which allows '_' as NOP character 285 ## Test extended number format which allows '_' as NOP character
286 %!assert (123_456, 123456) 286 %!assert (123_456, 123456)
287 %!assert (.123_456, .123456) 287 %!assert (.123_456, .123456)
288 %!assert (123_456.123_456, 123456.123456) 288 %!assert (123_456.123_456, 123456.123456)
289 %!assert (0xAB_CD, 43981) 289 %!assert (0xAB_CD, uint16 (43981))
290 %!assert (2e0_1, 20) 290 %!assert (2e0_1, 20)
291 291
292 ## Test binary constants 292 ## Test binary constants
293 %!assert (0b101, 5) 293 %!assert (0b101, uint8 (5))
294 %!assert (0B1100_0001, 0xC1) 294 %!assert (0B1100_0001, 0xC1)
295 %!assert (class (0b1), "double") 295 %!assert (class (0b1), "uint8")
296 296
297 ## Test range of large binary and hexadecimal literals 297 ## Test range of large binary and hexadecimal literals
298 %!assert (0x8000_0000_0000_0000, 2^63) 298 %!assert (0x8000_0000_0000_0000, uint64 (2^63))
299 %!assert (0xFFFF_FFFF_FFFF_FFFF, 2^64) 299 %!assert (0xFFFF_FFFF_FFFF_FFFF, uint64 (2^64))
300 %!assert (0b10000000_0000000_000000000_00000000_00000000_00000000_00000000_00000000, 2^63) 300 %!assert (0b10000000_0000000_000000000_00000000_00000000_00000000_00000000_00000000, uint64 (2^63))
301 %!assert (0b11111111_1111111_111111111_11111111_11111111_11111111_11111111_11111111, 2^64) 301 %!assert (0b11111111_1111111_111111111_11111111_11111111_11111111_11111111_11111111, uint64 (2^64))
302 302
303 ## Test creation of anonymous functions 303 ## Test creation of anonymous functions
304 304
305 %!test 305 %!test
306 %! af_in_cell = {@(x) [1 2]}; 306 %! af_in_cell = {@(x) [1 2]};