Call correct Antlr visitors without call all before visitors ultil match

痞子三分冷 提交于 2020-06-17 13:11:06

问题


I'm a little confused about how to do this. For example, I have this rule:

stat : '(' expression ')'               #ExpressionStatement;

expression1 
    : expression2 ('==' expression2)* #ValidateExpression1 
    ;

expression2
    : literal ('!=' literal)* #ValidateExpression2
    ;

literal
    :  ( 'true' | 'false') #literal
    ;

In this case, if I pass "(true)" to the parser, how can I just visit VisitListeral() and return true instead visiting the entire tree until the match? In the visitor: VisitExpressionStatement() if I do Visit(context.expression()) all visitors will be called, until they reach their correspondent, the VisitLiteral() In this case, and I would be required to implement all previous visitors with all their infinite validations.

来源:https://stackoverflow.com/questions/62283232/call-correct-antlr-visitors-without-call-all-before-visitors-ultil-match

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!