Antlr 4.13.2 generating incorrect c# code #4701
-
Antlr 4.13.2 appears to generate incorrect c# code for both my own grammar and the sample Lucne grammar. For instance, the following appears in the generated parser: _localctx.left = TokenStream.LT(1); When it should be something like: _localctx.left = _input.Lt(1); I'm having a ittle trouble believing that this error is occurring (but it is), and wonder if I have some kind of configuration or download error. Directory of F:\Antlr4 09/19/2024 11:43 AM .09/19/2024 11:43 AM .. 09/16/2024 11:35 AM 2,140,045 antlr-4.13.2-complete.jar 09/16/2024 10:41 PM 106,374 antlr4-parse.exe 09/16/2024 10:41 PM 106,370 antlr4.exe 09/19/2024 11:44 AM Documentation 09/19/2024 11:39 AM Examples 09/16/2024 04:15 PM Tools 3 File(s) 2,352,789 bytes 5 Dir(s) 625,795,338,240 bytes free Can someone offer help with this unexpected problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We need a minimal reproducible example. I.e., the .g4 grammar, driver, and most importantly the .csproj. But, I suspect that you are using the wrong "Antlr4"!
antlr4/runtime/CSharp/src/ITokenStream.cs Line 34 in 2a7904a It sounds like you are using the old Antlr4cs fork and all its associated packages: Antlr4, Antlr4.Runtime, Antlr4.CodeGenerator. These packages are ancient, and completely incompatible with "official Antlr4". Instead, use Antlr4.Runtime.Standard and my build package Antlr4BuildTasks. You don't need to download Java or the Antlr .jar. See AntlrHW for a complete, simple example. Just Also, very important: there is NO Antlr4.Runtime.Standard version 4.13.2 for C#. It was never released. You must use version 4.13.1. In addition, the Antlr4BuildTasks takes great measures to make sure there is no version skew between tool and runtime. It will generate code using 4.13.1 of the tool. |
Beta Was this translation helpful? Give feedback.
We need a minimal reproducible example. I.e., the .g4 grammar, driver, and most importantly the .csproj. But, I suspect that you are using the wrong "Antlr4"!
TokenStream.LT(1)
is correct. Parser.TokenStream is the property that accesses the private backing field _input. It is LT(int):antlr4/runtime/CSharp/src/ITokenStream.cs
Line 34 in 2a7904a
It sounds like you are using the old Antlr4cs fork and all its associated packages: Antlr4, Antlr4.Runtime, Antlr4.CodeGenerator. These packages are ancient, and completely incompatible with "official Antlr4".
Instead, use Antlr4.Runtime.Standard and my build package A…