[antlr-interest] Syntatic predicates...
Terence Parr
parrt at cs.usfca.edu
Mon May 17 14:45:08 PDT 2004
On May 17, 2004, at 2:18 PM, Mark Lentczner wrote:
>
>> 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.
Hi Mark,
Actually, this is a problem with the language as it is ambiguous. Any
grammar then for an ambiguous language must also be ambiguous. I cite
C++ expr vs decl which can only be solved with arbitrary lookahead,
that is, a syn pred. :) You have to look at the whole thing and then
according to the manual you choose decl if it fits else it's an expr
else an error.
> Now, occasionally this is okay. A good example is something like the
> dangling else problem:
>
> if c1 then if c2 then s1 else s2
I don't think this is a lookahead problem at all, but a language
ambiguity. It is resolved properly by simply consuming greedily.
Predicates should definitely not be used here. k=1 is max lookahead
ever required.
> 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...)
I get nervous too. It is either done when first learning LL grammars
or when you're in a hurry or when you have a nasty little language and
you want to make it "natural" ;)
Terence
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing
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