Questions tagged [pycparser]

pycparser is a parser for the C language, written in pure Python. It is a module designed to be easily integrated into applications that need to parse C source code

When you provide a code (file) to Pycparser to be parsed, it creates an Abstract Syntax Tree (AST) out of it. Abstract Syntax Tree (AST) is a tree representation of the syntax of source code - a convenient hierarchical data structure that's built from the code and is readily suitable for exploration and manipulation.

For FAQs about pycparser, please visit: https://github.com/eliben/pycparser/wiki/FAQ

78 questions
0
votes
1 answer

Find Division Operator Instances in C file

I am trying to find all division operators in a large c file. I saw this example for a Python Code. And I tried to use it for my c file. So, I parsed my c file into ast using pycparser as follows: from pycparser import parse_file, c_parser,…
Nemo
  • 85
  • 2
  • 11
0
votes
1 answer

how to find switch statement from an ast generated from pycparser?

I am trying to parse c files using pycparser and find the switch statement I have generated the ast using https://github.com/eliben/pycparser/blob/master/examples/explore_ast.py this link. then using n = len(ast.ext) i have found the length of the…
0
votes
0 answers

Unknown uint8_t type in pycparser

I am trying to parse a C function declaration. As it has uint8_t, uint16_t in it, pycparser is unable to recognize this type. typedef enum tagReturnCode {SUCCESS, FAIL} ReturnCode; typedef struct tagEntry { char* key; char* value; }…
cckumar
  • 1
  • 1
0
votes
0 answers

pycparser: parse back c file

i'm trying to learn how to use pycparser and during my practice I encontured this problem. Basically I have a C file with system header like #include and #include and I want to analyze it through the pycparser ast tree. I…
0
votes
2 answers

Can't run pycparser: Needs ply.yacc?

I downloaded pycparser and ran python setup.py install, but whenever I try to run anything, I get: ... from .c_parser import CParser File "C:\Program Files\Python 3.2\lib\site-packages\pycparser\c_parser.py", line 11, in import…
user541686
  • 205,094
  • 128
  • 528
  • 886
0
votes
1 answer

Edit C function declaration with pycparser

I need to write a Python program that parses C source code files and adds a hidden parameter at the end of each function declaration. More precisely, I need to change something like this: void f(int a, int b, int c) { ... } into something like…
Zehanort
  • 458
  • 2
  • 10
0
votes
2 answers

Getting all the functions called in the specified function

I am using pycparser to parse a C code. My goal is that given a C code and a function name, list out all the functions called in the specified function. I looked at the documentation for the pycparser but I couldn't find anything to solve…
sonic_maniac
  • 59
  • 10
0
votes
1 answer

How cbmc works with c header?

If I have a c file that contains more than one function, and I want to run the cbmc with z3 solver on the preprocessed version of the program (using gcc) and there are some other files(c files) in the header section. How will the cbmc see those…
eng2019
  • 53
  • 6
0
votes
1 answer

pycparser retrieving function call hierarchy

is there a way to get the function call stack with pycparser ? for example if i have code like this: static int Func_1(int *val) { unsigned int data_1 = 0; int result; result = Func_2(val, data_1 …
friggler
  • 177
  • 2
  • 14
0
votes
1 answer

How do I print out the constant names when printing all the constants in a C file using pycparser?

I'm working on automating a tool that prints out all constants in a C file. So far, I have managed to print out all the constants in a C file but I can't figure out of a way to show the variable names they are associated with without printing out…
0
votes
1 answer

How do I reverse the byte order of a list of constants in Python?

I have been looking for a way to extract constants from C source files and reverse their byte order in one automated process (no manual input). So far, I've managed to utilize pycparser to do most of the heavy lifting for me and created a script…
GoMonkey
  • 321
  • 1
  • 2
  • 7
0
votes
1 answer

Parse postgresql -pycparser.plyparser.ParseError before: pgwin32_signal_event

I need to parse an open-source project Postgresql using pycparser. While parsing its source-code the following error arises: Traceback (most recent call last): File "examples\using_cpp_libc.py", line 48, in getAllFiles(projectName) File…
0
votes
1 answer

Compilation of Postgresql using pycparser- header files not found

I have installed pycparser that parses C code. Using pycparser I want to parse an open source project, namely PostgreSQL(version-11.0). I have build it using Visual Studio Express 2017 compiler suite. However, during compilation it cannot find some…
0
votes
1 answer

pycparser parse error on multi-byte character

I'm using pycparser to parse some C code. Specifically code that can contain Japanese character inside characters and string such as below: int main() { char ch = '本'; } I have tried to compile this on Dev-c, and compiles properly. Is this…
Thor
  • 13
  • 2
0
votes
1 answer

pycparser ParseError

I am trying to creat AST usinfg pyCparser, The following error printed: Traceback (most recent call last): File "C:\Work\RE\Tools\VarsExporter\BuildExportedDb.py", line 1076, in main() File "C:\Work\RE\Tools\VarsExporter\BuildExportedDb.py", line…
David
  • 733
  • 2
  • 11
  • 30