Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Antlr4 如何为集合编写访问者类?_Antlr4 - Fatal编程技术网

Antlr4 如何为集合编写访问者类?

Antlr4 如何为集合编写访问者类?,antlr4,Antlr4,本书中的示例LabeledExpr.g4描述了如何为Singleton使用visitor类。但是如果我想参观一个收藏的课程,我该怎么做呢?e、 g.关于语法: prog: stat+ ; stat: expr NEWLINE # printExpr ; 用于打印的访问者功能如下所示: public Integer visitPrintExpr(LabeledExprParser.PrintExprContext ctx) { Integer value =

本书中的示例LabeledExpr.g4描述了如何为Singleton使用visitor类。但是如果我想参观一个收藏的课程,我该怎么做呢?e、 g.关于语法:

prog:   stat+ ;
stat:   expr NEWLINE   # printExpr
        ;
用于打印的访问者功能如下所示:

public Integer visitPrintExpr(LabeledExprParser.PrintExprContext ctx) {
    Integer value = visit(ctx.expr()); // evaluate the expr child
    System.out.println(value);         // print the result
    return 0;                          // return dummy value
}
“stat+”对应的访问者函数是什么,这样我就可以遍历“stat”列表了

我寻找这个的原因是,我可能希望首先解析整个对象模型并将其存储在内存中,然后对其进行多次访问和分析(而不是像书中的示例所示的那样进行动态评估/打印)

一个相关的问题是,如果我在语法文件中创建一些数据结构(如本书中的ActionExpr.g4所示),我如何在访问者函数中访问这些数据结构?e、 g.如何在访问者函数中访问下面创建的Expr类

stat  [Expr e]
      :   expr NEWLINE   # printExpr
           {$e = new Expr($expr);}
      ;

生成的
ProgContext.stat()
方法返回完整的集合。您可以从访问者的
visitProg
方法中访问它。

谢谢。但现在我有一个不同的问题——代码在eclipse中工作,但在命令行中不工作(既不是windows,也不是unix)。我已经发布了一个不同的问题,因为它看起来像某种错误-20138858。