An automatic dialect and frontend generator from antlr4 grammars

Hi!
I am new to the MLIR world and found no option to generate a lexer and parser that output MLIR programs automatically.
I started a project available on github that allows transforming an antlr4 grammar into an MLIR dialect representing the AST and an antlr4-based project compiling into this grammar.
Only a subset of antlr4 can be used for now, but it may change soon.

I am new to MLIR and antlr, and this is my first public project, so any comment or suggestion will be appreciated.

4 Likes

Exciting stuff! Do you have an example of what the generated dialects look like? Have you considered emitting IRDL instead of a full dialect project, for portability?

You can find a MiniJava antlr grammar in the example folder, and I added files of the generated AST dialect in this folder.
I don’t know IRDL yet, but it seems to be a dialect for defining dialects. It could be a good idea to add the possibility of an IRDL output.

This is very nice! There have been a few recent projects that use MLIR for AST, but nothing upstream yet. Even just pointing out gaps in modeling ability would be great. It may be good to have an AST ODM if we have enough folks that want to share experience.

Agreed! I just had a conversation with people researching software engineering and programming language design who share a similar interest in trying to represent ASTs in MLIR.

It may be a good way to further bridge the gap between compiler, language, and tool designers.