Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please help to resolve IF THEN ELSE issue in AlaSQL parser #279

Open
agershun opened this issue Apr 21, 2015 · 7 comments
Open

Please help to resolve IF THEN ELSE issue in AlaSQL parser #279

agershun opened this issue Apr 21, 2015 · 7 comments

Comments

@agershun
Copy link

Thank you again for the great software! May I ask you to help to resolve one issue in the grammar file, which we can not solve.

This is a grammar file https://github.com/agershun/alasql/blob/master/src/alasqlparser.jison

When I parse my file, I receive the following warnings:
Even with this warning all tests passed ok. How to modify grammar file to remove this warning?

    Conflict in grammar: multiple actions possible when lookahead token is ELSE in state 231
    - reduce by rule: If -> IF Expression AStatement
    - shift token (then go to state 381)

    States with conflicts:
    State 231
      If -> IF Expression AStatement .ElseStatement #lookaheads= GO SEMICOLON EOF END ELSE
      If -> IF Expression AStatement . #lookaheads= GO SEMICOLON EOF END ELSE
      ElseStatement -> .ELSE AStatement #lookaheads= EOF SEMICOLON GO END ELSE

These messages related to lines 1986-2003, which are:

        IF Expression AStatement ElseStatement 
    | IF Expression AStatement
    ;

ElseStatement
    : ELSE AStatement 
    ;

Could you help me with this problem?

@nolanlawson
Copy link
Contributor

The Bison docs have a section on fixing conflicts. In general, though, I believe the standard advice is, "It's really hard to write unambiguous grammars. If you can, great. If you can't, then it's usually not a problem." I am a newb to Jison, though, so take that with a grain of salt! :)

Also just a small piece of advice on simplifying your grammar: if you use the ebnf extended syntax, you can do stuff like:

IF Expression AStatement ElseStatement?

There's an example of this in my Jison Debugger; check the "musical chords" sample in the dropdown list.

@agershun
Copy link
Author

@nolanlawson - Thank you, great and useful tool! Is there way to to turn on ebnf in Jison?

I also tryed to use this Bison documentation parts, and tried to play with %left, %right and other flags - but everything had no desired effect.

@nolanlawson
Copy link
Contributor

@agershun Yup, check out the Jison Debugger's "musical chords" grammar, where I enable %ebnf. This feature is described in https://gist.github.com/zaach/1659274

@agershun
Copy link
Author

Thank you, Nolan! I will create the special issue to rewrite parser with this ebnf notation. May be I can solve this 'IF_THEN-ELSE' occasionally as well :)

@agershun
Copy link
Author

@nolanlawson I love this ebnf!!! It seems, that it does not reduce the size of the output file, but the source file is much much smaller and cleaner 👍

@nolanlawson
Copy link
Contributor

Yeah ebnf is awesome. :)

@agershun
Copy link
Author

Unfortunately, %ebnf has a serious bug. See #254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants