Skip to content
Advertisement

Extraneous input ” expecting {‘ ‘, ‘} – Antlr4

I have a text file which am parsing through antlr4.

Text format

JavaScript

Grammar Rules

JavaScript

I get this

JavaScript

What am i doing wrong and how could i make these rules better?

Advertisement

Answer

Your example input get properly parsed if you start with the init rule:

JavaScript

prints:

JavaScript

which looks like this indented:

JavaScript

My guess is that the error you’re getting is produced by a parser generated from a grammar that looks differently than the grammar you now posted. Every time you make changes to the grammar, you need to let ANTLR generate new lexer- and parser classes.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement