0
votes

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.

1

1 Answers

1
votes

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