]> granicus.if.org Git - yasm/commitdiff
Allow underscores in the middle of binary, octal, and hex constants.
authorPeter Johnson <peter@tortall.net>
Sat, 12 Apr 2008 08:30:22 +0000 (08:30 -0000)
committerPeter Johnson <peter@tortall.net>
Sat, 12 Apr 2008 08:30:22 +0000 (08:30 -0000)
This makes things like 00_11_22_33h okay.
Allow 0X as well as 0x in directives (already allowed for normal case).

svn path=/trunk/yasm/; revision=2063

libyasm/bitvect.c
modules/parsers/nasm/nasm-token.re
modules/parsers/nasm/tests/Makefile.inc
modules/parsers/nasm/tests/uscore.asm [new file with mode: 0644]
modules/parsers/nasm/tests/uscore.hex [new file with mode: 0644]

index 49f19b2611e9e65e9f24a1f905fbbde71345a8e7..57ad6133d8736176d5a1427121f54e6fe92e47ae 100644 (file)
@@ -1511,7 +1511,9 @@ ErrCode BitVector_from_Hex(wordptr addr, charptr string)
                 digit = (int) *(--string); length--;
                 /* separate because toupper() is likely a macro! */
                 digit = toupper(digit);
-                if ((ok = (isxdigit(digit) != 0)))
+                if (digit == '_')
+                    count -= 4;
+                else if ((ok = (isxdigit(digit) != 0)))
                 {
                     if (digit >= (int) 'A') digit -= (int) 'A' - 10;
                     else                    digit -= (int) '0';
@@ -1548,7 +1550,9 @@ ErrCode BitVector_from_Oct(wordptr addr, charptr string)
             for ( count = count_fill; (ok and (length > 0) and (count < BITS)); count += 3 )
             {
                 digit = (int) *(--string); length--;
-                if ((ok = (isdigit(digit) && digit != '8' && digit != '9')) != 0)
+                if (digit == '_')
+                    count -= 3;
+                else if ((ok = (isdigit(digit) && digit != '8' && digit != '9')) != 0)
                 {
                     digit -= (int) '0';
                     value |= (((N_word) digit) << count);
@@ -1628,6 +1632,9 @@ ErrCode BitVector_from_Bin(wordptr addr, charptr string)
                     case (int) '1':
                         value |= BITMASKTAB[count];
                         break;
+                    case (int) '_':
+                        count--;
+                        break;
                     default:
                         ok = FALSE;
                         break;
index a10694590b5919c8a5b0f0683732f33f684fe14e..931dbdc4547ccbbb2e91c64b1799888e9675506d 100644 (file)
@@ -63,9 +63,9 @@ static int linechg_numcount;
   any = [\001-\377];
   digit = [0-9];
   iletter = [a-zA-Z];
-  bindigit = [01];
-  octdigit = [0-7];
-  hexdigit = [0-9a-fA-F];
+  bindigit = [01_];
+  octdigit = [0-7_];
+  hexdigit = [0-9a-fA-F_];
   ws = [ \t\r];
   quot = ["'];
 */
@@ -151,14 +151,14 @@ scan:
         }
         /* 10010011b - binary number */
 
-        bindigit+ 'b' {
+        [01] bindigit* 'b' {
             s->tok[TOKLEN-1] = '\0'; /* strip off 'b' */
             lvalp->intn = yasm_intnum_create_bin(TOK);
             RETURN(INTNUM);
         }
 
         /* 777q or 777o - octal number */
-        octdigit+ [qQoO] {
+        [0-7] octdigit* [qQoO] {
             s->tok[TOKLEN-1] = '\0'; /* strip off 'q' or 'o' */
             lvalp->intn = yasm_intnum_create_oct(TOK);
             RETURN(INTNUM);
@@ -541,14 +541,14 @@ directive2:
         }
         /* 10010011b - binary number */
 
-        bindigit+ 'b' {
+        [01] bindigit* 'b' {
             s->tok[TOKLEN-1] = '\0'; /* strip off 'b' */
             lvalp->intn = yasm_intnum_create_bin(TOK);
             RETURN(INTNUM);
         }
 
         /* 777q or 777o - octal number */
-        octdigit+ [qQoO] {
+        [0-7] octdigit* [qQoO] {
             s->tok[TOKLEN-1] = '\0'; /* strip off 'q' or 'o' */
             lvalp->intn = yasm_intnum_create_oct(TOK);
             RETURN(INTNUM);
@@ -562,10 +562,10 @@ directive2:
         }
 
         /* $0AA and 0xAA forms of hexidecimal number */
-        (("$" digit) | "0x") hexdigit+ {
+        (("$" digit) | '0x') hexdigit+ {
             savech = s->tok[TOKLEN];
             s->tok[TOKLEN] = '\0';
-            if (s->tok[1] == 'x')
+            if (s->tok[1] == 'x' || s->tok[1] == 'X')
                 /* skip 0 and x */
                 lvalp->intn = yasm_intnum_create_hex(TOK+2);
             else
index c9115e943d5828fb7a17ea66fdfe322a2868feb1..f4589c3c41a9984705cdc7a3ca5cbd46243c7f0d 100644 (file)
@@ -38,6 +38,8 @@ EXTRA_DIST += modules/parsers/nasm/tests/struczero.asm
 EXTRA_DIST += modules/parsers/nasm/tests/struczero.hex
 EXTRA_DIST += modules/parsers/nasm/tests/syntax-err.asm
 EXTRA_DIST += modules/parsers/nasm/tests/syntax-err.errwarn
+EXTRA_DIST += modules/parsers/nasm/tests/uscore.asm
+EXTRA_DIST += modules/parsers/nasm/tests/uscore.hex
 
 EXTRA_DIST += modules/parsers/nasm/tests/worphan/Makefile.inc
 
diff --git a/modules/parsers/nasm/tests/uscore.asm b/modules/parsers/nasm/tests/uscore.asm
new file mode 100644 (file)
index 0000000..0630597
--- /dev/null
@@ -0,0 +1,10 @@
+dq 0000_1111_2222_3333h
+dq 0000111122223333h
+dd 0x01_23_45_67
+dd 0x01234567
+dw 1_2_3_4q
+dw 1234q
+db 00_11_00_11b
+db 00110011b
+_0:
+dw _0
diff --git a/modules/parsers/nasm/tests/uscore.hex b/modules/parsers/nasm/tests/uscore.hex
new file mode 100644 (file)
index 0000000..4793d1d
--- /dev/null
@@ -0,0 +1,32 @@
+33 
+33 
+22 
+22 
+11 
+11 
+00 
+00 
+33 
+33 
+22 
+22 
+11 
+11 
+00 
+00 
+67 
+45 
+23 
+01 
+67 
+45 
+23 
+01 
+9c 
+02 
+9c 
+02 
+33 
+33 
+1e 
+00