Question

Does anybody know if there is a way to add a new keyword to pycparser? I need to parse C code for the compiler which is based on C99 but is slightly different. There are a few keywords that are not part of C99.

Any help is appreciated

No correct solution

OTHER TIPS

c_lexer.py module has a tuple "keywords" definition. New keywords can be added to the existing list. Make sure the new keywords are accounted for in syntax rules defined in c_parser.py. For example, if a new type "mytype_t" has been added to the keywords, it has to be also added to the p_type_specifier function doc string in order to extend definition of the "type_specifier" as shown in the following example:

def p_type_specifier_1(self, p):
    """ type_specifier  : VOID
                        | BOOL
                        | CHAR
                        | MYTYPE_T
                        ...

Same approach works for other types of keywords.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top