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
2
votes
0 answers

Get members of a enum/struct with pycparser

I have a simple C program in test.c, and I want to get the members of sample_enum and sample_struct using python with the help of pycparser. #include typedef enum sample_enum { board1 = 0, board2 = 1, board3 = 2, board4 =…
ManiAm
  • 1,759
  • 5
  • 24
  • 43
2
votes
1 answer

How to remove AST nodes with pycparser?

Let's start by considering this snippet: import sys from pycparser import c_parser, c_ast, c_generator text = r""" void main() { foo(1,3); foo1(4); x = 1; foo2(4, 10, 3); foo3( "xxx" …
BPL
  • 9,632
  • 9
  • 59
  • 117
2
votes
0 answers

Win206 error in python

Traceback (most recent call last): File "C:\Python34\vp\pycparser\__init__.py", line 44, in preprocess_file universal_newlines=True) File "C:\Python34\lib\subprocess.py", line 859, in __init__ restore_signals, start_new_session) File…
2
votes
1 answer

pycparser error by using preprocessor output

I use pycparser to parse c code and for my test files it works fine. I had some problems with the cpp and the header files so I use a external cpp and give the pycparser the output of the preprocessor. With my test files it all works but with files…
harald
  • 21
  • 4
2
votes
2 answers

pycparser - Getting source line number from AST

I'm looking into parsing a C-file with pycparser and I'm trying to get the source line number from the AST generated by pycparser. Is this possible?
daveh
  • 21
  • 1
1
vote
1 answer

How to convert pycparser ast to python anytree format?

I am trying to convert the ast from pycparser to python anytree for further processing tasks. But the anytree tree I am currently getting does not contain several useful information and I also cannot figure it out how to do that. Currently my code…
batman
  • 60
  • 6
1
vote
1 answer

pycparser AST node pointers/locations

I am new in parsing and I am trying to use Pycparser to parse my c file and I follow the instruction by preprocessing the file gcc -E then I used using_gcc_E_libc.py from the example folder and I pass my file and I got some output but am not sure if…
eng2019
  • 53
  • 6
1
vote
1 answer

PostgreSQL doesn't contain some required header files

I have installed pycparser that parses C code. Using pycparser I want to parse an open source project, namely PostgreSQL . However, during compilation it cannot found some header files, namely pg_config_ext.h and pg_config_os.h. While looking at…
1
vote
1 answer

pycparser visit else only of an if-else statement

I'm using pycparser to parse some C code. Specifically, I need certain portions of the code, included in pycparser are some visitors like visit_If to visit "If" sections of the code. However, I'm having problem visiting 'else' part of an if-else…
Thor
  • 13
  • 2
1
vote
1 answer

Clang + pycparser fail to parse pythread.h header from CPython 3.7

Clang + pycparser fail to parse pythread.h header from CPython 3.7, but this was working in CPython 3.7-dev in Travis CI. opt/python/3.7.0/include/python3.7m/pythread.h:122:5: error: "Require native threads. See…
denfromufa
  • 5,610
  • 13
  • 81
  • 138
1
vote
0 answers

Unbable to import function

I have tried following when I tried to import the class from the file named plyparser.py of pycparser(https://github.com/eliben/pycparser/blob/master/pycparser/plyparser.py) using the following statement from pycparser.plyparser import…
Tom
  • 904
  • 1
  • 7
  • 21
1
vote
1 answer

How to store AST Children information(python)

I am relatively new to python and pycparser. I have already parsed the c file into an AST using the c-to-c.py file from https://github.com/eliben/pycparser. I am now trying to make a CFG using the AST but I am unable to store the information in…
1
vote
0 answers

Permission denied error in pip installing pyopenssl

As I'm trying to force reinstall pyopenssl, I'm running into the following error when it tries to install pycparser. I am doing this on Windows 7 64-bit with Python 2.7 using the following command: pip install pyopenssl --ignore-installed Here is…
auslander
  • 507
  • 2
  • 5
  • 14
1
vote
2 answers

Finding pointer arguments with GnuCParser?

I'm trying to parse this fragment of C code: void foo(const int *bar, int * const baz); using GnuCParser, part of pycparserext. Based on this answer I expected to see some PtrDecls, but here's what I get from ast.show() on the resulting parse…
unwind
  • 391,730
  • 64
  • 469
  • 606
1
vote
1 answer

Finding the input dependencies of a functions outputs

I've been working on a python program with pycparser which is supposed to generate a JSON-file with dependencies of a given function and its outputs. For an example function: int Test(int testInput) { int b = testInput; return b; } Here I…