Search code examples
c++cparsingprogramming-languageslua

What is the best way to reuse the Lua parser?


I know how to embed Lua in other languages, but I would like to re-use ONLY the parser to parse code and give me the result as AST for instance. What is the easiest way of doing that with the Lua platform?

Thanks!


Solution

  • Someone already made an ANTLR grammar for the Lua language:

    http://www.antlr3.org/grammar/1178608849736/Lua.g

    Or if you're using ANTLR v4:

    https://github.com/antlr/grammars-v4/blob/master/lua/Lua.g4

    I've used ANTLR on a couple projects with good results. It will generate a C (ANTLR v3) or C++ (ANTLR v2) parser including AST generation if you ask for it.