Hi,
I am using Antlr4 for a while and became interested in building an app similar to the Cymbol example in the Definitive Antlr4 Refernce book:
8.4 Validating Program Symbol Usage only for Java8.
I came across the the symtab project on github and tried to use it with Antlr4 together to build a symbol table in an antlr4 app (since Java8 is a statically scoped language, right?).
https://github.com/antlr/symtab
I started with rewriting Simple grammar event enterFile to enterCompilationUnit as:
Original example
public void enterFile(@NotNull SimpleParser.FileContext ctx) {
GlobalScope g = new GlobalScope(null);
ctx.scope = g;
pushScope(g);
}
my listener method:
public void enterCompilationUnit(Java8Parser.CompilationUnitContext ctx) {
GlobalScope g = new GlobalScope(null);
ctx.scope = g;
pushScope(g);
}
and it contains definition like:
file returns [Scope scope]
: (func|var)* EOF
;
My questions are:
What is the function of the returns statement in the grammar ?
Do I have to modify the Java8 grammar to accomplish a similar behaviour or is there an other option, which leaves the grammar untouched?
which mentions that Antlr4 supports symbol tables, but no further reference or example and I am a bit puzzled between the relationship of the symtab projects SymbolTable class and the one in the above example...
I have could follow the cymbol language example in the The Definitive ANTLR 4 Reference and have the language implementation patterns books as a reference, but I would like to avoid to reimplementing a symbol table for Java8 / rewrite the Java 8 grammar when it is possible...
Kind regards, Daniel