antlr4 - Is it possible to visit a rule without any of the lexer tokens defined in grammar? -
if have rule:
player : self | opp; self : 'self'; opp : 'opp' | 'opponent';
is possible visit player rule without having self or opp tokens?
here code more concrete:
@override public object visitplayer(playercontext ctx) { if (ctx.self() != null) { return behaviorexecutor.this.game.getplayerstates() .get(behaviorexecutor.this.selfindex); } else if (ctx.opp() != null) { return behaviorexecutor.this.game.getplayerstates() .get(behaviorexecutor.this.oppindex); } //is possible here? behaviorexecutor.this .logger.log("neither self nor opp token found when visiting player rule."); return null; }
the visitor not visit rules -- visits parse tree nodes. node not created , added parse tree unless of symbols of corresponding rule (or of alternative subrule) validly matched against sequence of source token instances. so, normally, 'here' not reachable.
of course, if parse tree manually modified after construction, there no guarantee children of node correspond parser rule's definition of node.
Comments
Post a Comment