From time to time I answer questions about ANTLR on Stackoverflow, and while doing so, I see many people using ANTLR up to a certain point and then ask themselves: "Okay, how do I proceed from here on? What do I do after creating an AST from my source code?". I hope to answer those questions by creating a small programming language called Tiny Language (TL henceforth) that will be parsed by ANTLR and then interpreted using plain Java code.
Don't worry if certain things are (already) a bit vague: I'll write the coming blogs in such a way that people without prior ANTLR experience and without a Computer Science background can follow them. Or, better said: I hope they will! The only thing you need to know is Java.
This tutorial consists of the following parts:
- TL specification
- Introduction to ANTLR
- Lexical analysis of TL
- Syntactic analysis of TL
- Building an AST
- Creating a tree grammar
- Interpreting and evaluating TL I
- Interpreting and evaluating TL II
- Room for improvement & recommendations