From 6eb88017ce9a2e91d90634cbb77097dd821b8626 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 7 Jan 2018 20:34:58 +0100 Subject: Accept empty parameter lists --- c.y | 22 +++++++++++++++------- test/t1.c | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/c.y b/c.y index ee98fe7..4de4cae 100644 --- a/c.y +++ b/c.y @@ -35,9 +35,9 @@ struct node *root_node; %left NOT NEGATE DEREF ADDROF %type ID NUM ADDOP MULOP RELOP BOOLOP -%type toplevel toplevel_decl var_decl func_decl parameter_list parameter block -%type statement statement_list open_statement matched_statement other_statement -%type expression atom_expr expression_list +%type toplevel toplevel_decl var_decl func_decl parameter_list parameter_list_rest +%type parameter block statement statement_list open_statement matched_statement +%type other_statement expression atom_expr expression_list %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 { diff --git a/test/t1.c b/test/t1.c index 6493dec..e47dfb0 100644 --- a/test/t1.c +++ b/test/t1.c @@ -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; -- cgit v1.2.3-70-g09d2