How to fix '"Character/_input does not exist in the current context" in Antlr with C# as target language?

huangapple go评论91阅读模式
英文:

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

How to fix '"Character/_input does not exist in the current context" in Antlr with C# as target language?

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! How to fix '"Character/_input does not exist in the current context" in Antlr with C# as target language? 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.

huangapple
  • 本文由 发表于 2020年7月22日 16:20:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63029869.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定