The Definitive ANTLR 4 Reference, 2nd Edition

Book description

Programmers run into parsing problems all the time. Whether it's a data format like JSON, a network protocol like SMTP, a server configuration file for Apache, a PostScript/PDF file, or a simple spreadsheet macro language--ANTLR v4 and this book will demystify the process. ANTLR v4 has been rewritten from scratch to make it easier than ever to build parsers and the language applications built on top. This completely rewritten new edition of the bestselling Definitive ANTLR Reference shows you how to take advantage of these new features.

Publisher resources

View/Submit Errata

Table of contents

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

Product information

  • Title: The Definitive ANTLR 4 Reference, 2nd Edition
  • Author(s): Terence Parr
  • Release date: January 2013
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781934356999