Read e-book online The Definitive ANTLR 4 Reference, 2nd Edition PDF

By Parr

The Definitive ANTLR four Reference through Parr, Terence [Pragmatic Bookshelf, 2013]...

Show description

Read Online or Download The Definitive ANTLR 4 Reference, 2nd Edition PDF

Similar reference books

Read e-book online Operations Management (11th Edition) (Operations and PDF

The 11th version of Stevenson's Operations administration good points built-in, updated insurance of present themes and developments, whereas keeping the middle options that experience made the textual content the marketplace chief during this direction for over a decade. Stevenson's cautious motives and approachable structure help scholars in knowing the real operations administration strategies in addition to utilising instruments and strategies with an emphasis on challenge fixing.

Download PDF by Frank Starke: Die keilschrift-luwischen Texte in Umschrift

Das aus 279 Tafelstucken unterschiedlicher Grosse bestehende Corpus der Texte in diesem Band - es handelt sich um magische Rituale, Beschworungen und Festrituale - wurde bereits im sixteen. und 15. Jahrhundert v. Chr. abgefasst. Von wenigen zeitgenossischen Niederschriften abgesehen, sind die Texte uberwiegend in Abschriften des 14.

Additional resources for The Definitive ANTLR 4 Reference, 2nd Edition

Sample text

One of ANTLR v4’s most significant new features is its ability to handle (most kinds of) left-recursive rules. A left-recursive rule is one that invokes itself at the start of an alternative. For example, in this grammar, rule expr has alternatives on lines 11 and 12 that recursively invoke expr on the left edge. Specifying arithmetic expression notation this way is dramatically easier than what we’d need for the typical top-down parser strategy. In that strategy, we’d need multiple rules, one for each operator precedence level.

In conjunction with semantic predicates (Boolean expressions), we can even make parts of our grammar disappear at runtime! For example, we might want to turn the enum keyword on and off in a Java grammar to parse different versions of the language. Without semantic predicates, we’d need two different versions of the grammar. Finally, we’ll zoom in on a few ANTLR features at the lexical (token) level. We’ll see how ANTLR deals with input files that contain more than one language. Then we’ll look at the awesome TokenStreamRewriter class that lets us tweak, mangle, or otherwise manipulate token streams, all without disturbing the original input stream.

First, we need to label the alternatives of the rules. ) Without labels on the alternatives, ANTLR generates only one visitor method per rule. ) In our case, we’d like a different visitor method for each alternative so that we can get different “events” for each kind of input phrase. Labels appear on the right edge of alternatives and start with the # symbol in our new grammar, LabeledExpr. g4 stat: expr NEWLINE | ID '=' expr NEWLINE | NEWLINE ; expr: | | | | ; expr op=('*'|'/') expr expr op=('+'|'-') expr INT ID '(' expr ')' # printExpr # assign # blank # # # # # MulDiv AddSub int id parens Next, let’s define some token names for the operator literals so that, later, we can reference token names as Java constants in the visitor.

Download PDF sample

The Definitive ANTLR 4 Reference, 2nd Edition by Parr


by Donald
4.4

Rated 4.73 of 5 – based on 14 votes