src/parser: Updated grammar and parser_nodes
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 25 May 2015 20:32:39 +0000 (16:32 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Tue, 26 May 2015 15:43:23 +0000 (11:43 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

src/parser/nit.sablecc3xx
src/parser/parser_nodes.nit

index eb80d5f..4a90050 100644 (file)
@@ -27,7 +27,9 @@ all = [0 .. 0xFF];
 lowercase = ['a' .. 'z'];
 uppercase = ['A' .. 'Z'];
 digit = ['0' .. '9'];
-hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
+hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'] | '_';
+bindigit = '0' | '1' | '_';
+octdigit = ['0' .. '7'] | '_';
 letter = lowercase | uppercase | digit | '_';
 
 tab = 9;
@@ -199,6 +201,8 @@ attrid = '_' lowercase letter*;
 
 number = digit+;
 hex_number = ('0x' | '0X') hexdigit+;
+bin_number = ('0b' | '0B') bindigit+;
+oct_number = ('0o' | '0O') octdigit+;
 float = digit* '.' digit+;
 string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
 start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
@@ -634,6 +638,8 @@ expr_single~nopar~nobra {-> expr}
        | {null} kwnull annotations_o {-> New expr.null(kwnull, annotations_o.annotations)}
        | {int} number annotations_o {-> New expr.dec_int(number, annotations_o.annotations)}
        | {hex_int} hex_number annotations_o {-> New expr.hex_int(hex_number, annotations_o.annotations)}
+       | {bin_int} bin_number annotations_o {-> New expr.bin_int(bin_number, annotations_o.annotations)}
+       | {oct_int} oct_number annotations_o {-> New expr.oct_int(oct_number, annotations_o.annotations)}
        | {float} float annotations_o {-> New expr.float(float, annotations_o.annotations)}
        | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
        | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
@@ -999,6 +1005,8 @@ expr       = {block} expr* kwend?
        | {null} kwnull annotations?
        | {dec_int} number annotations?
        | {hex_int} hex_number annotations?
+       | {bin_int} bin_number annotations?
+       | {oct_int} oct_number annotations?
        | {float} float annotations?
        | {char} char annotations?
        | {string} string annotations?
index fe79ef1..2a2298e 100644 (file)
@@ -946,6 +946,16 @@ class THexNumber
        super TokenLiteral
 end
 
+# A literal binary integer
+class TBinNumber
+       super TokenLiteral
+end
+
+# A literal octal integer
+class TOctNumber
+       super TokenLiteral
+end
+
 # A literal floating point number
 class TFloat
        super TokenLiteral
@@ -2462,6 +2472,22 @@ class AHexIntExpr
        var n_hex_number: THexNumber is writable, noinit
 end
 
+# An integer literal in binary format
+class ABinIntExpr
+       super AIntExpr
+
+       # The binary token
+       var n_bin_number: TBinNumber is writable, noinit
+end
+
+# An integer literal in octal format
+class AOctIntExpr
+       super AIntExpr
+
+       # The octal token
+       var n_oct_number: TOctNumber is writable, noinit
+end
+
 # A float literal
 class AFloatExpr
        super AExpr