From dfedb9c573e6492092c8acab3267277624498d9a Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 27 May 2015 13:20:21 -0400 Subject: [PATCH] parser: Added u8 suffix for byte literal values Signed-off-by: Lucas Bajolet --- src/parser/nit.sablecc3xx | 12 +++++++++ src/parser/parser_nodes.nit | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index 4a90050..769f05b 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -203,6 +203,10 @@ number = digit+; hex_number = ('0x' | '0X') hexdigit+; bin_number = ('0b' | '0B') bindigit+; oct_number = ('0o' | '0O') octdigit+; +bytenum = digit+ 'u8'; +hex_bytenum = ('0x' | '0X') hexdigit+ 'u8'; +bin_bytenum = ('0b' | '0B') bindigit+ 'u8'; +oct_bytenum = ('0o' | '0O') octdigit+ 'u8'; float = digit* '.' digit+; string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' '''; start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2; @@ -640,6 +644,10 @@ expr_single~nopar~nobra {-> expr} | {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)} + | {byte} bytenum annotations_o {-> New expr.dec_byte(bytenum, annotations_o.annotations)} + | {hex_byte} hex_bytenum annotations_o {-> New expr.hex_byte(hex_bytenum, annotations_o.annotations)} + | {bin_byte} bin_bytenum annotations_o {-> New expr.bin_byte(bin_bytenum, annotations_o.annotations)} + | {oct_byte} oct_bytenum annotations_o {-> New expr.oct_byte(oct_bytenum, 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)} @@ -1007,6 +1015,10 @@ expr = {block} expr* kwend? | {hex_int} hex_number annotations? | {bin_int} bin_number annotations? | {oct_int} oct_number annotations? + | {dec_byte} bytenum annotations? + | {hex_byte} hex_bytenum annotations? + | {bin_byte} bin_bytenum annotations? + | {oct_byte} oct_bytenum annotations? | {float} float annotations? | {char} char annotations? | {string} string annotations? diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index 2a2298e..6ec146f 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -956,6 +956,26 @@ class TOctNumber super TokenLiteral end +# A literal decimal byte +class TBytenum + super TokenLiteral +end + +# A literal hexadecimal byte +class THexBytenum + super TokenLiteral +end + +# A literal binary byte +class TBinBytenum + super TokenLiteral +end + +# A literal octal byte +class TOctBytenum + super TokenLiteral +end + # A literal floating point number class TFloat super TokenLiteral @@ -2488,6 +2508,43 @@ class AOctIntExpr var n_oct_number: TOctNumber is writable, noinit end +# An byte literal +class AByteExpr + super AExpr +end + +# An byte literal in decimal format +class ADecByteExpr + super AByteExpr + + # The decimal token + var n_bytenum: TBytenum is writable, noinit +end + +# An byte literal in hexadecimal format +class AHexByteExpr + super AByteExpr + + # The hexadecimal token + var n_hex_bytenum: THexBytenum is writable, noinit +end + +# An byte literal in binary format +class ABinByteExpr + super AByteExpr + + # The binary token + var n_bin_bytenum: TBinBytenum is writable, noinit +end + +# An byte literal in octal format +class AOctByteExpr + super AByteExpr + + # The octal token + var n_oct_bytenum: TOctBytenum is writable, noinit +end + # A float literal class AFloatExpr super AExpr -- 1.7.9.5