Recognizing Common Language Patterns with ANTLR Grammars

Now that we have a general top-down strategy for roughing out a grammar, we need to focus on the common language patterns: sequence, choice, token dependence, and nested phrase. We saw a few examples of these patterns in the previous section, but now we’re going to see many more examples from a variety of languages. As we go along, we’ll learn basic ANTLR notation by expressing the specific patterns as formal grammar rules. Let’s start with the most common language pattern.

Pattern: Sequence

The structure you’ll see most often in computer languages is a sequence of elements, such as the sequence of methods in a class definition. Even simple languages like the HTTP, POP, and SMTP network ...

Get The Definitive ANTLR 4 Reference, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.