ANTLR4 在某台机器上找不到任何令牌,但在具有相同输入文件的计算机上工作正常



我的程序使用ANTLR(v4.8.0(C++目标进行解析。现在有一台机器,我无法访问它进行故障跟踪,在它上

line 1:0 mismatched input '<EOF>'

报告了一个输入文件,该文件在我的机器上运行良好。错误消息让我相信ANTLR没有找到一个令牌,就像它被传递了一个空流。输入文件使用UTF8-BOM进行编码。

我的机器和不工作的机器都运行Windows 10。

加载输入流的代码是

antlr4::ANTLRInputStream antlrIs(inputAsUtf8);
A2lLexer lexer(&antlrIs);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
antlr4::CommonTokenStream tokens(&lexer);
// The strategy from https://groups.google.com/g/antlr-discussion/c/q-8MPVI9lrw has been tested 
// and found to yield the same performance as this basic one.
XParser parser(&tokens);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
XParser::XFileContext* xFileContext = parser.xFile();
if (lexer.getNumberOfSyntaxErrors() || parser.getNumberOfSyntaxErrors())
{
throw runtime_error((string("Syntax error in ") + inputFile + ".").c_str());
}

当打印到控制台时,inputAsUtf8的内容看起来很好。

有什么关于如何错误地追踪这个毛皮的想法吗?我有点困了。

由于某些原因,ifstream源有时是空的。因此,这与ANTLR无关,但实际上与ifstream有关。

相关内容

最新更新