Cool Lexical Features

ANTLR has three great token-related features that are worth demonstrating in our tour. First, we’ll see how to deal with formats like XML that have different lexical structures (inside and outside tags) in the same file. Next, we’ll learn how to insert a field into a Java class by tweaking the input stream. It’ll show how to generate output that is very similar to the input with minimal effort. And, lastly, we’ll see how ANTLR parsers can ignore whitespace and comments without having to throw them out.

Island Grammars: Dealing with Different Formats in the Same File

All the sample input files we’ve seen so far contain a single language, but there are common file formats that contain multiple languages. For example, ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.