[antlr-interest] Syntatic predicates...
Mark Lentczner
markl at glyphic.com
Mon May 17 14:18:11 PDT 2004
> In addition, it may encourage me not to investigate the core
> reason for nondeterministic rules. (Can a syntatic predicate hide real
> problems?)
To me, this is the major problem with syntactic predicates.
Something like:
rule1: (ruleA) => ruleA | ruleB ;
is saying "a sequence of tokens could be seen as either of two
different things, but I want the grammar to prefer the one over the
other". This is an admission that your users can write things that
aren't clear what they intend. (did they mean ruleA or ruleB?) Hence,
the grammar is probably flawed.
Now, occasionally this is okay. A good example is something like the
dangling else problem:
if c1 then if c2 then s1 else s2
We recognize that user may have intended "else s2" to be associated
with either "if c1" or "if c2". One may choose to make the grammar
ambiguous (and disambiguate it with syntactic predicates or options) to
enforce one way of parsing. But you should only do this consciously
and after weighing the trade-offs. Is the ambiguity better than the
extra syntax needed to remove it? In this case, adding required
brackets removes the problem at the expense of the user having to type
more:
if c1 then { if c2 then { s1 } else { s2 } }
When I read "generously spread around syntatic predicates" I get
nervous that your grammar is full of such problems and your users will
be continuously surprized at the results. (Even the most seasoned
programmer occasionally gets hit by the dangling else problem...)
- Mark
Mark Lentczner
markl at wheatfarm.org
http://www.wheatfarm.org/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list