开发者

separate return statement from other statements ANTRL

here's part from my grammar.

statement
    :   assignmentStatement
    |       doLoopStatement 
    |   whileStatement
    |   ifStatement
    |   procedureCallStatement
    ;


functio开发者_如何学Cn 
    : 'FUNCTION' IDENT '(' parameters? ')' ':' type ':=' 
         (variable (';' variable)*)?
        'BEGIN'
            main_body  //body can be empty
            return_Statement 
        'END' IDENT
    ;

where main_body is:

main_body
    : (statement (';' statement)*)?
    ;

now, before creating my AST, I need to fix the return statement,

the problem is that the assignmentStatement and return_Statement and so I'm getting a LL(*) error from the parser, as it does not know what to choose.

assignmentStatement
    :   IDENT ':=' expression
    ;

return_Statement
    :   IDENT ':=' expression
    ;

any ideas?


If assignmentStatement is really supposed to be identical to return_Statement then there's no reason to have both. Eliminate the return_Statement rule and in your function rule replace it with assignmentStatement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜