From 733e5fa2e1c55d9acdc69b7ec6f236822efb2bea Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 19 Jul 2013 23:25:01 -0500 Subject: [PATCH] Recognize C-style array declarations - The variable_name production now accepts an optional array size argument. (Not yet passed to the AST.) - The notation for using dotted ID lists as types has been changed from [id1.id2] to .id1.id2, beacuse the former conflicts with the notation for arrays. --- src/zscript/zcc-parse.lemon | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/zscript/zcc-parse.lemon b/src/zscript/zcc-parse.lemon index 6c461cc50..41c605300 100644 --- a/src/zscript/zcc-parse.lemon +++ b/src/zscript/zcc-parse.lemon @@ -402,7 +402,7 @@ type_name(X) ::= IDENTIFIER(A). /* User-defined type (struct, enum, or class) id->Id = A.Name(); X = type; } -type_name(X) ::= LBRACKET dottable_id(A) RBRACKET. +type_name(X) ::= DOT dottable_id(A). { NEW_AST_NODE(BasicType, type); type->Type = ZCC_UserType; @@ -441,6 +441,7 @@ vector_size(X) ::= LT INTCONST(A) GT. %type type_or_array {ZCC_Type *} %type class_restrictor {ZCC_Identifier *} %type array_size{ZCC_Expression *} +%type array_size_expr{ZCC_Expression *} aggregate_type(X) ::= MAP LT type_or_array(A) COMMA type_or_array(B) GT. /* Hash table */ { @@ -478,7 +479,7 @@ type_list(X) ::= type_list(A) COMMA type_or_array(B). { X = A; A->AppendSibling( type_list_or_void(X) ::= VOID. { X = NULL; } type_list_or_void(X) ::= type_list(A). { X = A; } -array_size(X) ::= LBRACKET opt_expr(A) RBRACKET. +array_size_expr(X) ::= LBRACKET opt_expr(A) RBRACKET. { if (A == NULL) { @@ -491,18 +492,13 @@ array_size(X) ::= LBRACKET opt_expr(A) RBRACKET. X = A; } } -array_size(X) ::= array_size(A) LBRACKET opt_expr(B) RBRACKET. +array_size(X) ::= array_size_expr(A). { - if (B == NULL) - { - NEW_AST_NODE(Expression,nil); - nil->Operation = PEX_Nil; - A->AppendSibling(nil); - } - else - { - A->AppendSibling(B); - } + X = A; +} +array_size(X) ::= array_size(A) array_size_expr(B). +{ + A->AppendSibling(B); X = A; } @@ -613,6 +609,12 @@ variable_name(X) ::= IDENTIFIER(A). var->Name = ENamedName(A.Int); X = var; } +variable_name(X) ::= IDENTIFIER(A) array_size. +{ + NEW_AST_NODE(VarName,var); + var->Name = ENamedName(A.Int); + X = var; +} variable_list(X) ::= variable_name(A). {