|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
parsing conflictHello,
I have a conflict problem and I don't know how to manage. The grammar is like this: void a() : {} { <TOKEN1> (b()|c()) } void b() : {} { identifier() <COLON> attribute1() } void c() : {} { identifier() <COMMA> attribute2() } void identifier() : {} { t = <IDENTIFIER> { jjtThis.setName(t.image); } } TOKEN : { < IDENTIFIER : <LETTER> (<LETTER>|<DIGIT>)* > ....... } I get a conflict error because of <IDENTIFIER> in the rule a(). Now I moved the identifier() in the rule a() but I would like to maintain rules as they are here. It seems that each part of the IDENTIFIER is a token and not all the IDENTIFIER is a token. In Antlr things are different. Is it possible to specify a token (using MORE for example) in order to have an IDENTIFIER as a single token and don't have the choice conflict? Thank you very much for the attention |
|
|
Re: parsing conflictOn 09/06/2009, at 11:02 PM, eugenio_ wrote: > I get a conflict error because of <IDENTIFIER> in the rule a(). Now > I moved > the identifier() in the rule a() but I would like to maintain rules > as they > are here. It sounds like you want to insert a lookahead. From a quick inspection it seems like a LOOKAHEAD(2) will do what you want. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: parsing conflictIt doesn't work with LOOKAHEAD = 2 or 3 or whatever and I don't understand why
|
|
|
Re: parsing conflictOn 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@... For additional commands, e-mail: users-help@... |
|
|
Re: parsing conflictIt 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
|
|
|
Re: parsing conflictOn 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@... For additional commands, e-mail: users-help@... |
|
|
Re: parsing conflictPerfect!
I tried the example different time and I found the problem that I had: using the option FORCE_LA_CHECK 0 true even if I specify the lookahead I get the error about the ambiguity. I thought that setting the option the warning disappeared. Thank you very much for your support. eu
|
|
|
Re: parsing conflictOn Jul 3, 2009, at 8:32 AM, eugenio_ wrote: > > Perfect! > I tried the example different time and I found the problem that I > had: using > the option > FORCE_LA_CHECK 0 true > even if I specify the lookahead I get the error about the ambiguity. I > thought that setting the option the warning disappeared. > > Thank you very much for your support. No problem, glad to hear you sorted it out! Yours, Tom --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free embeddable forum powered by Nabble | Forum Help |