I am writing a C parser using PLY and have recently encountered a problem. This code:
typedef int my_type;
my_type x;
Correct C code, because my_type is defined as a type earlier as such. I process it by filling out a table of type characters in a parser, which is used by the lexer to distinguish between types and simple identifiers.
However, while the type declaration rule ends with SEMI (token ;;), PLY shifts the token my_typefrom the second line before making a decision from the first. Because of this, I have no way to pass the update in the type symbol table to lexer, and this sees my_type as an identifier, not a type.
Any ideas for a fix?
Full code: http://code.google.com/p/pycparser/source/browse/trunk/src/c_parser.py
I don’t know how I can create a smaller example from this.
Edit:
The problem is resolved. See My solution below.
source
share