Skip to content

Commit

Permalink
fixed bug: grammar error in function call
Browse files Browse the repository at this point in the history
related issue: rswier#46
  • Loading branch information
siweiqian committed Oct 16, 2019
1 parent 2feb8c0 commit 1fa74b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion c4.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ void expr(int lev)
if (tk == '(') {
next();
t = 0;
while (tk != ')') { expr(Assign); *++e = PSH; ++t; if (tk == ',') next(); }
while (tk != ')') {
expr(Assign); *++e = PSH; ++t;
if (tk == ',') { next(); if(tk == ')') { printf("%d: error unexpected comma in function call\n", line); exit(-1); }}
else if(tk != ')') { printf("%d: error missing comma in function call\n", line); exit(-1); }
}
next();
if (d[Class] == Sys) *++e = d[Val];
else if (d[Class] == Fun) { *++e = JSR; *++e = d[Val]; }
Expand Down
16 changes: 16 additions & 0 deletions test_func_call.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>

int test(int a, int b)
{
return a + b;
}

int main()
{
int result;
//result = test(1 2);
//result = test(1, 2,);
result = test(1, 2);
printf("result is %d\n", result);
return 0;
}

0 comments on commit 1fa74b8

Please sign in to comment.