7

I'm having trouble setting up ANTLR v4 for C#, anyone keen to help me? I'm using the build target referred from the official site here https://github.com/sharwell/antlr4cs

I added a simple grammar 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

...and set the build action for it to Antlr4

Now I'm stuck with the following errors.

'´' came as a complete surprise to me
mismatched input 'grammar' expecting SEMI
ains
  • 1,436
  • 4
  • 18
  • 33

2 Answers2

13

I don't have enough points to make a comment yet, so this is just a link, but apparently one possible cause of this error message is saving the document in UTF-8 encoding with a BOM. Apparently this is an issue with the JAVA file input stream.

Notepad++ will let you save without the BOM.

Source: https://github.com/sharwell/antlr4cs/issues/12

Richard Vasquez
  • 187
  • 1
  • 5
  • 2
    Visual Studio will let you as well, if you use File → Advanced Save Options... – Sam Harwell Aug 26 '13 at 22:11
  • Thanks! Now, nothing seems to be generated :( Is antlr v4 even supported on C#? – ains Aug 27 '13 at 00:52
  • This was causing me grief -- I tried saving in 'US-ASCII' format in Visual Studio and it worked. – Steve Cooper May 09 '14 at 18:33
  • If, like me, you do not have the Advanced Save Options in the File menu do the following. Right-click the File menu and choose Customize. Switch to the Commands tab and in the top drop down, choose File. Then press Add Command button. Finally choose File - Advanced Save Options - OK. You can optionally move it to where you want it in the menu. – Rossco Feb 25 '15 at 20:34
0

I had similar issue for java target.I saved the grammar file with ANSI encoding in notepad and it started working

ramnar
  • 146
  • 1
  • 8