[antlr-interest] Problem with disambiguating semantic predicates and the decision DFA

Gary R. Van Sickle g.r.vansickle at att.net
Wed Dec 31 20:05:14 PST 2008


> From:  Markus Stoeger
> 
> First of all, a happy new year to everyone!
> 
> I'm writing a grammar for one of those twisted languages, 
> written by social deviants, that allow keywords to be used as 
> variables.
>

Well, at least it ain't SPICE, where keywords (e.g. in
"Rname_of_the_resistor", the "R" is the "keyword"), "variable" (node and
model) names, and even numerical values cannot be distinguished at
lexer-time.  Yeah.  Plus, there are a few instances where you don't even
know how many of these indistinguishable items to expect, so you can't say
"if it's a BJT, take in 3 or 4 node names, then one model name, then maybe
some optional stuff that's equally ill-defined" in any simple manner.  And
just to add insult to injury, the line continuation character is not placed
at the end of the line to be continued, but at the *beginning* of the *next*
line.

I think the whole CompSci field needs to institute a housecleaning policy,
whereby every say 5 years or so we completely start over, undo the sins of
our forefathers, and never look back lest we turn into pillars of salt, so
that we aren't forced to live with such atrocities indefinitely.

But enough of my rant of woe ;-).
 
> The solution provided in the ANTLR Reference book on page 287 
> ("Keywords as Variables") seems to work fine in most cases.

This brings up a semi-rhetorical question (in my mind anyway): In general,
isn't one of the strengths of the top-down parsing approach that it is able
to handle exactly this sort of ambiguity effortlessly, since there is
implicit context maintaned during the parse that isn't there in a bottom-up
approach?  It seems that the current "lex 'em all and let the parser sort
'em out" lexer implementation used by ANTLR results in a system which
needlessly suffers the limitations involved with the top-down approach and
prevents it from taking advantage of some of the benefits.

Idle New Years' Eve thinking-out-loud, FWIW.

-- 
Gary R. Van Sickle



More information about the antlr-interest mailing list