[antlr-interest] Hopefully just a little more help with syntax for semantic predicates?
dhjdhj
dhjdhj at gmail.com
Fri May 15 11:34:38 PDT 2009
I have been trying all day to get the rule below accepted (oh yeah,
that doesn't count about 2 hours wasted before I figured out that you
can't have a space after the right curly brace and the question mark
in a semantic predicate (grin))
I get a "cannot generate the grammar because" error which is
rule expression alt 1 uses rewrite syntax and also an AST operator
Now, I'm pretty certain this is happening because of the "^" that
follows lhs = simpleExpression^ in the first section of the rule.
However, removing that operator causes no tree node to be generated in
the case where there is just a simple expression. However, I tried
removing that operator and adding a rewrite rule after the FIRST
closing right brace, e.g.
lhs = simpleExpression
{
$type = $lhs.type;
} -> ^($lhs)
and many variants but this just caused ANTLR to complain that
comparisonOperator was an unexpected token. I also tried inserting a
third predicate in the bottom group that would test whether $rhs was
null and just put out the $lhs in that case but that didn't work either.
Can somebody please put me out of my misery (in a kind manner (grin))
and show me what I'm doing wrong? I'd love to have a quiet weekend
with no problems to worry about!!!
Thanks,
D
------------------------------------------------------------------
expression returns [TAttributeType type]
:
optionalSign
lhs = simpleExpression^
{
$type = $lhs.type;
}
(
(comparisonOperator rhs = simpleExpression)
{
$type =
TErrorHandling.Compatible($comparisonOperator.tree.token,
$comparisonOperator.token, $lhs.type, $rhs.type);
}
-> { isString($lhs.type) }? ^(comparisonOperator
STRINGOP $lhs $rhs)
-> ^(comparisonOperator $lhs $rhs)
)*
;
More information about the antlr-interest
mailing list