aboutsummaryrefslogtreecommitdiff
path: root/c.y
diff options
context:
space:
mode:
Diffstat (limited to 'c.y')
-rw-r--r--c.y22
1 files changed, 15 insertions, 7 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> 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 {