I have this example c file I want to parse:
StrcutWithinStruct.c
// simple struct within a struct example
struct A {
int a;
};
struct B {
A a;
int b;
};
I'm running pcyparser to parse it, with the following code
exploreStruct.py
#parse StructWithinStruct
from pycparser import parse_file
ast = parse_file(filename='..\StructWithinStruct.c')
ast.show()
As a result, I got the following:
Tracback (most recent call last):
File "exploreStruct.py", line 3, in <module>
ast = parse_file(filename='...\StructWithinStruct.c')
File "D:\...\pycparser\__init__.py", line 93, in parse_file
return parser.parse(text,filename)
File "D:\...\pycparser\c_parser.py", line 146, in parse
debug=debug_level)
File "D:\...\pycparser\yacc.py", line 331, in parse
return self.parseropt_notrack(input, lexer, debug, tracking, tokenfunc)
File "D:\...\pycparser\yacc.py", line 1181, in parseropt_notrack
tok=call_errorfunc(self.errorfunc, errtoken, self)
File "D:\...\pycparser\yacc.py", line 193, in call_errorfunc
r=errorfunc(token)
File "D:\...\pycparser\c_parser.py", line 1699, in p_error
column=self.clex.find_tok_column(p)))
File "D:\...\pycparser\plyparser.py", line 55, in _parse_error
raise ParseError("%s: %s % (coord, msg))
pycparser.plyparser.ParserError: D:...\StructWithinStruct.c:7:2: Before A
So, is pycparser can handle struct within struct, or not? I thought this is some basic requirement, so I'm pretty sure that the problem lying in my configuration somewhere...
One more thing: I know that pcypareser author, @Eli Bendersky, says that one should use Clang to parse C++, but I will like to know if there's another option nowadays to parse C++ (preferably over Python), and is user-friendly.
Thanks.