diff options
author | tomsmeding <tom.smeding@gmail.com> | 2018-01-07 20:34:58 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2018-01-07 20:35:15 +0100 |
commit | 6eb88017ce9a2e91d90634cbb77097dd821b8626 (patch) | |
tree | 73e96896a0fc648e3458b59c5a52b3f4d0587a36 | |
parent | 88548f1a9796b1bc02d6d81552450401c0015f28 (diff) |
Accept empty parameter lists
-rw-r--r-- | c.y | 22 | ||||
-rw-r--r-- | test/t1.c | 2 |
2 files changed, 16 insertions, 8 deletions
@@ -35,9 +35,9 @@ struct node *root_node; %left NOT NEGATE DEREF ADDROF %type <id> ID NUM ADDOP MULOP RELOP BOOLOP -%type <node> toplevel toplevel_decl var_decl func_decl parameter_list parameter block -%type <node> statement statement_list open_statement matched_statement other_statement -%type <node> expression atom_expr expression_list +%type <node> toplevel toplevel_decl var_decl func_decl parameter_list parameter_list_rest +%type <node> parameter block statement statement_list open_statement matched_statement +%type <node> other_statement expression atom_expr expression_list %type <type> type INT VOID %union { @@ -85,11 +85,19 @@ type: type PTR { $$ = type_ptr($1); } | INT { $$ = type_int(16); } | VOID { $$ = type_void(); } ; -parameter_list: parameter { - $$ = node_make_2(N_LIST, $1, node_make_0(N_LIST_END)); +parameter_list: { + $$ = node_make_0(N_LIST_END); } - | parameter ',' parameter_list { - $$ = node_make_2(N_LIST, $1, $3); + | parameter parameter_list_rest { + $$ = node_make_2(N_LIST, $1, $2); + } ; + +parameter_list_rest: + { + $$ = node_make_0(N_LIST_END); + } + | ',' parameter parameter_list_rest { + $$ = node_make_2(N_LIST, $2, $3); } ; parameter: type ID { @@ -14,7 +14,7 @@ int fibo(int n) { return b; } -void main(int argc, int **argv) { +void main() { int a = 1; int b = 2 + a * 3; glob = glob + 1; |