[antlr-interest] Syntatic predicates...
Tom Verbeure
hombre at gmail.com
Mon May 17 14:29:30 PDT 2004
Hi Mark,
To put things in context: I am trying to convert the parts of the bnf
description of the VHDL language into ANTLR. The BNF is full of
ambiguities. I've used a bunch of existing ANTLR and non-ANTLR
grammars for VHDL and ADA as a guide, but still like to redo parts
myself just to get a full grasp of how to build a decent parser *and*
to learn features of the language. (Writing a parser force me to
explore language constructs that, before, I never considered to be
sematically correct, even after reading the official language
specification.)
But I understand see your point that it's probably better to avoid
these predicates when building your own language.
Thanks for your comment!
Tom Verbeure
On Mon, 17 May 2004 14:18:11 -0700, Mark Lentczner <markl at glyphic.com> 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.
>
> 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