[antlr-interest] compilation error on grammar

Randall R Schulz rschulz at sonic.net
Thu Aug 2 16:43:03 PDT 2007


On Thursday 02 August 2007 16:37, Warner Onstine wrote:
> 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;
>
> ...
>
> 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

I advise against using line comments in the actions of ANTLR grammars. 
All the lines of an action are passed through, without regard to 
whether they happen to be partially or fully commented. The problem 
comes from the fact that ANTLR (the target language-specific string 
templates, I guess) sometimes expand portions of the actions with 
content that includes a newline, thus prematurely terminating the 
comment.

Instead, use only /* explicitly bounded */ comments inside actions.


> any help is greatly appreciated


Randall Schulz


More information about the antlr-interest mailing list