aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2018-01-07 20:34:58 +0100
committertomsmeding <tom.smeding@gmail.com>2018-01-07 20:35:15 +0100
commit6eb88017ce9a2e91d90634cbb77097dd821b8626 (patch)
tree73e96896a0fc648e3458b59c5a52b3f4d0587a36
parent88548f1a9796b1bc02d6d81552450401c0015f28 (diff)
Accept empty parameter lists
-rw-r--r--c.y22
-rw-r--r--test/t1.c2
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> 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 {
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;