O'Reilly logo

The Definitive ANTLR 4 Reference, 2nd Edition by Terence Parr

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required