[antlr-interest] weird behavior

Alexandru Mosoi brtzsnr at gmail.com
Mon Mar 17 17:30:50 PDT 2008


This is a part of my grammar (a homework similar to pascal)



conditionalStatement
    : (KW_IF blah KW_THEN ID KW_ELSE ID) => (KW_IF^ blah KW_THEN! ID
KW_ELSE! ID)
    | (KW_IF blah KW_THEN ID) => (KW_IF^ blah KW_THEN! ID)
    ;


termExpression
    : binaryExpression *// ((STAR^ | SLASH^ | KW_DIV^ | KW_MOD^)
binaryExpression)**
    ;

binaryExpression
    : unaryExpression ((LT^ | GT^ | LE^ | GE^ | EQUAL^ | NOT_EQUAL^)
unaryExpression)?
    ;

unaryExpression
    : variable
    | constant
    | functionCallWithArgs
    | KW_NOT^ unaryExpression
    | MINUS^ unaryExpression
    | LPAREN baseType RPAREN unaryExpression -> ^(CAST baseType
unaryExpression)
    | LPAREN expression RPAREN -> expression
    ;


blah
    : *binary*Expression
    ;


If blah is binaryExpression, the input is parsed without problems. however
if I do blah termExpression I get:
"line 2:1 no viable alternative at input 'instructiunetrue'. (blah is only
used in conditionalStatemen an termExpression was commented out so that it's
identical to binaryExpression).

This is in input in both cases

if conditie then
        instructiunetrue
else
        instructiunefalse


Anybody, any idea why is this happening?

-- 
Alexandru Moşoi
http://alexandru.mosoi.googlepages.com

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080318/20bb154e/attachment-0001.html 


More information about the antlr-interest mailing list