[antlr-interest] Newbie Issues: MismatchedTokenExceptions and FailedSyntacticPredicates
Benji Smith
benji at benjismith.net
Thu Jul 12 12:26:07 PDT 2007
Hi. I'm new to this list, and new to ANTLR in general, though I have
quite a bit of experience on a previous project implementing a DSL
compiler with JavaCC (I'm switching to ANTLR primarily because of
support for C#).
I'm currently developing a grammar for stock-market indicators. For
example, when complete it'll allow a user to define an indicator like
this:
<code>
// In technical analysis, the "MACD" symbol represents a "Moving Average
// Convergence Divergence" indicator. This indicator is a simple arithmetic
// function over a "slow" exponential moving average (EMA), and a "fast"
// exponential moving average.
indicator MACD[m, n] : EMA[m](CLOSE) - EMA[n](CLOSE)
</code>
But I'm getting ahead of myself. For now, I'm just trying to get the
left-hand side of the assignment expression to parse correctly. The
attached grammar file (VTExpression.g) was written to parse syntax
like "indicator MACD[m, n]", as well as "indicator EMA[3]" or
"indicator XYZ[true, 5, 3 + (n % 2) ]".
But even on the simplest stuff ("indicator EMA[3]"), I get a
MismatchedTokenException from the ANTLRWorks interpreter at the top
level of the expression. I tried rewriting the grammar
(VTExpression2.g) to use string literals in the rule definitions
instead of tokens, and the error went away. (Why? Shouldn't the lexer
& parser be identical at this point, whether the grammar uses tokens
or string literals in the rules?)
Now, using the tokenless grammar (VTExpression2.g), the interpreter
gets inside the left-bracket, but it fails to recognize the "3" as an
IntegerLiteral, instead throwing a FailedPredicateException (between
primaryExpression and synpred19).
When I do a google search on syntactic predicates, I can see that
they're defined like this:
(...)=>
But I'm not doing that. Whenever I've seen these failed predicate
problems, it's from ordinary stuff like this:
A : B ( op_a B)* ;
B : C ( op_b C)* ;
I don't understand where all of these synpred objects come from. As
far as I can tell, I'm never actually using a syntactic predicate.
I feel a little silly grappling with errors parsing such simple little
expressions. The stuff I used to do in JavaCC was significantly more
complex than this. Is it just me, or do many other people find ANTLR a
lot more difficult to use?
Anyhow, thanks for whatever help you can offer. I appreciate it.
--benji smith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VTExpression.g
Type: application/octet-stream
Size: 4041 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070712/ba207b10/attachment.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VTExpression2.g
Type: application/octet-stream
Size: 3077 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070712/ba207b10/attachment-0001.obj
More information about the antlr-interest
mailing list