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

Does pycparser supports user defined types?

Does pycparser supports user defined types? I want to get list of functions with user defined type as return type from *.C file.
pipsik
  • 219
  • 1
  • 2
  • 9
0
votes
1 answer

Not able to run basic example of pycparser

I am trying to start with pycparser and was trying to run the examples given on the github repo. I only changed the path of the file to be parsed after saving the sample c file locally. I get the following error and am not sure if there is some…
pHM
  • 315
  • 5
  • 17
0
votes
1 answer

generator.visit of pycparser displaying wrong output in Ubuntu 16.04.3

I have written the following program using pycparser and pycparserext: from pycparser import parse_file,c_parser, c_ast, c_generator from pycparserext.ext_c_parser import GnuCParser content="int main() { int x = 1; int y = 0; while (y < 1000 &&…
Tom
  • 904
  • 1
  • 7
  • 21
0
votes
1 answer

Using pycparser i would like to extract the statements in a function?

For example i have this statement in my function definition (void)((void)( SchM_Enter_Com(COM_EXCLUSIVE_AREA_0), (*( uint8 *)((((&*bix_rx_bms_stat_ar2_BMS_BatTmp_Max_A*))))) = (uint8) ( ((*(com_UnionBuffer.raw)[(0u) + 2]* & (uint8)0xe0) >> 5u) |…
Alwin Joy
  • 1
  • 2
0
votes
1 answer

Get column number of C construct in ast generated by pycparser

I do know that "coord" attribute of AST node gives the line number but by default it has column number set as None. Is there a way to set this to true column number?
manish RAI
  • 3
  • 1
  • 2
0
votes
1 answer

How to get function names of Linux Kernel files with pycparser?

I created fake header files under pycparser/utils/fake_libc_include for every header found in kernel/sched/core.c and put #include "_fake_defines.h" #include "_fake_typedefs.h" into them. A few other header files where missing, lot's of headers…
JohnnyFromBF
  • 9,873
  • 10
  • 45
  • 59
0
votes
1 answer

How to find function name in function declarations with pycparser?

I found the following example to search for a specific function name like malloc, but I want to find all function names in function declarations of a C source file. So in the case of ReturnCode HashCreate(Hash** hash, unsigned int table_size) I'm…
JohnnyFromBF
  • 9,873
  • 10
  • 45
  • 59
0
votes
2 answers

Pycparser parse error on byteswap.h

I know that this is a pretty specific issue but I've done about all I can to search for an answer and still haven't come up with anything of value. I'm using pycparser to try and parse some code in (surprise, surprise) and when it does the linking…
rreichel
  • 794
  • 3
  • 9
  • 25
0
votes
1 answer

"Unresolved import: module" when importing a module into LiClipse

I have installed liclipse 2.4 (Python 3.0 grammar) recently and downloaded pycparser-master.zip file, extracted it, and added the pycparser-master/pycparser/ directory under Project->Properties->PyDev-PYTHONPATH->External Libraries. I used the below…
user691197
  • 927
  • 6
  • 20
  • 38
0
votes
2 answers

pycparser nested node visitor

I am tring to parse a C code with pycparser with visitor for every IF statements. From my observation it only visits top nodes without nested IFs. Is it intentional, or something is wrong in my code?
Knight of Ni
  • 1,780
  • 3
  • 20
  • 47
0
votes
2 answers

pycparser ParseError with typedef

I'm using pycparser to parse some C code that I cannot compile with cpp before parsing, so I'm manually stripping off all comments and preprocessor directives with the following function: def remove_comments(text): def replacer(match): s…
Vektor88
  • 4,841
  • 11
  • 59
  • 111
0
votes
1 answer

Is there any way to avoid parse-errors in pycparser library of python

The below code triggers an error in .c file when pycparser tries to parse it. This might be because rf_wcdma_bup_flags_t is not a defined typedef, is there anyway to skip it? rf_wcdma_bup_flags_t rf_wcdma_debug_flags = { 0 };
0
votes
2 answers

Converting a parse tree to a string

I used PycParser to generate an abstract syntax tree for a C function, but I'm still trying to figure out how to convert the parse tree into a string: from pycparser import c_parser src = ''' int hello(a, b){ return a + b; } ''' ast =…
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
0
votes
1 answer

python pyparser fails at #pragma directive

The python C-parser pycparser fails at the following #pragma directive: #pragma ghs section somestring="some_other_string" generates error: AssertionError: invalid #pragma directive What's wrong with this #pragma?
michal.szulc
  • 71
  • 1
  • 4
0
votes
1 answer

Find all macro definition in c header file

I am trying to get list of all macro definitions in a c header file by using pycparser. Can you please help me on this issue with an example if possible? Thanks.