0

I'm using pycparser to parse some C code. Specifically code that can contain Japanese character inside characters and string such as below:

int main()
{
    char ch = '本';
}

I have tried to compile this on Dev-c, and compiles properly. Is this possible with pycparser?

Thor
  • 13
  • 2

1 Answers1

0

What issues are you observing? I think it's working:

$ cat /tmp/45.c
int main()
{
    char ch = '本';
}
$ python3 examples/dump_ast.py /tmp/45.c 
FileAST: 
  FuncDef: 
    Decl: main, [], [], []
      FuncDecl: 
        TypeDecl: main, []
          IdentifierType: ['int']
    Compound: 
      Decl: ch, [], [], []
        TypeDecl: ch, []
          IdentifierType: ['char']
        Constant: char, '本'
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • I get the following error, File "C:\Python34\lib\site-packages\pycparser\plyparser.py", line 67, in _parse_error raise ParseError("%s: %s" % (coord, msg)) pycparser.plyparser.ParseError: ./multi.c:3:15: Invalid char constant '本' – Thor Oct 01 '18 at 05:42
  • I'm using version 2.19 anyway – Thor Oct 01 '18 at 05:43
  • I'm also using gcc as my preprocessor – Thor Oct 01 '18 at 18:13
  • I got this to work, it was my mistake, I used an incorrect encoding to read the file in the first place. – Thor May 21 '20 at 13:12