« Return to Thread: parsing conflict
Tom Copeland wrote:On Jun 17, 2009, at 9:43 AM, eugenio_ wrote:
>
> It is the right situation that I meant, thank you very much for you
> answer as
> soon as possible I will try to execute the code on my computer and
> see the
> result. I am courius to see where I was wrong.
>
> I will tell you how it went.
Cool, sounds good, and here's a more useful version with a main()
method:
============
PARSER_BEGIN(Foo)
import java.io.*;
public class Foo {
public static void main(String[] args) throws Exception {
Foo p = new Foo(new StringReader(args[0]));
p.a();
System.out.println("Successfully parsed " + args[0]);
}
}
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()) <EOF>
}
void b() : {} {
identifier() <COLON> attribute1()
}
void c() : {} {
identifier() <COMMA> attribute2()
}
void identifier() : {} {
<IDENTIFIER>
}
void attribute1() : {} {
"ATTRIBUTE1"
}
void attribute2() : {} {
"ATTRIBUTE2"
}
============
Here's the little test data string I was using:
============
$ rm -f *.java *.class && javacc foo.jj && javac *.java && java Foo
"TOKEN1x,ATTRIBUTE2"
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.
Successfully parsed TOKEN1x,ATTRIBUTE2
============
Yours,
Tom
---------------------------------------------------------------------
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 |