我正在上一门有关编译器技术的类(class)。我已经创建了一个g4格式的文件,当我尝试使用java编译器(javac)进行编译时会对其进行编译,这给了我很多错误。
有人可以解释我在做什么错吗?
在下面,我显示了我正在输入的内容和我做错的事情。
我尝试检查是否没有安装antlr4,但是我已经安装了,并且我确定已经安装了。
是否通过Microsoft Store通过Ubuntu应用程序进行了每次安装,而我正在Windows 10上使用Ubuntu终端。
:~$ cd /mnt/c/Users/myUser/dato
:/mnt/c/Users/myUser/dato$ antlr4 dato.g4
:/mnt/c/Users/myUser/dato$ javac *.java
datoBaseListener.java:3: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.ParserRuleContext;
^
datoBaseListener.java:4: error: package org.antlr.v4.runtime.tree does not exist
import org.antlr.v4.runtime.tree.ErrorNode;
^
datoBaseListener.java:5: error: package org.antlr.v4.runtime.tree does not exist
import org.antlr.v4.runtime.tree.TerminalNode;
^
datoListener.java:2: error: package org.antlr.v4.runtime.tree does not exist
import org.antlr.v4.runtime.tree.ParseTreeListener;
^
datoListener.java:8: error: cannot find symbol
public interface datoListener extends ParseTreeListener {
^
symbol: class ParseTreeListener
datoParser.java:3: error: package org.antlr.v4.runtime.dfa does not exist
import org.antlr.v4.runtime.dfa.DFA;
^
datoParser.java:12: error: cannot find symbol
public class datoParser extends Parser {
^
symbol: class Parser
datoParser.java:92: error: cannot find symbol
public static class StartContext extends ParserRuleContext {
^
symbol: class ParserRuleContext
location: class datoParser
datoBaseListener.java:31: error: cannot find symbol
@Override public void enterEveryRule(ParserRuleContext ctx) { }
^
symbol: class ParserRuleContext
location: class datoBaseListener
datoBaseListener.java:37: error: cannot find symbol
@Override public void exitEveryRule(ParserRuleContext ctx) { }
^
symbol: class ParserRuleContext
location: class datoBaseListener
datoBaseListener.java:43: error: cannot find symbol
@Override public void visitTerminal(TerminalNode node) { }
^
symbol: class TerminalNode
location: class datoBaseListener
datoBaseListener.java:49: error: cannot find symbol
@Override public void visitErrorNode(ErrorNode node) { }
^
symbol: class ErrorNode
location: class datoBaseListener
datoParser.java:93: error: cannot find symbol
public Token d;
^
symbol: class Token
location: class StartContext
datoParser.java:94: error: cannot find symbol
public TerminalNode EOF() { return getToken(datoParser.EOF, 0); }
^
symbol: class TerminalNode
location: class StartContext
datoParser.java:95: error: cannot find symbol
public TerminalNode MYTOKEN() { return getToken(datoParser.MYTOKEN, 0); }
^
symbol: class TerminalNode
location: class StartContext
datoParser.java:96: error: cannot find symbol
public StartContext(ParserRuleContext parent, int invokingState) {
^
symbol: class ParserRuleContext
location: class StartContext
datoParser.java:101: error: cannot find symbol
public void enterRule(ParseTreeListener listener) {
^
symbol: class ParseTreeListener
location: class StartContext
datoParser.java:105: error: cannot find symbol
public void exitRule(ParseTreeListener listener) {
^
symbol: class ParseTreeListener
location: class StartContext
datoParser.java:15: error: cannot find symbol
protected static final DFA[] _decisionToDFA;
^
symbol: class DFA
location: class datoParser
datoParser.java:16: error: cannot find symbol
protected static final PredictionContextCache _sharedContextCache =
^
symbol: class PredictionContextCache
location: class datoParser
datoParser.java:43: error: cannot find symbol
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
^
symbol: class Vocabulary
location: class datoParser
datoParser.java:72: error: cannot find symbol
public Vocabulary getVocabulary() {
^
symbol: class Vocabulary
location: class datoParser
datoParser.java:86: error: cannot find symbol
public ATN getATN() { return _ATN; }
^
symbol: class ATN
location: class datoParser
datoParser.java:88: error: cannot find symbol
public datoParser(TokenStream input) {
^
symbol: class TokenStream
location: class datoParser
datoParser.java:110: error: cannot find symbol
public final StartContext start() throws RecognitionException {
^
symbol: class RecognitionException
location: class datoParser
datoParser.java:137: error: cannot find symbol
public static final ATN _ATN =
^
symbol: class ATN
location: class datoParser
datoParser.java:2: error: package org.antlr.v4.runtime.atn does not exist
import org.antlr.v4.runtime.atn.*;
^
datoParser.java:4: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.*;
^
datoParser.java:5: error: package org.antlr.v4.runtime.misc does not exist
import org.antlr.v4.runtime.misc.*;
^
datoParser.java:6: error: package org.antlr.v4.runtime.tree does not exist
import org.antlr.v4.runtime.tree.*;
^
datoLexer.java:2: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.Lexer;
^
datoLexer.java:3: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.CharStream;
^
datoLexer.java:4: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.Token;
^
datoLexer.java:5: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.TokenStream;
^
datoLexer.java:8: error: package org.antlr.v4.runtime.dfa does not exist
import org.antlr.v4.runtime.dfa.DFA;
^
datoLexer.java:12: error: cannot find symbol
public class datoLexer extends Lexer {
^
symbol: class Lexer
datoLexer.java:15: error: cannot find symbol
protected static final DFA[] _decisionToDFA;
^
symbol: class DFA
location: class datoLexer
datoLexer.java:16: error: cannot find symbol
protected static final PredictionContextCache _sharedContextCache =
^
symbol: class PredictionContextCache
location: class datoLexer
datoLexer.java:50: error: cannot find symbol
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
^
symbol: class Vocabulary
location: class datoLexer
datoLexer.java:79: error: cannot find symbol
public Vocabulary getVocabulary() {
^
symbol: class Vocabulary
location: class datoLexer
datoLexer.java:84: error: cannot find symbol
public datoLexer(CharStream input) {
^
symbol: class CharStream
location: class datoLexer
datoLexer.java:105: error: cannot find symbol
public ATN getATN() { return _ATN; }
^
symbol: class ATN
location: class datoLexer
datoLexer.java:136: error: cannot find symbol
public static final ATN _ATN =
^
symbol: class ATN
location: class datoLexer
datoLexer.java:6: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.*;
^
datoLexer.java:7: error: package org.antlr.v4.runtime.atn does not exist
import org.antlr.v4.runtime.atn.*;
^
datoLexer.java:9: error: package org.antlr.v4.runtime.misc does not exist
import org.antlr.v4.runtime.misc.*;
^
datoBaseListener.java:31: error: method does not override or implement a method from a supertype
@Override public void enterEveryRule(ParserRuleContext ctx) { }
^
datoBaseListener.java:37: error: method does not override or implement a method from a supertype
@Override public void exitEveryRule(ParserRuleContext ctx) { }
^
datoBaseListener.java:43: error: method does not override or implement a method from a supertype
@Override public void visitTerminal(TerminalNode node) { }
^
datoBaseListener.java:49: error: method does not override or implement a method from a supertype
@Override public void visitErrorNode(ErrorNode node) { }
^
datoParser.java:13: error: cannot find symbol
static { RuntimeMetaData.checkVersion("4.7.2", RuntimeMetaData.VERSION); }
^
symbol: variable RuntimeMetaData
location: class datoParser
datoParser.java:13: error: cannot find symbol
static { RuntimeMetaData.checkVersion("4.7.2", RuntimeMetaData.VERSION); }
^
symbol: variable RuntimeMetaData
location: class datoParser
datoParser.java:17: error: cannot find symbol
new PredictionContextCache();
^
symbol: class PredictionContextCache
location: class datoParser
datoParser.java:43: error: cannot find symbol
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
^
symbol: class VocabularyImpl
location: class datoParser
datoParser.java:64: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:70: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:76: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:79: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:82: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:85: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:90: error: cannot find symbol
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
^
symbol: variable _interp
location: class datoParser
datoParser.java:90: error: cannot find symbol
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
^
symbol: class ParserATNSimulator
location: class datoParser
datoParser.java:94: error: cannot find symbol
public TerminalNode EOF() { return getToken(datoParser.EOF, 0); }
^
symbol: variable EOF
location: class datoParser
datoParser.java:95: error: cannot find symbol
public TerminalNode MYTOKEN() { return getToken(datoParser.MYTOKEN, 0); }
^
symbol: method getToken(int,int)
location: class StartContext
datoParser.java:99: error: method does not override or implement a method from a supertype
@Override public int getRuleIndex() { return RULE_start; }
^
datoParser.java:100: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:104: error: method does not override or implement a method from a supertype
@Override
^
datoParser.java:111: error: cannot find symbol
StartContext _localctx = new StartContext(_ctx, getState());
^
symbol: variable _ctx
location: class datoParser
datoParser.java:111: error: cannot find symbol
StartContext _localctx = new StartContext(_ctx, getState());
^
symbol: method getState()
location: class datoParser
datoParser.java:112: error: cannot find symbol
enterRule(_localctx, 0, RULE_start);
^
symbol: method enterRule(StartContext,int,int)
location: class datoParser
datoParser.java:114: error: cannot find symbol
enterOuterAlt(_localctx, 1);
^
symbol: method enterOuterAlt(StartContext,int)
location: class datoParser
datoParser.java:116: error: cannot find symbol
setState(2);
^
symbol: method setState(int)
location: class datoParser
datoParser.java:117: error: cannot find symbol
((StartContext)_localctx).d = match(MYTOKEN);
^
symbol: method match(int)
location: class datoParser
datoParser.java:118: error: cannot find symbol
setState(3);
^
symbol: method setState(int)
location: class datoParser
datoParser.java:119: error: cannot find symbol
match(EOF);
^
symbol: variable EOF
location: class datoParser
datoParser.java:122: error: cannot find symbol
catch (RecognitionException re) {
^
symbol: class RecognitionException
location: class datoParser
datoParser.java:123: error: cannot find symbol
_localctx.exception = re;
^
symbol: variable exception
location: variable _localctx of type StartContext
datoParser.java:124: error: cannot find symbol
_errHandler.reportError(this, re);
^
symbol: variable _errHandler
location: class datoParser
datoParser.java:125: error: cannot find symbol
_errHandler.recover(this, re);
^
symbol: variable _errHandler
location: class datoParser
datoParser.java:128: error: cannot find symbol
exitRule();
^
symbol: method exitRule()
location: class datoParser
datoParser.java:138: error: cannot find symbol
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
^
symbol: class ATNDeserializer
location: class datoParser
datoParser.java:140: error: cannot find symbol
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
^
symbol: class DFA
location: class datoParser
datoParser.java:142: error: cannot find symbol
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
^
symbol: class DFA
location: class datoParser
datoLexer.java:13: error: cannot find symbol
static { RuntimeMetaData.checkVersion("4.7.2", RuntimeMetaData.VERSION); }
^
symbol: variable RuntimeMetaData
location: class datoLexer
datoLexer.java:13: error: cannot find symbol
static { RuntimeMetaData.checkVersion("4.7.2", RuntimeMetaData.VERSION); }
^
symbol: variable RuntimeMetaData
location: class datoLexer
datoLexer.java:17: error: cannot find symbol
new PredictionContextCache();
^
symbol: class PredictionContextCache
location: class datoLexer
datoLexer.java:50: error: cannot find symbol
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
^
symbol: class VocabularyImpl
location: class datoLexer
datoLexer.java:71: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:77: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:86: error: cannot find symbol
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
^
symbol: variable _interp
location: class datoLexer
datoLexer.java:86: error: cannot find symbol
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
^
symbol: class LexerATNSimulator
location: class datoLexer
datoLexer.java:89: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:92: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:95: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:98: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:101: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:104: error: method does not override or implement a method from a supertype
@Override
^
datoLexer.java:137: error: cannot find symbol
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
^
symbol: class ATNDeserializer
location: class datoLexer
datoLexer.java:139: error: cannot find symbol
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
^
symbol: class DFA
location: class datoLexer
datoLexer.java:141: error: cannot find symbol
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
^
symbol: class DFA
location: class datoLexer
100 errors
:/mnt/c/Users/myUser/dato$ sudo apt install antlr4
[sudo] password for ACCOUNT:
Reading package lists... Done
Building dependency tree
Reading state information... Done
antlr4 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
:/mnt/c/Users/myUser/dato$
为什么会出现这些错误?我使用了错误的命令吗?
最佳答案
Java编译器找不到ANTLR运行时类(这是error: package org.antlr.v4.runtime does not exist
错误的含义)。换句话说,antlr-4.8-complete.jar
are not properly added to your CLASSPATH中的类。
忘记这些命令的任何别名:了解如何自己编译Java类。
首先,确保文件antlr-4.8-complete.jar
和dato.g4
位于同一文件夹中,然后在该文件夹中打开终端和CD。
1生成解析器
java -cp antlr-4.8-complete.jar org.antlr.v4.Tool dato.g4
2个编译Java文件视窗
javac -cp .;antlr-4.8-complete.jar *.java
*尼克斯javac -cp .:antlr-4.8-complete.jar *.java
关于compiler-errors - 通过Ubuntu终端进行编译(在Windows 10上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63799030/