On 12/13/2009 02:49 PM, Johannes Bittner wrote:
> Hello,
> 
> The Java code generated for the following grammar produces a
> NoViableAltException when using "void foo (int a, int b) { foo }" as
> input, i.e. when the second token is "foo", it works otherwise. I
> tried this with antlrworks 1.3.1. Could somebody clearify why this
> happens?

Because 'foo' is a literal in your parser, it can never be an ID.

This is the difference between reserved words and keywords.  If you need
to be able to match a literal as an ID, you need to make a parser rule like:

id: ID | 'foo' | 'int' | 'void';

> Thanks, Johannes
> 
> method
>     : type ID '(' args ')' ';'
>     | type ID '(' args ')' '{' 'foo' '}'
>     ;
> 
> type: 'void' | 'int';
> args: arg (',' arg)*;
> arg: 'int' ID;
> 
> ID  :   ('a'..'z'|'A'..'Z')+ ;
> INT :   '0'..'9'+ ;
> WS  :   (' '|'\t'|'\r'|'\n')+ {skip();} ;
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address


-- 
Kevin J. Cummings
[email protected]
[email protected]
[email protected]
Registered Linux User #1232 (http://counter.li.org)

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--

You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.


Reply via email to