ANTLR Section Index | Page 3
How do I make ANTLR build a lexer that uses my own token class?
You can set the factory used to generate
Tokens with a call to setTokenObjectFactory.
Check out the java/C++ file for CharScanner.
Or, tell the lexer what class you want to use:
public static v...more
Where can I find examples of C++, JScript, VBScript, C, XML, Java Class grammars for ANTLR? Is there any repository out there in the internet?
Where can I find examples of C++, JScript, VBScript, C, XML,
Java Class grammars for ANTLR? Is there any repository
out there in the internet?
Is it possible to build a (valid or invalid) sentence generator from a grammar?
The general answer to getting the set of valid sentences is "no"
because there are infinitely long strings, but that only matters in
theory. If you limit the input to k-token length sen...more
How does one report a bug?
For now, please post potential bugs to the ANTLR forum.
How can I force ANTLR to match the tokens in the "tokens {...}" section case-insensitive?
When you're extending the Lexer, set the options as
caseSensitive=false;
caseSensitiveLiterals=false;
Here you must Put All Tokens in LowerCase.
EX:
tokens
{
ROSE="rose";
...more
Why doesn't the lexer match any of the literals from my "tokens" section?
The most common problem is that your lexer does not have a rule that
can match a pattern that includes your literals. For example, there
is no rule that can match the text for "blort", ...more
Why does ANTLR sometimes go into an infinite loop when constructing AST trees?
Turn off default AST construction for that rule
eg rule was
assignmentExpression
: lhs:lhsExpression ASSIGN! ex:expression
{#assignmentExpression = #(#[ASSIGN_EXPR,"ASSIGN"],#l...more
Can I use French (UNICODE) characters in my ANTLR grammar (versus the files I parse with it)?
As of 2.7.2, yes, you can.
Why is the (...)* loop below nondeterministic for any k (is this an example of ANTLR computing linear approximate lookahead)?
Why is the (...)* loop below nondeterministic for any k (is
this an example of ANTLR computing linear approximate lookahead)?
a: b S b B ;
b: A (B A)* ;
What does LL(k) means?
The first letter, L for left to right or R for right to left, denotes the order in which to scan the source
text.
The second letter denotes the derivation of the constructed parse tree. At each ...more
How can I throw my own exception out of a parser or tree walker?
Please see 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?
more
When should I use ANTLR instead of PERL?
When you come to your senses... ;-)
It really depends on what you are trying to do. ANTLR is a parser that allows you to define vocabularies/grammars through a meta-language and then uses the gra...more
How do I distinguish keywords from identifiers and how can I have all keywords returned as KEYWORD?
T. Parr: Just reference strings in your parser and the lexer will add them to a hashtable which it checks upon each completed token. If the token matches a "keyword" it returns that tok...more
I'm working on the lexer for a language which allows abbreviated keywords Any suggestions for handling this in ANTLR's lexer?
I'm working on the lexer for a language which allows abbreviated keywords (ex: "display" "disp" "displ" and "displa" are all treated as "display")....more
How do I pass extra parameters to AST constructors?
You can't. ASTs define initialize() methods that take either an AST node or a Token object. The appropriate place is to make your own subclass of either Token or AST which can hold the data your...more