From 1b4851224e717a7841ecfc7bc87360181f697656 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 10 Sep 2013 21:44:32 -0500 Subject: [PATCH] Let the grammar accept unsigned integer constants --- src/zscript/zcc-parse.lemon | 12 +++++++++++- src/zscript/zcc_parser.cpp | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/zscript/zcc-parse.lemon b/src/zscript/zcc-parse.lemon index b180381c47..cbdea0f4f7 100644 --- a/src/zscript/zcc-parse.lemon +++ b/src/zscript/zcc-parse.lemon @@ -449,7 +449,7 @@ type_name(X) ::= DOT dottable_id(A). * straight away.) */ vector_size(X) ::= . { X.Int = ZCC_Vector3; X.SourceLoc = stat->sc.GetMessageLine(); } -vector_size(X) ::= LT INTCONST(A) GT. +vector_size(X) ::= LT intconst(A) GT. { if (A.Int >= 2 && A.Int <= 4) { @@ -462,6 +462,8 @@ vector_size(X) ::= LT INTCONST(A) GT. } X.SourceLoc = A.SourceLoc; } +intconst(X) ::= INTCONST(A). { X = A; } +intconst(X) ::= UINTCONST(A). { X = A; } /* Type names can also be used as identifiers in contexts where type names * are not normally allowed. */ @@ -1123,6 +1125,14 @@ constant(X) ::= INTCONST(A). intconst->IntVal = A.Int; X = intconst; } +constant(X) ::= UINTCONST(A). +{ + NEW_AST_NODE(ExprConstant, intconst, A); + intconst->Operation = PEX_ConstValue; + intconst->Type = TypeUInt32; + intconst->IntVal = A.Int; + X = intconst; +} constant(X) ::= FLOATCONST(A). { NEW_AST_NODE(ExprConstant, floatconst, A); diff --git a/src/zscript/zcc_parser.cpp b/src/zscript/zcc_parser.cpp index 73301e6b58..a178cb9800 100644 --- a/src/zscript/zcc_parser.cpp +++ b/src/zscript/zcc_parser.cpp @@ -140,6 +140,7 @@ static void InitTokenMap() TOKENDEF (TK_Identifier, ZCC_IDENTIFIER); TOKENDEF (TK_StringConst, ZCC_STRCONST); TOKENDEF (TK_IntConst, ZCC_INTCONST); + TOKENDEF (TK_UIntConst, ZCC_UINTCONST); TOKENDEF (TK_FloatConst, ZCC_FLOATCONST); TOKENDEF (TK_NonWhitespace, ZCC_NWS); } @@ -197,6 +198,11 @@ static void DoParse(const char *filename) value.Int = sc.Number; tokentype = ZCC_INTCONST; } + else if (sc.TokenType == TK_UIntConst) + { + value.Int = sc.Number; + tokentype = ZCC_UINTCONST; + } else if (sc.TokenType == TK_FloatConst) { value.Float = sc.Float;