ANTLR Section Index
Greg Lindholm points out: ANTLR doesn't have a way of specifing start-of-line as part of a rule. Once you have entered a rule you can use a sematic predicate to check what column your at, but t...more
What's the difference between a parse tree and an abstract syntax tree (AST)? Why doesn't ANTLR generate trees with nodes for grammar rules like JJTree does?
A parse tree is a record of the rules (and tokens) used to match some input text whereas a syntax tree records the structure of the input and is insensitive to the grammar that produced it. Note ...more
Complicated input languages often have a few lexical constructs that are really nested lexical structures such as Java's javadoc comments, regular comments, or even just strings. In other words, ...more
All I know is that I need to build a parser or translator. Give me an overview of what ANTLR does and how I need to approach building things with ANTLR.
[See also Getting started ] To build a language recognizer, you specify the structure of that langage with a grammar and then have ANTLR generate a Java or C++ class definitio...more
To illustrate the problem, let's take a subset of fortran. Say the lexer returns a character at a time, eating up the white space. statement : D O (DIGIT)+ id EQ num COMMA num | id EQ...more
Where can I learn (more) about using various XML (eXtensible Markup Language) technologies (such as DTDs, Schemas, SOAP, DOMs, etc.) with Java?
Check out the jGuru XML FAQ.
Check out the jGuru IO FAQ.
Imagine input: class P extends Parser; a : "a" A ; class L extends Lexer; A : "a"; ANTLR will think "a" and A are two different tokens as it doesn't know that in the Lexer you will define A...more
Check out the article describing conversion of the old C++ grammar to new ANTLR. This is based on Tom Nurkkala's original article.more
Only simple, so-called syntax directed translations can be done with actions within the parser. These kinds of translations can only spit out constructs that are functions of information already ...more
In most general terms, the strategy for building a translator can be summarized as follows: Parse the input file(s) in the old language, constructing a tree representing the structure of the inp...more
Why does ANTLR say that two of my lexer rules are ambiguous? Or, why am I having so much trouble with DOT or PERIOD at the left-edge of lexer rules?
Imagine that your grammar (prolog) has two types of tokens that begin with DOT (the period symbol). Specifically the "." may appear alone as the end token or it may appear as the start of a graph...more
Why are trees not built properly when I manually manipulate the return tree (with an action) for a rule?
Generally the problem is that you cannot use manual tree construction actions within a rule that is doing automatic tree construction--you confuse the automatic mechanism. For example, to constru...more
How can I track the character position within an input file? I want know at what index does a token start.
One way is to implement your own input stream and to override all the read() methods (much like FilterInputStream). You can supply an instance of this stream to the lexer's constructor. Note t...more
You are thinking in terms of the old one-token-of-lookahead type parser generators without backtracking capabilities. ANTLR specifically provides a mechanism to lookahead ahead a fixed amount, k,...more