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
1
vote
1 answer

Parsing variable dependency with Pycparser

I'm currently working on a project to find variable dependencies in a given function for I/O, and have chosen to work with Pycparser. My code right now is mostly just one visitor-class, and a few node-classes. What it does is it traverses the AST…
Zpooks
  • 90
  • 8
1
vote
2 answers

pycparser: how to get end of function in C file

I am using pycparser to parse C file. I wish to get start and end of each function definition in C file. But what I actually get is only start of function definitions. memmgr_init at examples/c_files/memmgr.c:46 get_mem_from_pool at…
1
vote
2 answers

Pycparser not getting imported

2.7.11 python pckg for Mac - and installed the same. Now I am trying to execute a python file python file1.py It throws up the error : File "file1.py", line 107, in from pycparser import parse_file, c_parser, c_ast ImportError: No module…
user3304726
  • 219
  • 2
  • 4
  • 17
1
vote
1 answer

Cannot install cryptography 0.9.3 on OSX 10.8

I'm new to python and django. I'm struggling to install our company's development package locally since the latest release of django. Here's the message stack: Installing django. django: There's no directory named after our project. Probably you…
1
vote
1 answer

Including Fake-headers via pycparser in Windows?

We can support new typedefs , #includes and #defines , by preprocessing it with the help of pycparser parse_file . I also went through the documentation: README page and the blog post , but all the documentation was written for linux systems.I have…
1
vote
1 answer

extern followed by string literal

I am trying to parse the syntax of a C file using pycparser. I send the C file through a preprocessor and then send the output of the preprocessor to be parsed by pycparser. The following code is in one of the C files ... extern "asm" { extern…
Stefan Bossbaly
  • 6,682
  • 9
  • 53
  • 82
1
vote
2 answers

Extracting input parameters and its Identifier type While parsing a c file using PycParser

Note: Ones who are familiar with pycparser would understand the problem much better. I am using pycparser v2.10 and I am trying to extract all the functions that have been defined in the C file as well extract its input parameter name and…
1
vote
1 answer

Is there a way to add a keyword to pycparser?

Does anybody know if there is a way to add a new keyword to pycparser? I need to parse C code for the compiler which is based on C99 but is slightly different. There are a few keywords that are not part of C99. Any help is appreciated
flashburn
  • 4,180
  • 7
  • 54
  • 109
1
vote
1 answer

Add line of code surrounding certain function calls

I don't know if it is possible, but I'd like to put some line of code around function calls from a certaint .c file. Say I have a file1.c in which I do something like: #include "file2.h" ... void fun(){
Phate
  • 6,066
  • 15
  • 73
  • 138
1
vote
1 answer

Ignore includes with #pycparser and define multiple Subgraphs in #pydot

I am new to stackoverflow, but I got a lot of help until now, thanks to the community for that. I'm trying to create a software showing me caller depandencys for legacycode. I'parsing a directory with c code with pycparcer, and for each file i want…
Adrian
  • 21
  • 5
0
votes
1 answer

how do i create a usable .py file after using pycparser

I am able to successfully parse a c file containing a function i want to use in python. now i cannot figure how to either a) call said function or b) create a .py file with said function. All i have is this mysterious "ast" object
0
votes
1 answer

Parse macro-defined values using pycparser

I'm currently trying to parse a C header file AND retain the name of some macro-defined values. As Tim notes in the comments below the preprocessor does its job and ultimately derives that raw value that will be used in the code. However, I was…
afterShock
  • 33
  • 1
  • 7
0
votes
0 answers

pycparser ParseError on barrier.h

I am trying to creat AST for a kernel file using pyCparser and met ParseError. I preprocessed the file using command like, and no error generated. clang -E -D'__attribute__(x)=' -D'__extension__=' -D'__signed__=signed' -D'__builtin_va_list=int'…
Amy
  • 1
0
votes
1 answer

Preprocessor linemarkers in pycparser

I am working on a project using pycparser for parsing C source code. Accordingly with https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html when I run preprocessor I have # linenum filename flags linemarkers in my preprocessed translation…
0
votes
0 answers

I need to find the function argument has a return type or not using Pycparser.How will I do that?

My code is:- class FuncDefVisitor(c_ast.NodeVisitor): def visit_FuncDef(self, node): node.body.show() node.decl.type.args.show() print('%s at %s' % (node.decl.name, node.decl.coord)) I am unable to understand how to find if…