« Return to Thread: parsing conflict

Re: parsing conflict

by eugenio_ :: Rate this Message:

Reply to Author | View in Thread

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.

Thank you again for you attention,
eu

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