0

I'm trying to create my first antlr4 grammar for C# and I'm getting the following exception:

System.NotSupportedException: Could not deserialize ATN with UUID aadb8d7e-aeef-4415-ad2b-8204d6cf042e (expected ab35191a-1603-487e-b75a-479b831eaf6d or a legacy UUID). at Antlr4.Runtime.Atn.ATNDeserializer.Deserialize(Char[] data)

My grammar is fairly simple just recognizing numbers and identifiers from the expression string. I have only lexer grammar because I want to get tokens (number and words) from text, without some AST. It fails immediately on init:

lexer = new MyLexer(new AntlrInputStream("3"));

// fails in this line in constructor: Interpreter = new LexerATNSimulator(this,_ATN);

I'm not using Antlr language support for VS because I'm using dotnet core where I have .xproj instead of .csproj so I'm not sure is it supported. However, I think that this doesn't make a difference since I'm using command line:

java -jar antlr-4.5.3-complete.jar -Dlanguage=CSharp MyLexer.g4

I have added 4.5.3 nuget package and I can see in project.json that the version is the same as version of jar:

"dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Antlr4": "4.5.3"  
}
...
}

I have also tried with pre-release but I'm getting the same error.

I have found the similar issue in java version: Initialising my Lexer throws an error in Antlr4 However, it cannot help in my C# case because there was a problem with mismatched versions of ANTLR and here I'm using 4.5.3 to generate both .cs file and in the runtime.

Community
  • 1
  • 1
Jovan MSFT
  • 13,232
  • 4
  • 40
  • 55

1 Answers1

1

The C# target distributed with the ANTLR release from antlr.org is a fork of my original C# target, and it does not produce C# code compatible with the official C# target I distribute through NuGet. You will need to use the code generator distributed through NuGet (in the Antlr4 package for 4.5.3, but moved to Antlr4.CodeGenerator for 4.5.4) before it will work at runtime.

Also, keep in mind that stack overflow is not a support channel for the C# target which I monitor closely. In most cases you will want to create an issue on GitHub if you have a question, bug report, or enhancement request: https://github.com/tunnelvisionlabs/antlr4cs

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
  • Thanks for clarifying. I have seen yours target, but I was confused what is the official/recommended version. Do you have some example of command line that generates parser in C# (all examples imply that I need to setup MSBUILD in VS). Currently I'm not sure is dotnet core, VS 2015 U3, and xproj files fully supported, so it would help to have single command line that generates C# file. – Jovan MSFT Dec 14 '16 at 11:37
  • @JovanMSFT I would recommend using my release, which is highly optimized and has much tighter restrictions regarding cross-version compatibility than the "standard" release. To work out a build strategy for xproj files, it would be best to open an issue on GitHub at the link given earlier. – Sam Harwell Dec 19 '16 at 17:00