1

I am learning how to generate a symbol table using Antlr4. I came across this example (and the only one so far) but it gives compilation errors for the files generated by Antlr4.

(commands: antlr4 Simple.g4 and javac Simple*.java)

-bash-4.1$ javac Simple*.java
SimpleBaseListener.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
SimpleListener.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
SimpleParser.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
SimpleParser.java:87: error: cannot find symbol
            public Scope scope;
                   ^
symbol:   class Scope
location: class FileContext
SimpleParser.java:166: error: cannot find symbol
            public Scope scope;
                   ^
symbol:   class Scope
location: class FuncContext
SimpleParser.java:356: error: cannot find symbol
            public Scope scope;
                   ^
symbol:   class Scope
location: class BlockContext
SimpleLexer.java:3: error: package org.antlr.symbols does not exist
import org.antlr.symbols.*;
^
7 errors

My guess is that this implementation uses an old verison of Antlr.

Is there an example for Antlr4? I tried the official documentation but it is not very helpful for a newbie.

Nht_e0
  • 140
  • 4
  • 15
  • Try [https://github.com/antlr/symtab](https://github.com/antlr/symtab) – GRosenberg Sep 13 '18 at 03:03
  • @GRosenberg isn't this built using Antlr3 (or 2) and not Antlr4? Antlr4 is very different from its previous versions, so many of the features in Antlr3 and below don't work for Antlr4 – Nht_e0 Sep 13 '18 at 04:57
  • No. It is for Antlr4. This earlier answer provides a [symbol table](https://stackoverflow.com/questions/15588452/build-symbol-table-from-grammar/15602385#15602385) for a more general language use. – GRosenberg Sep 13 '18 at 17:41

0 Answers0