Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANTLR error(99) grammar has no rules

Tags:

antlr

I previously posted about my first attempt at using ANTLR when I was having issues with left recursion.

Now that I have resolved those issues, I am getting the following error when I try to use org.antlr.v4.Tool to generate the code:

error(99): C:test.g4::: grammar 'test' has no rules

What are the possible reasons for this error? Using ANTLRWorks I can certainly see rules in the Parse Tree so why can't it see them? Is it because it cannot find a suitable START rule?

like image 852
Felix Bembrick Avatar asked Jun 13 '13 03:06

Felix Bembrick


2 Answers

I think Antlr expects the first rule name to be in small case. I was getting the same error with my grammar

grammar ee;
Condition : LogicalExpression ;
LogicalExpression : BooleanLiteral ; 
BooleanLiteral :  True ;
True : 'true' ;

By changing the first production rule in the grammar to lower case it solved the issue i.e. the below grammar worked for me.

grammar ee;
condition : LogicalExpression ;
LogicalExpression : BooleanLiteral ; 
BooleanLiteral :  True ;
True : 'true' ;

Note: It is my personal interpretation, I couldn't find this reasoning in the online documentation.

Edit: The production rules should begin with lower case letters as specified in the latest docs [1]

[1] https://github.com/antlr/antlr4/blob/master/doc/lexicon.md#identifiers

like image 151
vdua Avatar answered Sep 20 '22 20:09

vdua


I'm not sure if you've found the solution for this, but I had the same problem and fixed it by changing my start symbol to 'prog'. So for example, the first two lines of your .g4 file would be:

    grammar test;
    prog : <...> ;

Where <...> will be your first derivation.

like image 36
Markoorn Avatar answered Sep 20 '22 20:09

Markoorn