[antlr-interest] compilation error on grammar

Warner Onstine warnero at gmail.com
Thu Aug 2 16:37:13 PDT 2007


Hi all,
Just to preface this, I am very new to grammars (and ANTLR
specifically). I am attempting to convert a Groovy DSL that I wrote to
an external DSL piece by piece. Here is the current error I'm running
into with this grammar:
grammar Model;

prog	:	package WS? model
	;
	
package	:	'package' WS name=QIDStar NEWLINE
		{System.out.println("found package " + $name.text);}
	;

imports :	'imports' WS? '{' WS? import+ '}'
		{System.out.println("found imports");}
	;
	
import	:	name=QIDStar NEWLINE
		{System.out.println("found import " + $name.text);}
	;
	
model	:	'model' WS name=ID WS? '{' WS? '}'
		{System.out.println("found model " + $name.text);}
	;
	

ID	:	('a'..'z'|'A'..'Z')+ ;
QIDStar
	:	ID ('.' ID)* '.*'?
	;
INT	:	'0'..'9'+ ;
NEWLINE	:	'\r'? '\n' ;
WSNoNewline
	:	(' '|'\t')+ {skip();} ;
WS	:	(' '|'\t'|'\n'|'\r')+ {skip();} ;

When I generate the java class files for the grammer I get an error in
my ModelParser.java file here:
    // $ANTLR start prog
    // C:\\java\\projects\\chama-antlr\\src\\main\\antlr\\Model.g:3:1:
prog : package ( WS )? model ;
    public final void prog() throws RecognitionException {
        try {
            // C:\\java\\projects\\chama-antlr\\src\\main\\antlr\\Model.g:3:8:
( package ( WS )? model )
            // C:\\java\\projects\\chama-antlr\\src\\main\\antlr\\Model.g:3:8:
package ( WS )? model
            {
            pushFollow(FOLLOW_package_in_prog10);
            package();
            _fsp--;

on the package(); call Eclipse (and a normal build) is telling me that:
illegal start of an expression
<identifier>(or this) expected
'(' expected

any help is greatly appreciated

-- 
Warner Onstine - Programmer/Author
New book on Tapestry 4!
Tapestry 101 available at
http://sourcebeat.com/books/tapestrylive.html
warner at warneronstine.com
http://warneronstine.com/blog


More information about the antlr-interest mailing list