[antlr-interest] Re: Suggestion: syntactic sugar for generateAmbigWarnings = false;

uprightness_of_character andrei at metalanguage.com
Wed Jun 18 13:37:51 PDT 2003


--- In antlr-interest at yahoogroups.com, "uprightness_of_character" 
<andrei at m...> wrote:
> I (predictably) concur. In my projects with antlr (a C-like language 
> translator, a Cecil documentation system, and an email filter) I 
found 
> myself quite often needing to express precedence between rules with 
> overlapping FIRST sets. The generated code is also more efficient 
> than, for example, making sure the FIRST sets are non-overlapping by 
> using ~(THIS | THAT | THE_OTHER). 

One more thing. antlr should still generate warnings if the FIRST set 
of the left-hand side of a "||" includes the FIRST set of the 
right-hand side. That means the second alternative is "dead" - never 
reachable. For example:

macro_body
    : (~NEWLINE || BACKSLASH NEWLINE)*
    ;

In this case, the first alternative eats everything, including the 
backslash, so the second alternative never gets a crack. In this case, 
antlr should give a warning:

"Warning: alt 2 of rule macro_body not reachable"

When the FIRST set of the lhs does not include the FIRST set of the 
rhs, the "||" operator might be helpful in parsing languages without 
being overly uptight about defining disjoint FIRST sets.


Andrei


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list