|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Question on examples/LookaheadHi all,
I am newbie to JavaCC and I started by the tutorials. I tried the examples/Lookahead/Example1.jj and I am surprised that the grammar does not accept "abc" as it is said on the tutorial. I am using JavaCC 5.0 and I compile and run the example with these commands: riadh@giscard:Lookahead$ ../../bin/javacc Example1.jj Java Compiler Compiler Version 5.0 (Parser Generator) (type "javacc" with no arguments for help) Reading from file Example1.jj . . . Warning: Choice conflict in [...] construct at line 60, column 7. Expansion nested within construct and expansion following construct have common prefixes, one of which is: "c" Consider using a lookahead of 2 or more for nested expansion. File "TokenMgrError.java" is being rebuilt. File "ParseException.java" is being rebuilt. File "Token.java" is being rebuilt. File "SimpleCharStream.java" is being rebuilt. Parser generated with 0 errors and 1 warnings. riadh@giscard:Lookahead$ javac *.java riadh@giscard:Lookahead$ java Example abc Exception in thread "main" ParseException: Encountered "<EOF>" at line 1, column 4. Was expecting: "c" ... at Example.generateParseException(Example.java:206) at Example.jj_consume_token(Example.java:144) at Example.Input(Example.java:12) at Example.main(Example.java:6) riadh@giscard:Lookahead$ Can you help me to understand why "abc" is not accepted? Best regards, Riadh. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Question on examples/LookaheadOn Oct 20, 2009, at 5:41 PM, Riadh Elloumi wrote: > Hi all, > > I am newbie to JavaCC and I started by the tutorials. I tried the > examples/Lookahead/Example1.jj and I am surprised that the grammar > does not accept "abc" as it is said on the tutorial. I am using > JavaCC 5.0 and I compile and run the example with these commands: > > riadh@giscard:Lookahead$ ../../bin/javacc Example1.jj > Java Compiler Compiler Version 5.0 (Parser Generator) > (type "javacc" with no arguments for help) > Reading from file Example1.jj . . . > Warning: Choice conflict in [...] construct at line 60, column 7. > Expansion nested within construct and expansion following > construct > have common prefixes, one of which is: "c" > Consider using a lookahead of 2 or more for nested expansion. > File "TokenMgrError.java" is being rebuilt. > File "ParseException.java" is being rebuilt. > File "Token.java" is being rebuilt. > File "SimpleCharStream.java" is being rebuilt. > Parser generated with 0 errors and 1 warnings. > riadh@giscard:Lookahead$ javac *.java > riadh@giscard:Lookahead$ java Example > abc > Exception in thread "main" ParseException: Encountered "<EOF>" at > line 1, column 4. > Was expecting: > "c" ... > > at Example.generateParseException(Example.java:206) > at Example.jj_consume_token(Example.java:144) > at Example.Input(Example.java:12) > at Example.main(Example.java:6) > riadh@giscard:Lookahead$ > > Can you help me to understand why "abc" is not accepted? Hello Riadh - I think the idea with examples/Lookahead/Example1.jj is to illustrate how backtracking affects a grammar. In terms of BNF, Example1.jj can handle "abc", but since JavaCC parsers don't backtrack, the parser that JavaCC generates can't. If you look at section 6 of the example/ Lookahead/README file you'll see a discussion of how to solve the problem in Example1.jj with semantic lookahead. Hope this helps, Yours, Tom http://generatingparserswithjavacc.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free embeddable forum powered by Nabble | Forum Help |