Java Tools Section Index | Page 94
Can I compile ANTLR to a binary executable (with GCJ?)?
get & install gcj and libgcj. Both can be found at:
http://sourceware.cygnus.com/java/download.html
gcj is part of the GNU compiler (gcc 2.95.1) and libgcj is a
separa...more
How can I get an exception thrown in the lexer to escape out to the parser's invoker?
[Version 2.7.0 or greater; earlier versions didn't have the
TokenStreamException hierarchy]
Use a filter rule to trap invalid sequences and throw a
TokenStreamRecognitionException, which is a
To...more
How can I know the context of an expression, like whether it is a statement itself or part of a while statement or actually a sub-expression?
Add some single element rules. Consider this grammar:
program: (statement)* ;
statement: #("print" topexpr)
| #("while" topexpr (statments)*)
| stmtexpr
;
stmtexentp:pr: topexpr ;...more
How can I tell what subtree my tree walker is screwing up on?
Try adding an exception handler to the rule. I cheat and use the _t
variable which is passed into every tree rule and is eqivalent to LA(1) in
the parser.
constant
options {
defaultError...more
How did I get an infinite loop in my parser?
Check for loops over rules with an empty alternative.
How do I build a list of nodes with no root?
I want to translate a subtree like #(CHAIN ID) into three
nodes like #(#[ASSIGNMENT], ID, ID) followed by #[NEWLINE, " : "] then
#[EXIT_SUB]. I haven't
found any examples of how to do this using...more
How do I fix this error: Incompatible type for method. Can't convert arev.ArevAST to int.
Lets say you have something like this:
functionargs
: #(FUNCTIONARGS ((a:expr) (b:expr)?)? )
{
## = #(#[FUNCTIONARGS, "FUNCTIONARGS"], #a);
}
;
What happens is that...more
I want to use a syntactic predicate, but only with one alternative.
Sometimes you use rules with an empty alternative with syntactic predicates.
In R/BASIC a COLON could be used as an operator in an expression, or it
could follow an expression to end a PRINT stat...more
If you change a rule action to do manual tree building, don't forget to put the '!' on that alternative to turn off the automatic tree building--the results can be quite confusing.
question field says it all
My actions aren't getting executed when evaluating my syntactic predicates.
My actions aren't getting executed when evaluating my syntactic predicates.
Why not?
What am I doing to get a cycle in my tree?
Remember that tree construction doesn't deal only with nodes, but with
siblings as well.
I was trying to turn #(PLUSEQ pi:idRef pe:expr) into
#(ASSIGNMENT pi #(PLUS pi pe)) (Like a+=b --> a =...more
What is a "protected" lexer rule?
A lexer is a TokenStream source that merely spits out a
stream of Token objects to the parser (or another stream
consumer). As such, a lexer implements method nextToken() to
satisfy interface Tok...more
What is ANTLR?
ANTLR, Another Tool for Language Recognition,(formerly PCCTS) is a parser and translator generatortool, akin to the venerable lex/yacc duo, that lets you constructrecognizers, compilers, an...more
When do I use labels versus return values?
Return values are provided because every rule is really a method, and people
are used to being able to pass parameters into methods and have a return
value. You declare this yourself and can do ...more
You can use ## as shorthand for the current rule subtree node in a tree walker. In PCCTS this was #0.
question field says it all