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
9
votes
1 answer

How to get only function blocks using sly

I need to get the function blocks (definition and everything, not just declaration), in order to get a function dependency graph. From the function dependency graph, identify connected components and modularize my insanely huge C codebase, one file…
LazyCoder
  • 1,267
  • 5
  • 17
9
votes
3 answers

How can I parse a C format string in Python?

I have this code in my C file: printf("Worker name is %s and id is %d", worker.name, worker.id); I want, with Python, to be able to parse the format string and locate the "%s" and "%d". So I want to have a function: >>> my_function("Worker name is…
speller
  • 1,641
  • 2
  • 20
  • 27
8
votes
3 answers

python pycparser setup error

I am seeing the following error while setting up pyparser on CentOS 7 via pip /usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-PMzCYU/pycparser/setup.py';exec(compile(getattr(tokenize, 'open',…
user1580835
  • 101
  • 1
  • 2
6
votes
0 answers

Converting "c-like language" to "custom language" with parser

I have a collection of files written in a language 'A' that need to be translated into corresponding files of a language 'B'. I want to create a program/parser that can automate this task (probably rather a toolchain than a single program).…
Ronin100
  • 85
  • 4
5
votes
1 answer

Pycparser failed on comments

When I'm trying to use pycparser to parse files with comments I got ParseError import pycparser parser = pycparser.CParser() parser.parse("int main(void){return 0;}") parser.parse("/* comment */ int main(void){return 0;}") Traceback (most recent…
Mikhail Aksenov
  • 944
  • 9
  • 23
4
votes
1 answer

How can I get around this pycparser installation error using poetry?

I'm using the latest version of poetry (1.1.10) and while trying to update my lock file, I ran into an error while attempting to install pycparser==2.20: Writing lock file Package operations: 65 installs, 0 updates, 0 removals • Installing…
Boris
  • 716
  • 1
  • 4
  • 25
4
votes
1 answer

Unable to modify pycparser AST | Convert AST to C code

I'm trying to modify/refactor input C source code. I'm trying to add a printf statement after every line of my input code. For e.g. if my input is - void foo(){ // Sample input code int a = 0, b = 0; a++; if(a<5) b++; …
Shash
  • 83
  • 7
3
votes
0 answers

Parsing from C to Javascript with pycparser

I am trying to parse some code in C into Javascript to use it on a website. I have downloaded pycparser as said in the github documentation https://github.com/eliben/pycparser but I donot know how to use it. For example what commands do I need to…
Maria M
  • 31
  • 2
3
votes
2 answers

C - int not-equal to printf?

What this C statement does? i=!({ printf("%d\n",r); }); i and r are integers. I'm trying to parse it using pycparser which doesn't recognize it and raises an error: pycparser.plyparser.ParseError: :7:6: before: { Thanks
Avihay
  • 63
  • 7
3
votes
1 answer

pycparser.plyparser.ParseError on complex struct

I'm trying to use pycparser to parse this C code: https://github.com/nbeaver/mx-trunk/blob/0b80678773582babcd56fe959d5cfbb776cc0004/libMx/d_adsc_two_theta.c A repo with a minimal example and Makefile is…
3
votes
2 answers

Pycparser not working on preprocessed code

I need to use pycparser on preprocessed C code (the results produced by 'gcc -E'). However I am currently running into issue that I can't understand or solve. I am using the provided samples year2.c and func_defs.py, which i modified to use a…
Araiguma
  • 69
  • 1
  • 4
3
votes
1 answer

#include
with pycparser

Using pycparser I encountered a problem with the included headers in the C code I want to parse. For some mysterious reason, some "fake header" works fine and other doesn't work as well. For example, if I include stdint.h, pycparser can parse the…
patatarte
  • 43
  • 4
3
votes
1 answer

how does pycparser reads the header files listed in includes in C code files?

I am trying to parse a C file using pycparser. I am curious to know that while pre-processing the C file does the pycparser reads only those library files which are provided in fake lib folder(if you provide the path of fake lib in cpp_args) or it…
2
votes
1 answer

Installing Packages with Poetry: ERROR: Can not combine '--user' and '--prefix' as they imply different installation locations

If I try to run poetry install I get the error • Installing six (1.16.0) CalledProcessError Command 'C:\Users\XXX\AppData\Local\pypoetry\Cache\virtualenvs\XXX-MaFxIpG_-py3.9\Scripts\python.exe -m pip install --disable-pip-version-check…
Lazloo Xp
  • 858
  • 1
  • 11
  • 36
2
votes
1 answer

How to extract and map function names and and their comments from C-header files?

I have many different .h files in different formats. They include function definitions, variable definitions and more. My goal is to extract all function names and their respective comments and map them. I am looking for a working approach to…
1
2 3 4 5 6