'''让我完全惊讶

ain*_*ins 5 c# antlr4

我在为C#设置ANTLR v4时遇到了麻烦,有谁热衷于帮助我?我正在使用官方网站提到的构建目标https://github.com/sharwell/antlr4cs

我添加了一个简单的语法 Foo.g

grammar Foo;
r  : 'hello' ID ;         // match keyword hello followed by an identifier
ID : [a-z]+ ;             // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
Run Code Online (Sandbox Code Playgroud)

...并为其设置构建操作 Antlr4

现在我遇到了以下错误.

'´' came as a complete surprise to me
mismatched input 'grammar' expecting SEMI
Run Code Online (Sandbox Code Playgroud)

小智 11

我还没有足够的观点来发表评论,所以这只是一个链接,但显然这个错误消息的一个可能原因是使用BOM以UTF-8编码保存文档.显然这是JAVA文件输入流的问题.

Notepad ++将让您在没有BOM的情况下进行保存.

资料来源:https://github.com/sharwell/antlr4cs/issues/12

  • 如果您使用File&rarr,Visual Studio也会让您使用; 高级保存选项... (2认同)