You are previewing The Definitive ANTLR 4 Reference, 2nd Edition.
O'Reilly logo
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.

Table of Contents

  1. The Definitive ANTLR 4 Reference
    1. Copyright
    2. For the Best Reading Experience...
    3. Table of Contents
    4. Early Praise for The Definitive ANTLR 4 Reference
    5. Acknowledgments
    6. 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
    7. Part 1: Introducing ANTLR and Computer Languages
      1. Chapter 1: Meet ANTLR
        1. Installing ANTLR
        2. Executing ANTLR and Testing Recognizers
      2. Chapter 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. Chapter 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. Chapter 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
    8. Part 2: Developing Language Applications with ANTLR Grammars
      1. Chapter 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. Chapter 6: Exploring Some Real Grammars
        1. Parsing Comma-Separated Values
        2. Parsing JSON
        3. Parsing DOT
        4. Parsing Cymbol
        5. Parsing R
      3. Chapter 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. Chapter 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
    9. Part 3: Advanced Topics
      1. Chapter 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. Chapter 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. Chapter 11: Altering the Parse with Semantic Predicates
        1. Recognizing Multiple Language Dialects
        2. Deactivating Tokens
        3. Recognizing Ambiguous Phrases
      4. Chapter 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
    10. Part 4: ANTLR Reference
      1. Chapter 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. Chapter 14: Removing Direct Left Recursion
        1. Direct Left-Recursive Alternative Patterns
        2. Left-Recursive Rule Transformations
      3. Chapter 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
    11. Appendix 1: Bibliography
      1. You May Be Interested In…