yacc - Error in array declaration grammar -
%token digit return identifier colon comma else if nl keyword br read write while equal %start y2 %left '-' %left '+' %right '=' %% stmt1:keyword identifier x1 //for initialization. ; y2:stmt1 stmt2 //y2 starting variable | ; x1:colon {printf(" int a/ char a");} |'['digit']'colon {printf("for array declarations");} ; stmt2:keyword identifier"("stmt3")"stmt5 {printf("for functions");} | ; stmt3:keyword identifier x2 | ; x2:stmt4 {printf("for parameter int/char");} |"["digit"]"colon {printf("for parameter int arr[]/char arr[]");} //in production parser not responding ; stmt4:comma stmt3 {printf("to have multiple arguments");} | ; %%
i parsing string int a[10];
instead of parsing, execute yyerror()
every time. code parses int a;
single statement char a;
also.
make sure lexer returns '['
when sees open bracket.
mixing single-quoted tokens '['
, named tokens colon
confusing , suggests copy-and-pasting different sources, rather designing program. since lexer , parser must agree on handling of tokens, form of creating programs error-prone. recommend using single-quoted single-character tokens throughout, since more readable , simplifies lexer.
with respect x2
, there difference between '['
, "["
. want first one. same problem found in stmt2
, uses "("
, ")"
instead of single-quoted versions.
Comments
Post a Comment