ANTLR Section Index | Page 5
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
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
Use the lexer grammar option "filter=true" or "filter=MySkipRule". See ANTLR Masquerading as SED and ANTLR Meets Sed.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
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
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 email@example.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
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
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
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
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