Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Bison syntax not recognizing multiple statements in function

$
0
0

I am new to bison and I ran into a problem that I cannot understand.

I have this test file as input to the parser:

x = 2;function foo(){    function foo(bar){        local foo = 2;        return foo + bar;    }}

and bison says:

syntax error, unexpected RETURN, expecting RCURBR at line: 5

The grammar for this specific example is this:

funcdef:          FUNCTION IDENT LPAR {scope++;} idlist RPAR func_block                   {SymTable_put(sym_table, $2, USERFUNC, yylineno, scope);};func_block:       LCURBR stmt_star RCURBR       { SymTable_setActive(sym_table, scope, 0); scope--; }                | LCURBR RCURBR                 { SymTable_setActive(sym_table, scope, 0); scope--; };stmt:     expr SEMICOLON        { ; }        | returnstmt            { ; }        | funcdef               { ; }        | SEMICOLON             { ; };stmt_star: stmt                 { ; }        |  stmt stmt_star       { ; };returnstmt:       RETURN SEMICOLON              { printf("return without expr\n"); }                | RETURN expr SEMICOLON         { printf("return with expr\n"); };

Of course there is much more grammar than this but for this specific example that's allyou need to know.

As I understand it, the parser recognizes the "local foo = 2;" as an assign expression (based on some other grammar) and then it expects for the function block to close although I am telling it to expect more than one statement through the "stmt_star" between '{' and '}'.

I know that "local foo = 2" is being recognized correctly, as it is inserted into the symbol table. I can provide all the grammar if you want me to.

Please help me, I am so lost on this.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>