[antlr-interest] Simple grammar issue?

Jim Idle jimi at temporal-wave.com
Wed Sep 17 22:20:56 PDT 2008


On Thu, 2008-09-18 at 01:06 -0400, Ilya Sterin wrote:

> I'm having an issue with what seems to be very simple grammar...


Please read the "5 minute introduction to ANTLR" on the wike page. This
will explain how to write sch a simple grammar. All your rules are lexer
rules and you are not catering for whitespace, some of your lexer rules
overlap others and so on. These are all basic mistakes that everyone
makes, but a bit of reading on the wiki will get you through it.

Jim

> 
> The CREATECOMMAND is parsing correctly...
> 
> Here is what I use for validation...
> 
> create jar named "alex.jar"
> 
> I get a NoViableAltException for the TYPE definition
> 
> The grammar file is below...
> 
> 
> //////// alex.g ////////
> 
> grammar alex;
> 
> tokens {
> 	BUILD='build';
> 	FROM='from';
> 	TO='to';
> 	CREATE='create';
> 	NAMED='named';
> }
> 
> COMMAND		:	BUILDCOMMAND CREATECOMMAND;
> 
> BUILDCOMMAND	:	BUILD (SOURCE | DESTINATION)+;
> CREATECOMMAND	:	CREATE TYPE (NAME | SOURCE | DESTINATION)+;
> 
> SOURCE		:	FROM FILE;
> DESTINATION 	:	TO FILE;
> 
> TYPE		:	('jar' | 'war');
> 
> NAME		:	NAMED FILE;
> 
> FILE		:	'"' FILENAME '"';
> FILENAME	: 	('a'..'z'|'A'..'Z'|'0'..'9'|'.')+;
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080917/22c7f454/attachment.html 


More information about the antlr-interest mailing list