From 064710422ba641c74b6d8692b239765f664ecc5a Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 24 Aug 2013 20:32:59 -0500 Subject: [PATCH] Accept empty struct and enum definitions (useless as they may be) --- src/zscript/zcc-parse.lemon | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/zscript/zcc-parse.lemon b/src/zscript/zcc-parse.lemon index 2d6eb131f..bfb5a8e12 100644 --- a/src/zscript/zcc-parse.lemon +++ b/src/zscript/zcc-parse.lemon @@ -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);