0

我知道这是一个非常具体的问题,但我已经尽我所能寻找答案,但仍然没有提出任何有价值的东西。我正在使用 pycparser 尝试解析一些代码(惊喜,惊喜),当它进行链接时,它会失败并出现以下错误。如果有人有任何想法,我将不胜感激。

  File "test.py", line 14, in <module>
    cpp_args=['-E', r'-Iutils/fake_libc_include'])
  File "/usr/lib/python2.7/site-packages/pycparser/__init__.py", line 93, in parse_file
    return parser.parse(text, filename)
  File "/usr/lib/python2.7/site-packages/pycparser/c_parser.py", line 146, in parse
    debug=debuglevel)
  File "/usr/lib/python2.7/site-packages/ply/yacc.py", line 265, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python2.7/site-packages/ply/yacc.py", line 1047, in parseopt_notrack
    tok = self.errorfunc(errtoken)
  File "/usr/lib/python2.7/site-packages/pycparser/c_parser.py", line 1680, in p_error
    column=self.clex.find_tok_column(p)))
  File "/usr/lib/python2.7/site-packages/pycparser/plyparser.py", line 55, in
_parse_error
    raise ParseError("%s: %s" % (coord, msg))

/usr/include/bits/byteswap.h:46:1: before: {

这是在 CentOS 7 上。

编码:

      (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))

#ifdef __GNUC__
# if __GNUC_PREREQ (4, 3)
static __inline unsigned int
__bswap_32 (unsigned int __bsx)
{
  return __builtin_bswap32 (__bsx);
}
# elif __GNUC__ >= 2
#  if __WORDSIZE == 64 || (defined __i486__ || defined __pentium__            \
                           || defined __pentiumpro__ || defined __pentium4__  \
                           || defined __k8__ || defined __athlon__            \
                           || defined __k6__ || defined __nocona__            \
                           || defined __core2__ || defined __geode__          \
                           || defined __amdfam10__)
4

2 回答 2

2

所以我真的没有答案,但我至少会将此作为解决方法发布,以防其他人遇到同样的问题。我必须通过预处理器手动运行我的代码,因为我认为有一些编译器问题会导致 pycparser 问题(我知道这很奇怪)。无论如何,手动预处理代码然后使用 pycparser 解析对我有用!

于 2016-05-25T22:40:09.910 回答
1

pyparser 不支持编译器特定的关键字,例如__inline. 您必须使用 fake_libc_include 标头。见https://github.com/eliben/pycparser/wiki/FAQ

于 2016-08-05T22:44:44.617 回答