Accept empty struct and enum definitions (useless as they may be)

This commit is contained in:
Randy Heit 2013-08-24 20:32:59 -05:00
parent 80daf736ec
commit 064710422b

View file

@ -191,10 +191,11 @@ class_member(X) ::= const_def(A). { X = A; }
/*----- Struct Definition -----*/
/* Structs can define variables and enums. */
%type opt_struct_body{ZCC_TreeNode *}
%type struct_body{ZCC_TreeNode *}
%type struct_member{ZCC_TreeNode *}
struct_def(X) ::= STRUCT IDENTIFIER(A) LBRACE struct_body(B) RBRACE opt_semicolon.
struct_def(X) ::= STRUCT IDENTIFIER(A) LBRACE opt_struct_body(B) RBRACE opt_semicolon.
{
NEW_AST_NODE(Struct,def);
def->StructName = A.Name();
@ -202,6 +203,9 @@ struct_def(X) ::= STRUCT IDENTIFIER(A) LBRACE struct_body(B) RBRACE opt_semicolo
X = def;
}
opt_struct_body(X) ::= . { X = NULL; }
opt_struct_body(X) ::= struct_body(A). { X = A; }
struct_body(X) ::= error. { X = NULL; }
struct_body(X) ::= struct_member(A). { X = A; }
struct_body(X) ::= struct_member(A) struct_body(B). { X = A; A->AppendSibling(B); }
@ -215,9 +219,10 @@ struct_member(X) ::= enum_def(A). { X = A; }
%type enum_type {EZCCBuiltinType}
%type enum_list {ZCC_EnumNode *}
%type opt_enum_list {ZCC_EnumNode *}
%type enumerator {ZCC_EnumNode *}
enum_def(X) ::= ENUM IDENTIFIER(A) enum_type(B) LBRACE enum_list(C) opt_comma RBRACE opt_semicolon.
enum_def(X) ::= ENUM IDENTIFIER(A) enum_type(B) LBRACE opt_enum_list(C) RBRACE opt_semicolon.
{
NEW_AST_NODE(Enum,def);
def->EnumName = A.Name();
@ -233,6 +238,9 @@ enum_list(X) ::= error. { X = NULL; }
enum_list(X) ::= enumerator(A). { X = A; }
enum_list(X) ::= enum_list(A) COMMA enumerator(B). { X = A; A->AppendSibling(B); }
opt_enum_list(X) ::= . { X = NULL; }
opt_enum_list(X) ::= enum_list(A) opt_comma. { X = A; }
enumerator(X) ::= IDENTIFIER(A).
{
NEW_AST_NODE(EnumNode,node);