Reproducible Way to Create AST from Parse Tree

42 views
Skip to first unread message

Kenneth Cochran

unread,
Mar 17, 2025, 7:44:15 PMMar 17
to antlr-di...@googlegroups.com
For my GameVM project I'm using ANTLR v4 to create multiple compiler frontends. Generating the lexer and parser for each language saved me a ton of work (especially since I have no background in compiler writing), but I'm getting bogged down on implementing ASTs for each language.

I'm planning on supporting at least 10 different languages that will be transformed to a yet to be decided IR. 

Maybe there's no way to transform a parse tree to an AST but by implementing the node types one at a time and writing visitor functions to do the translation but I can't help but feel there's an easier way to do this.

Any ideas or help would be appreciated.


Mike Lischke

unread,
Mar 18, 2025, 4:01:08 AMMar 18
to antlr-di...@googlegroups.com
It's easy, but please ask on stack overflow.com. I'll help you there. This mailing list/newsgroup is now designated as an announcement list.


Adrian Sutherland

unread,
Mar 18, 2025, 6:14:21 AMMar 18
to antlr-di...@googlegroups.com
A bit off topic - but I have an implemented algorithm (just a heuristic) which is designed to turn a generic AST tree BACK into a parse tree. The use case is for language developers who have created their AST tree to process a language but are disappointed that they can't easily use it for syntax highlighting. This turns it back to a parse tree with tokens in the right (source code) order and with no gaps. This is coupled with a shared remote buffer to allow an editor to do interactive syntax highlighting (and folding but not yet completion or refactoring) using a largely unmodified AST based language processor (i.e. a compiler)

Anyway - and I appreciate ANTLR focuses on parse trees but - if anyone is at all interested let me know! WIP but I can try and share a working version with notice!

Adrian

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/antlr-discussion/CALe4hHWWvu5mDTRYWFLWXRFpWMQ2vrp-ga2CzpaqihVWp1wC-w%40mail.gmail.com.


--
 
Reply all
Reply to author
Forward
0 new messages