Java 在Antlr4中找不到符号

Java 在Antlr4中找不到符号,java,antlr4,Java,Antlr4,这是我的SimpleBaseListner.java文件 // Generated from Simple.g4 by ANTLR 4.7.1 import org.antlr.v4.runtime.tree.ParseTreeListener; /** * This interface defines a complete listener for a parse tree produced by * {@link SimpleParser}. */ public interface

这是我的SimpleBaseListner.java文件

// Generated from Simple.g4 by ANTLR 4.7.1
import org.antlr.v4.runtime.tree.ParseTreeListener;

/**
 * This interface defines a complete listener for a parse tree produced by
 * {@link SimpleParser}.
 */
public interface SimpleListener extends ParseTreeListener {
/**
 * Enter a parse tree produced by {@link SimpleParser#file}.
 * @param ctx the parse tree
 */
void enterFile(SimpleParser.FileContext ctx);
/**
 * Exit a parse tree produced by {@link SimpleParser#file}.
 * @param ctx the parse tree
 */
void exitFile(SimpleParser.FileContext ctx);
/**
 * Enter a parse tree produced by {@link SimpleParser#func}.
 * @param ctx the parse tree
 */
void enterFunc(SimpleParser.FuncContext ctx);
/**
 * Exit a parse tree produced by {@link SimpleParser#func}.
 * @param ctx the parse tree
 */
void exitFunc(SimpleParser.FuncContext ctx);
/**
 * Enter a parse tree produced by {@link SimpleParser#arg}.
 * @param ctx the parse tree
 */
void enterArg(SimpleParser.ArgContext ctx);
/**
 * Exit a parse tree produced by {@link SimpleParser#arg}.
 * @param ctx the parse tree
 */
void exitArg(SimpleParser.ArgContext ctx);
/**
 * Enter a parse tree produced by {@link SimpleParser#body}.
 * @param ctx the parse tree
 */
void enterBody(SimpleParser.BodyContext ctx);
/**
 * Exit a parse tree produced by {@link SimpleParser#body}.
 * @param ctx the parse tree
 */
void exitBody(SimpleParser.BodyContext ctx);
/**
 * Enter a parse tree produced by {@link SimpleParser#block}.
 * @param ctx the parse tree
 */
void enterBlock(SimpleParser.BlockContext ctx);
/**
 * Exit a parse tree produced by {@link SimpleParser#block}.
 * @param ctx the parse tree
 */
void exitBlock(SimpleParser.BlockContext ctx);
/**
 * Enter a parse tree produced by {@link SimpleParser#var}.
 * @param ctx the parse tree
 */
void enterVar(SimpleParser.VarContext ctx);
/**
 * Exit a parse tree produced by {@link SimpleParser#var}.
 * @param ctx the parse tree
 */
void exitVar(SimpleParser.VarContext ctx);
/**
 * Enter a parse tree produced by {@link SimpleParser#stat}.
 * @param ctx the parse tree
 */
void enterStat(SimpleParser.StatContext ctx);
/**
 * Exit a parse tree produced by {@link SimpleParser#stat}.
 * @param ctx the parse tree
 */
void exitStat(SimpleParser.StatContext ctx);
}
当我使用
javac SimpleBaseListner.java
编译此文件时,我得到以下内容
错误:

我是Antlr4的新手,我不知道这里出了什么问题。虽然is表示找不到符号,但此类型范围在语法文件中定义。因此,据我所知,它应该在Antlr4编译语法文件时定义


有人能帮我吗

缺少
范围
源文件。在获取语法文件的存储库中找到它:(有多个作用域实现)

例如,这个:

// source: https://github.com/parrt/cs652/blob/master/labs/symtab-mono/src/symtab/BasicScope.java
package symtab;

import java.util.HashMap;
import java.util.Map;

public class BasicScope implements Scope {
    public Map<String,Symbol> symbols = new HashMap<>();

    @Override
    public String getScopeName() {
        return "<unknown>";
    }

    @Override
    public void define(Symbol s) {
        symbols.put(s.name, s);
    }

    @Override
    public Symbol resolve(String name) {
        Symbol s = symbols.get(name);
        if ( s!=null ) return s;
        if ( getEnclosingScope()!=null ) {
            return getEnclosingScope().resolve(name);
        }
        return null;
    }

    @Override
    public Scope getEnclosingScope() {
        return null;
    }
}

您可能需要的其他类可以在这里找到:

我没有看到语法中定义的
范围。我只看到
返回[Scope]
,但这不是类定义。您应该在某个地方有
公共类作用域{…}
。@BartKiers是的,您是对的。它没有定义。你能解释一下那门课应该做什么吗?请核对我的答案
// source: https://github.com/parrt/cs652/blob/master/labs/symtab-mono/src/symtab/BasicScope.java
package symtab;

import java.util.HashMap;
import java.util.Map;

public class BasicScope implements Scope {
    public Map<String,Symbol> symbols = new HashMap<>();

    @Override
    public String getScopeName() {
        return "<unknown>";
    }

    @Override
    public void define(Symbol s) {
        symbols.put(s.name, s);
    }

    @Override
    public Symbol resolve(String name) {
        Symbol s = symbols.get(name);
        if ( s!=null ) return s;
        if ( getEnclosingScope()!=null ) {
            return getEnclosingScope().resolve(name);
        }
        return null;
    }

    @Override
    public Scope getEnclosingScope() {
        return null;
    }
}
// source: https://github.com/parrt/cs652/blob/master/labs/symtab-mono/src/symtab/Scope.java
public interface Scope {
    String getScopeName();
    void define(Symbol s);
    Symbol resolve(String name); // bind or lookup
    Scope getEnclosingScope();
}