help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to implement optional semicolon rules


From: Matthias Simon
Subject: Re: How to implement optional semicolon rules
Date: Fri, 12 Dec 2014 08:47:21 +0100
User-agent: Roundcube Webmail/0.7.1

Hi again,

I want to share my solution with you and the future generations stumbling across similar problems ;) I decided implementing the exact semicolon rules was not worth the trouble:

- The grammar is already quite complex and difficult to understand, changing these to respect semicolon rules is a waste of effort - Let bison instruct the lexer when to inject a semicolon, like <<OptSemicolon: { driver->inject_semicolon = 1; } ';'>>, did not work out, because when the mid-action is executed, bison already has read the next token, so it is to late to inject. But moving this action one token earlier would cause the lexer to inject semicolon in the wrong places.

So, I just made all semicolons optional and tried to cope with the conflicts. I just had two kinds of conflicts ( \o/ ), actually. One --probably a quite common-- was:

Stmt:
    ...
    | "return"
    | "return" Expression
    | Assignment
    ....

Expression and Assignment both may begin with an identifier. So bison does not know whether to shift for the second option or to reduce the first and start with the Assignment. The default --shifting the Expression-- totally works for me. First because, having an Assignment right after a `return' does virtually never appear, secondly the type-checker is able dectect a `mis-shifted' return and could suggest an explicit semicolon.

Problem solved. Thank you a lot for your support :)

Cheers,

Matthias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]