ANTLR Section Index | Page 5
Are parsers generated by ANTLR thread-safe? Can I parse multiple inputs concurrently?
The simple answer is "yes", however, if you try to parse the same input using the same object with more than one thread the answer is "no". Fortunately, parsing is, for the mo...more
Has anyone constructed a grammar file for English, Spanish, or other natural language?
No. Naturally language is considered a much more difficult problem than the deterministic, unambiguous parsing of programming languages, data formats, and the like. That said, you can do a prett...more
How can I make a lexer throw away characters until a rule is satisfied?
Use the lexer grammar option "filter=true" or "filter=MySkipRule". See ANTLR Masquerading as SED and ANTLR Meets Sed.more
How can I use multiple lexers to scan my input (how do I get "lexer states")?
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
How can I use the same lexer with multiple parsers?
Lexers are just objects, so you can attach any parser you want to instances of the same object (just don't have the parsers operate simultaneously--lexers only work on one input stream at a time)....more
How do I signal the parser to bail out immediately upon detection of a syntax error, instead of trying to consume tokens until it resynchs?
ANTLR generates catch-clauses to catch RecognitionException objects thrown by
rules (parsers and tree-parsers). Parser rules can throw either
RecognitionException objects or TokenStreamException ...more
Is there an ANTLR grammar/parser for language X?
The list changes constantly as people build more and more parsers and translators with ANTLR; some of these people make their work available. Your best bet is to ask antlr-interest@egroups.com, t...more
Using the heterogenous tree construction facility, how can I force all the AST nodes created be of type MyASTNode thereby doing away the required casting from AST*?
Forcing all tree nodes to be the same kind of object makes them homogeneous trees not heterogeneous trees. If you are asking how to get ANTLR to generate variable references as MyASTNode, then ju...more
Why does ANTLR generate an if-then-else for an optional subrule where the else-clause tests for what follows the subrule?
Summary: ANTLR tries to detect errors as soon as possible.
To make the question more concrete, look at this grammar fragment:
r : (A)? B ;
For the optional subrule and B reference, ANTLR g...more
How can I get AWK or SED type filtering behavior?
The core of the answer is: use the filter option in the lexer. This option is used in a simple form where filter=true and in a more sophisticated form of filter=SKIP_RULE. The first just says, &...more
How do I use a non-ANTLR-generated (C++) lexer into an ANTLR-generated parser?
Subclass your scanner from antlr::TokenStream
and make it adhere to the interface defined
by TokenStream. Basically this comes down to defining
a nextToken function in your scanner class.
I use...more
How do you design the parser to retain identifiers to check if the same identifier is being repeated later in the input?
You need what we typically call a symbol table. This is usually just a hashtable that records the symbols you see in a particular scope (if you have scopes, that is). So, if you see the definiti...more
Is it possible to parse/lex UNICODE characters with ANTLR?
Yes. See Scanning Unicode Characters for a full description.
I hope to support predefined UNICODE sets now like LETTER but that will wait for 2.7.3 I think.
As of 2.7.2, you can use European ...more
Can a tree parser inherit from another tree parser?
Sure. In fact, this is a great way to do multiple-phase tree transformations. Have the super grammar contain all common rules and the complete set of token types used by your system so that the ...more
When I inherit rules from another grammar, the generated output parser actually includes the combined rules of my grammar and the supergrammar. Why doesn't the generated parser class just inherit from the class generated from the supergrammar?
In Java, when one class inherits from another, you override methods to change the behavior. The same is true for grammars except that changes a rule in a subgrammar can actually change the lookah...more