« Return to Thread: parsing conflict
Tom Copeland wrote:On Jun 12, 2009, at 10:03 AM, eugenio_ wrote:
>
> It doesn't work with LOOKAHEAD = 2 or 3 or whatever and I don't
> understand
> why
LOOKAHEAD(2) seems to work for me:
==============
$ cat foo.jj
PARSER_BEGIN(Foo)
import java.io.*;
public class Foo {}
PARSER_END(Foo)
TOKEN : {
< TOKEN1 : "TOKEN1">
| < COMMA : ",">
| < COLON : ":">
| < IDENTIFIER : <LETTER> (<LETTER>|<DIGIT>)* >
| < LETTER : ["a"-"z"]>
| < DIGIT : ["0"-"9"]>
}
void a() : {} {
<TOKEN1> (LOOKAHEAD(2) b()|c())
}
void b() : {} {
identifier() <COLON> attribute1()
}
void c() : {} {
identifier() <COMMA> attribute2()
}
void identifier() : {} {
t = <IDENTIFIER>
}
void attribute1() : {} {
"ATTRIBUTE1"
}
void attribute2() : {} {
"ATTRIBUTE2"
}
$ javacc foo.jj
Java Compiler Compiler Version 4.2 (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file foo.jj . . .
File "TokenMgrError.java" does not exist. Will create one.
File "ParseException.java" does not exist. Will create one.
File "Token.java" does not exist. Will create one.
File "SimpleCharStream.java" does not exist. Will create one.
Parser generated successfully.
==============
Or does that grammar not represent the problem you're facing?
Yours,
Tom
http://generatingparserswithjavacc.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@javacc.dev.java.net
For additional commands, e-mail: users-help@javacc.dev.java.net
« Return to Thread: parsing conflict
| Free embeddable forum powered by Nabble | Forum Help |