-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does antlr have a length limit for parsing c/cpp code? #3599
Comments
Please provide a few more details.
|
What version of Antlr are you using? OK, you are using the "Java" target. For the c grammar, using Antlr 4.13.0, the CSharp (dotnet 7.0.305) target, on Ubuntu 20.04.6, on an AMD Ryzen 7 2700 Eight-Core Processor, 16GB DDR4, code.txt and cfile.txt both take each about 0.13 s. cfile.txt is 377 lines long, code.txt 50 lines ( I tried it on a 1k line file from the GCC testsuite (Wmisleading-indentation.c). Took about the same amount of time. NB: pre-processor directives should be ignored, but it looks like the c grammar parses only two types of directives. That's wrong. #3601 |
Updated the grammar for parsing preprocessor directives. #3602 For the Java target, using "grouped parsing" (aka "warm up parsing"), these are the runtimes for each of the test files.
|
OK. "code.txt" is your driver code for the Java target. "cfile.txt" is NOT a C-language file. It's a C++ source file. For example, it contains a class declaration "class ImageServer". Classes do not exist in the C language. So, you are using the wrong grammar. This cannot be parsed by c grammar. It's cpp grammar. Starting over........ |
This input is C++ source code, and code that is before preprocessing. It cannot be parsed cleanly with the cpp grammar because the macro call However, with the cpp grammar, the input is parsed with error, rather slowly.
|
I'm using antlr 4.9 in maven, which means that if my .c file exceeds 500 lines it can't be parsed? I downloaded the c.g4 from the official antlr repository or do I need to preprocess the data myself? Is there a .g4 file that can parse both cpp and c? |
Does antlr have a length limit for parsing c/cpp code? I'm using antlr to parse a 2000 line c code file, but the parser can only parse up to 500 lines, when I delete the first 500 lines it parses a few hundred lines. How to solve the length limitation?
The text was updated successfully, but these errors were encountered: