如何使用 Eclipse 构建 Antlr4 C# 语法?

How to build Antlr4 C# grammar using Eclipse?

我正在尝试构建以下存储库中可用的 Antlr V4 语法:https://github.com/antlr/grammars-v4。我已成功构建 Python3 和 Java 语法,并已成功生成目标 *.java 文件。但是,当我尝试构建 C# 语法时,例如CSharpLexer.g4、CSharpParser.g4 和 CsharpPreporcessorParser.g4 我遇到构建错误。它会产生以下错误:

error(114): CSharpPreprocessorParser.g4:7:21: cannot find tokens file ./CSharpLexer.tokens
error(126): CSharpParser.g4:20:62: cannot create implicit token for string literal in non-combined grammar: '.'
error(126): CSharpParser.g4:25:14: cannot create implicit token for string literal in non-combined grammar: '?'
error(126): CSharpParser.g4:25:37: cannot create implicit token for string literal in non-combined grammar: '*'
error(126): CSharpParser.g4:31:8: cannot create implicit token for string literal in non-combined grammar: '*'
error(126): CSharpParser.g4:71:3: cannot create implicit token for string literal in non-combined grammar: '<'
error(126): CSharpParser.g4:71:14: cannot create implicit token for string literal in non-combined grammar: ','
error(126): CSharpParser.g4:71:25: cannot create implicit token for string literal in non-combined grammar: '>'
error(126): CSharpParser.g4:76:14: cannot create implicit token for string literal in non-combined grammar: ','
error(126): CSharpParser.g4:80:15: cannot create implicit token for string literal in non-combined grammar: ':'
error(126): CSharpParser.g4:99:3: cannot create implicit token for string literal in non-combined grammar: '='
error(126): CSharpParser.g4:99:9: cannot create implicit token for string literal in non-combined grammar: '+='
error(126): CSharpParser.g4:99:16: cannot create implicit token for string literal in non-combined grammar: '-='
error(126): CSharpParser.g4:99:23: cannot create implicit token for string literal in non-combined grammar: '*='
error(126): CSharpParser.g4:99:30: cannot create implicit token for string literal in non-combined grammar: '/='

我正在尝试使用 Antlr V4 eclipse 插件构建它。我的目标是生成 *.java 文件以继续下一步。不确定如何构建所有的 csharp *.g4 文件,因为 Java 和 Python 分别只有一个语法文件。

首先构建CSharpLexer.g4。然后构建 CSharpParser.g4 和 CsharpPreporcessorParser.g4。构建 CSharpLexer.g4 将生成 CSharpLexer.tokens,供 CSharpParser.g4 的后期使用。