The problem is that you are considering 'else if' as a single token instead of
thinking of the second 'if' as being part of its own statement. Just delete
the
'else if' part of your ifExpr production and make sure that block can be an
ifExpr. That is,
if (cond1) block1
else if (cond2) block2
else block3
is interpreted as
if (cond) block1
else { if (cond2) block2
else block3
}
which, you should find, is what you really want.
--Loring
----- Original Message ----
> From: st3 <[email protected]>
> To: [email protected]
> Sent: Thu, September 2, 2010 9:45:54 AM
> Subject: [antlr-interest] if/else if/else vs. if/elif/else
>
>
> Hi,
>
> I have defined a simple if/else if/else rule (below):
>
> ifExpr : 'if' LRND ifCond=rightExpr RRND ifBlock=block
> ('else if' LRND elifCond+=rightExpr RRND elifBlock+=block)*
> ('else' elseBlock=block)?
>
> this throws the following error:
>
> mismatched character '{' expecting 'i'
> extraneous input '}' expecting 'return '
>
> I can solve it by changing 'else if' to 'elif' - as clearly 'else if' and
> 'else' are confusing the lexer/parser.
>
> However, I was hoping to have the easer-to-read 'else if'.
>
> Can someone suggest how I can accomplish that?
>
> I tried the syntactic predicate ('else if')=> - but that did not work.
>
> Thank you!
> --
> View this message in context:
>http://antlr.1301665.n2.nabble.com/if-else-if-else-vs-if-elif-else-tp5491890p5491890.html
>
> Sent from the ANTLR mailing list archive at Nabble.com.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
>http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.