Five minute introduction to ANTLR 3
What is ANTLR 3?
ANTLR – *AN*other *T*ool for *L*anguage *RE*cognition ANother Tool for Language REcognition – is a tool that helps you write language processing tools. It's commonly categorised as a compiler generator or compiler compiler in the tradition of tools such as Lex/Flex and Yacc/Bison). ANTLR takes a grammar description (which may define both a language and how to process the language's constructs) and emits multiple files in your chosen target language (e.g. Java, C/C++, C#, Python, Ruby...).
...
- How to write lexer rules
- How to write basic parser rules
- How to direct tokens away from the parser (to ignore them)
- How to insert executable code into a parser.
Some points to consider:
- You can insert custom actions anywhere.
- Most of your custom code winds up in the last stage of the parsing process. Here it was in the Parser; if you used an AST, it would be in the tree parser.
What next?
This covers the majority of the things you need to know to develop a grammar. You may want to work through another of the tutorials:
- Java programmers can try See Test-Driven Development with ANTLR for an example of building a grammar from the ground up.
- Try the JSON Interpreter or the Simple tree-based interpeter to learn about Abstract Syntax Trees.
...
You could also:
- Order The Definitive ANTLR Reference from the Pragmatic Programmers
- Read the Antlr 3 Documentation
- Chew on the Quick+Starter+on+Parser+Grammars
- Browse the list of questions frequently asked about ANTLR 3
- Try the AntlrWorks IDE for ANTLR 3. AntlrWorks can be downloaded from the AntlrWorks page on the ANTLR website
Special constructs (reference)
...