inducer / pycparserext

Extensions for Eli Bendersky's pycparser
http://pypi.python.org/pypi/pycparserext
Other
83 stars 28 forks source link

Fixed ambiguity in if-expr-asm-semi-else-asm-semi #16

Closed vijunag closed 8 years ago

vijunag commented 8 years ago

Statements of the below form resulted in shift-reduce conflict since asm was directly reduced to a statement production.

if (expr) asm(); else asm();

The above if-else clause is ambiguous when the state of the parser is IF LPAREN expression RPAREN asm --> LookAheadToken(';') since asm can be reduced to a statement the parser performs a right most derivation of "asm" as statement with the next look_ahead token as semi-colon (';) matching the production IF LPAREN expression RPAREN statement as a selection statement. In the new state ';' (as look ahead token) is an invalid/unexpected token as selection statements can only be of the form selection_statement: IF LPAREN expression RPAREN statement selection_statement: IF LPAREN expression RPAREN statement else statement The solution is to reduce asm followed by semi-colon as a statement expression so as to remove the ambiguity when the next token is ELSE or something else.

I have added the concerned test-cases in the test file and it seems to be running fine with the new grammar changes.

vijunag commented 8 years ago

Also, added support for empty GNU structures.

inducer commented 8 years ago

Looks good. Thanks for the contribution!