how to use antlr4 visitor

感情迁移 提交于 2019-12-03 02:37:31

You have to call super if you want ANTLR4 to visit children. Like this:

@Override 
public Integer visitPgm_body(@NotNull MicroParser.Pgm_bodyContext ctx){
    super.visitPgm_body(ctx);
    System.out.println(ctx.getText());
    return 467;
}

@Override
public Integer visitProgram(@NotNull MicroParser.ProgramContext ctx){
    super.visitProgram(ctx);
    System.out.println("11");
    return 456;
}

You have to think about where to put your logic: before super or after.

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