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.
This commit is contained in:
Randy Heit 2013-07-19 23:25:01 -05:00
parent 9cf9226e86
commit 733e5fa2e1

View file

@ -402,7 +402,7 @@ type_name(X) ::= IDENTIFIER(A). /* User-defined type (struct, enum, or class)
id->Id = A.Name(); id->Id = A.Name();
X = type; X = type;
} }
type_name(X) ::= LBRACKET dottable_id(A) RBRACKET. type_name(X) ::= DOT dottable_id(A).
{ {
NEW_AST_NODE(BasicType, type); NEW_AST_NODE(BasicType, type);
type->Type = ZCC_UserType; type->Type = ZCC_UserType;
@ -441,6 +441,7 @@ vector_size(X) ::= LT INTCONST(A) GT.
%type type_or_array {ZCC_Type *} %type type_or_array {ZCC_Type *}
%type class_restrictor {ZCC_Identifier *} %type class_restrictor {ZCC_Identifier *}
%type array_size{ZCC_Expression *} %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 */ 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) ::= VOID. { X = NULL; }
type_list_or_void(X) ::= type_list(A). { X = A; } 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) if (A == NULL)
{ {
@ -491,18 +492,13 @@ array_size(X) ::= LBRACKET opt_expr(A) RBRACKET.
X = A; X = A;
} }
} }
array_size(X) ::= array_size(A) LBRACKET opt_expr(B) RBRACKET. array_size(X) ::= array_size_expr(A).
{ {
if (B == NULL) X = A;
{
NEW_AST_NODE(Expression,nil);
nil->Operation = PEX_Nil;
A->AppendSibling(nil);
} }
else array_size(X) ::= array_size(A) array_size_expr(B).
{ {
A->AppendSibling(B); A->AppendSibling(B);
}
X = A; X = A;
} }
@ -613,6 +609,12 @@ variable_name(X) ::= IDENTIFIER(A).
var->Name = ENamedName(A.Int); var->Name = ENamedName(A.Int);
X = var; 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). variable_list(X) ::= variable_name(A).
{ {