inducer / pycparserext

Extensions for Eli Bendersky's pycparser
http://pypi.python.org/pypi/pycparserext
Other
83 stars 28 forks source link

Error while parsing C file #7

Open MaheshVenkateshwaran1203 opened 10 years ago

MaheshVenkateshwaran1203 commented 10 years ago

I have a .h file which I am trying to parse.

#include <stdio.h>

#define MAX_VAL 100
struct {
    int x;
    char a[MAX_VAL];
} mahesh_t;

after preprocessing it I get the following lines

cpp -E test.h > test.hh

excerpt from the file:

#1 "/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h" 1 3 4
#211 "/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h" 3 4
typedef long unsigned int size_t;
#35 "/usr/include/stdio.h" 2 3 4

when I try to run the script I get this error

$ python c-to-c.py ./test.hh
Traceback (most recent call last):
  File "c-to-c.py", line 60, in <module>
    translate_to_c(sys.argv[1])
  File "c-to-c.py", line 24, in translate_to_c
    ast = parse_file(filename, use_cpp=True)
  File "/usr/lib/python2.6/site-packages/pycparser/__init__.py", line 93, in parse_file
    return parser.parse(text, filename)
  File "/usr/lib/python2.6/site-packages/pycparser/c_parser.py", line 138, in parse
    debug=debuglevel)
  File "/usr/lib/python2.6/site-packages/pycparser/ply/yacc.py", line 265, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python2.6/site-packages/pycparser/ply/yacc.py", line 1047, in parseopt_notrack
    tok = self.errorfunc(errtoken)
  File "/usr/lib/python2.6/site-packages/pycparser/c_parser.py", line 1613, in p_error
    column=self.clex.find_tok_column(p)))
  File "/usr/lib/python2.6/site-packages/pycparser/plyparser.py", line 54, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: /usr/include/_G_config.h:53:24: before: __attribute__

Any ideas on how do I fix this? What wrong am I doing? thanks

inducer commented 10 years ago

No, sorry. Look for _G_config.h in the preprocessed source and try to figure out what parser production you're in, then try to fix the parser. I'd be happy to take a patch.

Andreas

thamilk commented 5 years ago

I run into similar issue, may someone share what is the solution for this issue ?

Thanks in advance.

pycparser.plyparser.ParseError: /usr/include/_G_config.h:53:24: before: attribute