ANTLR error (99) grammar has no rules

Earlier, I wrote about my first attempt to use ANTLR when I had problems with left recursion.

Now that I have solved these problems, I get the following error when I try to use org.antlr.v4.Tool to generate code:

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

What are the possible causes of this error? Using ANTLRWorks I can, of course, see the rules in the analysis tree, so why don't they see them? Is it because he cannot find a suitable START rule?

+4
source share
6 answers

I'm not sure if you found a solution for this, but I had the same problem and fixed it by changing my initial character to "prog". For example, the first two lines of your .g4 file:

  grammar test; prog : <...> ; 

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

+2
source

I got this error too (antlworks 2.1). transition from RULE : THIS | THAT ; RULE : THIS | THAT ; to RULE : THIS | THAT ; RULE : THIS | THAT ; for parser rules (i.e., from uppercase to lowercase) solved the problem!

EDIT The above amendment is saved only for RULE , which follows after : can be any combination of lexer / parser rules

+1
source

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

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

Changing the first production rule in the grammar to lowercase, he solved the problem, that is, the following grammar worked for me.

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

Note. This is my personal interpretation, I could not find this argument in the online documentation.

+1
source

The most likely reason is that it offers an error message. And the most likely reason for this is because you did not save the grammar in a file - or if you use ANTLRWorks2 - ANTLRWorks did not save your work in a file. I do not know why ANTLRWorks is not securely stored.

0
source

I also got the same error but could not fix it. I downloaded antlrworks-1.4.jar and it works great.

Download β†’ antlrworks-1.4.jar

0
source

Changing the first rule to start with a lowercase character worked for me.

0
source

Source: https://habr.com/ru/post/1485912/


All Articles