Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while parsing C file #7

Open
MaheshVenkateshwaran1203 opened this issue Jan 2, 2014 · 2 comments
Open

Error while parsing C file #7

MaheshVenkateshwaran1203 opened this issue Jan 2, 2014 · 2 comments

Comments

@MaheshVenkateshwaran1203

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
Copy link
Owner

inducer commented Jan 2, 2014

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
Copy link

thamilk commented Nov 19, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants