英文:
How to fix '"Character/_input does not exist in the current context" in Antlr with C# as target language?
问题
我已成功使用Antlr4生成了解析器和词法分析器,目标语言是C#。
所使用的语法文件是Java 9。语法文件的链接在这里 Java9.g4。
在生成的.cs文件中,当尝试在dotnet core项目中编译时,Java9Lexer.cs 抛出了以下错误:
error CS0103: 当前上下文中不存在名称 'Character'
error CS0103: 当前上下文中不存在名称 '_input'
请帮助我以正确的方式修复这个错误!:) 感谢您的帮助。
英文:
I have successfully generated parser and lexer using Antlr4 with target language c#.
Used Grammar file is for Java 9. Link to the grammar file is here Java9.g4
In the generated .cs files, Java9Lexer.cs is throwing the below errors when tried to compile in dotnet core project.
error CS0103: The name 'Character' does not exist in the current context
error CS0103: The name '_input' does not exist in the current context
Please help me fix this error the right way! Thanks for helping me out.
答案1
得分: 1
在.g4
文件中,位于{
和}?
之间的所有内容都是特定于目标的代码。在您的情况下,这是Java代码。由于您的目标是C#,您需要将该Java代码替换为相应的C#代码。
英文:
Everything inside {
and }?
in .g4
files is target specific code. In your case, it's Java code. Since you're targeting C#, you need to replace that Java code with the C# equivalent.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论