Cover
Table of Contents
Acknowledgments
Welcome Aboard!
Who Is This Book For?
What's So Cool About ANTLR V4?
What's in This Book?
Learning More About ANTLR Online
Part I—Introducing ANTLR and Computer Languages
1. Meet ANTLR
Installing ANTLR
Executing ANTLR and Testing Recognizers
2. The Big Picture
Let's Get Meta!
Implementing Parsers
You Can't Put Too Much Water into a Nuclear Reactor
Building Language Applications Using Parse Trees
Parse-Tree Listeners and Visitors
3. A Starter ANTLR Project
The ANTLR Tool, Runtime, and Generated Code
Testing the Generated Parser
Integrating a Generated Parser into a Java Program
Building a Language Application
4. A Quick Tour
Matching an Arithmetic Expression Language
Building a Calculator Using a Visitor
Building a Translator with a Listener
Making Things Happen During the Parse
Cool Lexical Features
Part II—Developing Language Applications with ANTLR Grammars
5. Designing Grammars
Deriving Grammars from Language Samples
Using Existing Grammars as a Guide
Recognizing Common Language Patterns with ANTLR Grammars
Dealing with Precedence, Left Recursion, and Associativity
Recognizing Common Lexical Structures
Drawing the Line Between Lexer and Parser
6. Exploring Some Real Grammars
Parsing Comma-Separated Values
Parsing JSON
Parsing DOT
Parsing Cymbol
Parsing R
7. Decoupling Grammars from Application-Specific Code
Evolving from Embedded Actions to Listeners
Implementing Applications with Parse-Tree Listeners
Implementing Applications with Visitors
Labeling Rule Alternatives for Precise Event Methods
Sharing Information Among Event Methods
8. Building Some Real Language Applications
Loading CSV Data
Translating JSON to XML
Generating a Call Graph
Validating Program Symbol Usage
Part III—Advanced Topics
9. Error Reporting and Recovery
A Parade of Errors
Altering and Redirecting ANTLR Error Messages
Automatic Error Recovery Strategy
Error Alternatives
Altering ANTLR's Error Handling Strategy
10. Attributes and Actions
Building a Calculator with Grammar Actions
Accessing Token and Rule Attributes
Recognizing Languages Whose Keywords Aren't Fixed
11. Altering the Parse with Semantic Predicates
Recognizing Multiple Language Dialects
Deactivating Tokens
Recognizing Ambiguous Phrases
12. Wielding Lexical Black Magic
Broadcasting Tokens on Different Channels
Context-Sensitive Lexical Problems
Islands in the Stream
Parsing and Lexing XML
Part IV—ANTLR Reference
13. Exploring the Runtime API
Library Package Overview
Recognizers
Input Streams of Characters and Tokens
Tokens and Token Factories
Parse Trees
Error Listeners and Strategies
Maximizing Parser Speed
Unbuffered Character and Token Streams
Altering ANTLR's Code Generation
14. Removing Direct Left Recursion
Direct Left-Recursive Alternative Patterns
Left-Recursive Rule Transformations
15. Grammar Reference
Grammar Lexicon
Grammar Structure
Parser Rules
Actions and Attributes
Lexer Rules
Wildcard Operator and Nongreedy Subrules
Semantic Predicates
Options
ANTLR Tool Command-Line Options
A1. Bibliography
Index
– SYMBOLS –
– A –
– B –
– C –
– D –
– E –
– F –
– G –
– H –
– I –
– J –
– K –
– L –
– M –
– N –
– O –
– P –
– R –
– S –
– T –
– U –
– V –
– W –
– X –