Search code examples
c#parsingantlr4visitor-patternsymbol-table

Is there an implementation of a visitor of the ANTLR generated parse tree that builds a symbol table?


I'm using ANTLR4 to build the parse tree of a program (C# program, but could be any other popular language). Now I need to resolve the declarations and usages. I know the basic principles (stack of sopes, symbol table...) but I believe this is a fairly common task for there to be an existing implementation. However, I can't find any. If there is one, please guide me. If not, I wonder why.

Note: Ideally, the visitor should be for the ANTLR Parse tree of a C# or javascript/Typescript program, and written in C#. But I don't want to be picky.


Solution

  • Usually questions asking for other tools or software is not valid on Stackoverflow, but since I can answer that with a reference to my own work (shameless plug) I will answer it.

    In the ANTLR4 extension for Visual Studio Code I implemented a symbol table and a listener, which fills that. This extension parses ANTLR4 grammars and builds a symbol table with rule/token names, options, alternatives, blocks etc. The symbol table construction happens in the DetailsListener implementation.