[antlr-interest] Lookahead and wildcards (was: ANTLR Masquerading as SED)
Terence Parr
parrt at jguru.com
Tue Apr 29 07:57:19 PDT 2003
Hi. k is a "do not exceed" value not a fixed value. I must modulate k
in the grammar to make it smaller and faster. k=1 is sufficient for
just about every decision, with k>1 needed in a few places. Examine
the output of the java.g file and you'll see me modulate k.
I know that k=2 is sufficient to distinguish those two rules from each
other so I only use two :)
Ter
On Tuesday, April 29, 2003, at 12:02 AM, Oliver Zeigermann wrote:
> OK, maybe I am dump, but I still do not get it. This is the real
> core of my question:
>
> Why does this grammar
>
>
> class T extends Lexer;
> options {
> k=3;
> charVocabulary = '\3'..'\177';
> }
> P : "<p>" ;
> BR : "<br>" ;
>
> IGNORE : . ;
>
>
> result to this generated code
>
>
> if ((LA(1)=='<') && (LA(2)=='p')) {
> mP(true);
> theRetToken=_returnToken;
> }
> else if ((LA(1)=='<') && (LA(2)=='b')) {
> mBR(true);
> theRetToken=_returnToken;
> }
> else if (((LA(1) >= '\u0003' && LA(1) <= '\u007f')) && (true)) {
> mIGNORE(true);
> theRetToken=_returnToken;
> }
>
>
> I would have expected this code (because of k=3)
>
>
> if ((LA(1)=='<') && (LA(2)=='p') && (LA(3)=='>')) {
> mP(true);
> theRetToken=_returnToken;
> }
> else if ((LA(1)=='<') && (LA(2)=='b') && (LA(3)=='r')) {
> mBR(true);
> theRetToken=_returnToken;
> }
> else if (((LA(1) >= '\u0003' && LA(1) <= '\u007f')) && (true)) {
> mIGNORE(true);
> theRetToken=_returnToken;
> }
>
>
> Thanks,
>
> Oliver
>
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Co-founder, http://www.peerscope.com link sharing, pure-n-simple
Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list