-
Hi, I was using ANTLR (Cpp target) to tokenize and parse typescript scripts. I found that the parser can report "seg fault" when parsing certain syntax, for example, My question is, is this bug expected? i.e. is typescript syntax not fully supported by ANTLR Cpp target? I looked into the source code further and I found the error is caused by I am new to ANTLR and still making sense of how it works. Any general suggestions/resources are also welcomed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There's actually a couple of problems. First, the port of the typescript grammar for Cpp has several errors due to faulty translation from one of the other ports to C++.
If you don't believe me on these errors, output the token types to verify all tests are working across all targets. BTW, this seems to be the same problem I described with another grammar which was forked from this grammar or the other way around. antlr/grammars-v4#2909 (comment) Any time you see problems with a port, you should first suspect the port is in error, not the Antlr code--although that can happen! And, in this case, yes, there is a problem there too. (Fix the port errors first, then run.) The program will crash in prediction context comparisons, which I fixed a few months ago. antlr/grammars-v4#2909 (comment)
This won't be in 4.11.1. You'll have to get a copy of the latest "dev" branch of the Cpp runtime. I just tested with the new code, and it parses fine. |
Beta Was this translation helpful? Give feedback.
There's actually a couple of problems.
First, the port of the typescript grammar for Cpp has several errors due to faulty translation from one of the other ports to C++.
lastToken = false;
. Call me old school (almost >40 years with C, working with C++ since it was invented), but I don't trust the C++ runtime to initialize this correctly (and I don't want to wade through to 1000-page Language Spec to see if it's supposed to init bools to false).lastToken
at https://github.com/antlr/grammars-v4/blob/0042cb5f6f0…