[antlr-interest] Lookahead question
Terence Parr
parrt at cs.usfca.edu
Thu Dec 9 09:35:08 PST 2004
On Dec 8, 2004, at 9:45 AM, jose.sanleandro at ventura24.es wrote:
> The reason is that some of the grammar rules allow arbitrary texts,
> which
> ocassionally triggered conflicts with literals. I thought I had just
> the
> lookahead option to defeat such conflicts.
> Finally, I decided to use a lookahead of one character, and explictly
> solve
> the conflicts. That ended up in a grammar which doesn't seem so :(.
> Take a
> look at a fragment:
>
> STARTS_WITH_B:
> 'b'
> (({ if ( (LA(1) == 'r')
> && (LA(2) == 'a')
> && (LA(3) == 'n')
> && (LA(4) == 'c')
> && (LA(5) == 'h')
> && (LA(6) == ':'))
> {
> mRESERVED_BRANCH(false);
> $setType(LITERAL_BRANCH);
> }
> else
> {
> mSTRING(false);
> $setType(STRING);
> }
> })
> )
> ;
Isn't that the same as looking up the literal in the literals table?
I.e., just have rule:
ID : ('a'..'z')+ ;
and no rules like
BR : "branch" ;
and ANTLR will do the right thing albeit not super fast ;)
> Moreover, which is the main drawback of explicitly resolving the
> ambiguous
> situations for the lexer using inline LA(x) checks?
Well, only that ANTLR should really be saving you the trouble. :)
Ter
--
CS Professor & Grad Director, 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!
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