💾 Archived View for tris.fyi › pydoc › pycparser.c_parser captured on 2022-03-01 at 16:06:05. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-01-08)

➡️ Next capture (2022-07-16)

-=-=-=-=-=-=-

Back to module index

Go to module by name

pycparser

pycparser.c_parser

This module has no docstring.

Classes

CLexer

 A lexer for the C language. After building it, set the
        input text with input(), and call token() to get new
        tokens.

        The public attribute filename can be set to an initial
        filename, but the lexer will update it upon #line
        directives.
    
build(self, **kwargs)

   Builds the lexer from the specification. Must be
              called after the lexer object is created.

              This method exists separately, because the PLY
              manual warns against calling lex.lex inside
              __init__
        
find_tok_column(self, token)

   Find the column of the token in its line.
        
input(self, text)
reset_lineno(self)

   Resets the internal line number counter of the lexer.
        
t_BAD_CHAR_CONST(self, t)
t_BAD_CONST_OCT(self, t)
t_BAD_STRING_LITERAL(self, t)
t_CHAR_CONST(self, t)
t_FLOAT_CONST(self, t)
t_HEX_FLOAT_CONST(self, t)
t_ID(self, t)
t_INT_CONST_BIN(self, t)
t_INT_CONST_CHAR(self, t)
t_INT_CONST_DEC(self, t)
t_INT_CONST_HEX(self, t)
t_INT_CONST_OCT(self, t)
t_LBRACE(self, t)
t_NEWLINE(self, t)

  \n+
t_PPHASH(self, t)

  [ \t]*\#
t_RBRACE(self, t)
t_UNMATCHED_QUOTE(self, t)
t_WCHAR_CONST(self, t)
t_WSTRING_LITERAL(self, t)
t_error(self, t)
t_ppline_FILENAME(self, t)
t_ppline_LINE_NUMBER(self, t)
t_ppline_NEWLINE(self, t)

  \n
t_ppline_PPLINE(self, t)

  line
t_ppline_error(self, t)
t_pppragma_NEWLINE(self, t)

  \n
t_pppragma_PPPRAGMA(self, t)

  pragma
t_pppragma_STR(self, t)

  .+
t_pppragma_error(self, t)
token(self)
bad_char_const = '(\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F]))))[^\'\n]+\')|(\'\')|(\'([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-9])[^\'\\n]*\')'
bad_escape = '([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-9])'
bad_octal_constant = '0[0-7]*[89]'
bad_string_literal = '"([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-9])([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*"'
bin_constant = '0[bB][01]+(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?'
bin_digits = '[01]+'
bin_prefix = '0[bB]'
binary_exponent_part = '([pP][+-]?[0-9]+)'
cconst_char = '([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F]))))'
char_const = '\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F]))))\''
decimal_constant = '(0(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?)|([1-9][0-9]*(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?)'
decimal_escape = '(\\d+)(?!\\d)'
escape_sequence = '(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F])))'
escape_sequence_start_in_string = '(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"])'
exponent_part = '([eE][-+]?[0-9]+)'
floating_constant = '((((([0-9]*\\.[0-9]+)|([0-9]+\\.))([eE][-+]?[0-9]+)?)|([0-9]+([eE][-+]?[0-9]+)))[FfLl]?)'
fractional_constant = '([0-9]*\\.[0-9]+)|([0-9]+\\.)'
hex_constant = '0[xX][0-9a-fA-F]+(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?'
hex_digits = '[0-9a-fA-F]+'
hex_escape = '(x[0-9a-fA-F]+)(?![0-9a-fA-F])'
hex_floating_constant = '(0[xX]([0-9a-fA-F]+|((([0-9a-fA-F]+)?\\.[0-9a-fA-F]+)|([0-9a-fA-F]+\\.)))([pP][+-]?[0-9]+)[FfLl]?)'
hex_fractional_constant = '((([0-9a-fA-F]+)?\\.[0-9a-fA-F]+)|([0-9a-fA-F]+\\.))'
hex_prefix = '0[xX]'
identifier = '[a-zA-Z_$][0-9a-zA-Z_$]*'
integer_suffix_opt = '(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?'
keyword = '__INT128'
keyword_map = {'_Bool': '_BOOL', '_Complex': '_COMPLEX', 'auto': 'AUTO', 'break': 'BREAK', 'case': 'CASE', 'char': 'CHAR', 'const': 'CONST', 'continue': 'CONTINUE', 'default': 'DEFAULT', 'do': 'DO', 'double': 'DOUBLE', 'else': 'ELSE', 'enum': 'ENUM', 'extern': 'EXTERN', 'float': 'FLOAT', 'for': 'FOR', 'goto': 'GOTO', 'if': 'IF', 'inline': 'INLINE', 'int': 'INT', 'long': 'LONG', 'register': 'REGISTER', 'offsetof': 'OFFSETOF', 'restrict': 'RESTRICT', 'return': 'RETURN', 'short': 'SHORT', 'signed': 'SIGNED', 'sizeof': 'SIZEOF', 'static': 'STATIC', 'struct': 'STRUCT', 'switch': 'SWITCH', 'typedef': 'TYPEDEF', 'union': 'UNION', 'unsigned': 'UNSIGNED', 'void': 'VOID', 'volatile': 'VOLATILE', 'while': 'WHILE', '__int128': '__INT128'}
keywords = ('_BOOL', '_COMPLEX', 'AUTO', 'BREAK', 'CASE', 'CHAR', 'CONST', 'CONTINUE', 'DEFAULT', 'DO', 'DOUBLE', 'ELSE', 'ENUM', 'EXTERN', 'FLOAT', 'FOR', 'GOTO', 'IF', 'INLINE', 'INT', 'LONG', 'REGISTER', 'OFFSETOF', 'RESTRICT', 'RETURN', 'SHORT', 'SIGNED', 'SIZEOF', 'STATIC', 'STRUCT', 'SWITCH', 'TYPEDEF', 'UNION', 'UNSIGNED', 'VOID', 'VOLATILE', 'WHILE', '__INT128')
multicharacter_constant = '\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F])))){2,4}\''
octal_constant = '0[0-7]*(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?'
simple_escape = '([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))'
states = (('ppline', 'exclusive'), ('pppragma', 'exclusive'))
string_char = '([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))'
string_literal = '"([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*"'
t_AND = '&'
t_ANDEQUAL = '&='
t_ARROW = '->'
t_COLON = ':'
t_COMMA = ','
t_CONDOP = '\\?'
t_DIVEQUAL = '/='
t_DIVIDE = '/'
t_ELLIPSIS = '\\.\\.\\.'
t_EQ = '=='
t_EQUALS = '='
t_GE = '>='
t_GT = '>'
t_LAND = '&&'
t_LBRACKET = '\\['
t_LE = '<='
t_LNOT = '!'
t_LOR = '\\|\\|'
t_LPAREN = '\\('
t_LSHIFT = '<<'
t_LSHIFTEQUAL = '<<='
t_LT = '<'
t_MINUS = '-'
t_MINUSEQUAL = '-='
t_MINUSMINUS = '--'
t_MOD = '%'
t_MODEQUAL = '%='
t_NE = '!='
t_NOT = '~'
t_OR = '\\|'
t_OREQUAL = '\\|='
t_PERIOD = '\\.'
t_PLUS = '\\+'
t_PLUSEQUAL = '\\+='
t_PLUSPLUS = '\\+\\+'
t_RBRACKET = '\\]'
t_RPAREN = '\\)'
t_RSHIFT = '>>'
t_RSHIFTEQUAL = '>>='
t_SEMI = ';'
t_STRING_LITERAL = '"([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*"'
t_TIMES = '\\*'
t_TIMESEQUAL = '\\*='
t_XOR = '\\^'
t_XOREQUAL = '\\^='
t_ignore = ' \t'
t_ppline_ignore = ' \t'
t_pppragma_ignore = ' \t'
tokens = ('_BOOL', '_COMPLEX', 'AUTO', 'BREAK', 'CASE', 'CHAR', 'CONST', 'CONTINUE', 'DEFAULT', 'DO', 'DOUBLE', 'ELSE', 'ENUM', 'EXTERN', 'FLOAT', 'FOR', 'GOTO', 'IF', 'INLINE', 'INT', 'LONG', 'REGISTER', 'OFFSETOF', 'RESTRICT', 'RETURN', 'SHORT', 'SIGNED', 'SIZEOF', 'STATIC', 'STRUCT', 'SWITCH', 'TYPEDEF', 'UNION', 'UNSIGNED', 'VOID', 'VOLATILE', 'WHILE', '__INT128', 'ID', 'TYPEID', 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', 'INT_CONST_BIN', 'INT_CONST_CHAR', 'FLOAT_CONST', 'HEX_FLOAT_CONST', 'CHAR_CONST', 'WCHAR_CONST', 'STRING_LITERAL', 'WSTRING_LITERAL', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD', 'OR', 'AND', 'NOT', 'XOR', 'LSHIFT', 'RSHIFT', 'LOR', 'LAND', 'LNOT', 'LT', 'LE', 'GT', 'GE', 'EQ', 'NE', 'EQUALS', 'TIMESEQUAL', 'DIVEQUAL', 'MODEQUAL', 'PLUSEQUAL', 'MINUSEQUAL', 'LSHIFTEQUAL', 'RSHIFTEQUAL', 'ANDEQUAL', 'XOREQUAL', 'OREQUAL', 'PLUSPLUS', 'MINUSMINUS', 'ARROW', 'CONDOP', 'LPAREN', 'RPAREN', 'LBRACKET', 'RBRACKET', 'LBRACE', 'RBRACE', 'COMMA', 'PERIOD', 'SEMI', 'COLON', 'ELLIPSIS', 'PPHASH', 'PPPRAGMA', 'PPPRAGMASTR')
unmatched_quote = '(\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F]))))*\\n)|(\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F]))))*$)'
wchar_const = 'L\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)|(x[0-9a-fA-F]+)(?![0-9a-fA-F]))))\''
wstring_literal = 'L"([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*"'

CParser

p_abstract_declarator_1(self, p)

   abstract_declarator     : pointer
        
p_abstract_declarator_2(self, p)

   abstract_declarator     : pointer direct_abstract_declarator
        
p_abstract_declarator_3(self, p)

   abstract_declarator     : direct_abstract_declarator
        
p_argument_expression_list(self, p)

   argument_expression_list    : assignment_expression
                                          | argument_expression_list COMMA assignment_expression
        
p_assignment_expression(self, p)

   assignment_expression   : conditional_expression
                                      | unary_expression assignment_operator assignment_expression
        
p_assignment_operator(self, p)

   assignment_operator : EQUALS
                                  | XOREQUAL
                                  | TIMESEQUAL
                                  | DIVEQUAL
                                  | MODEQUAL
                                  | PLUSEQUAL
                                  | MINUSEQUAL
                                  | LSHIFTEQUAL
                                  | RSHIFTEQUAL
                                  | ANDEQUAL
                                  | OREQUAL
        
p_binary_expression(self, p)

   binary_expression   : cast_expression
                                  | binary_expression TIMES binary_expression
                                  | binary_expression DIVIDE binary_expression
                                  | binary_expression MOD binary_expression
                                  | binary_expression PLUS binary_expression
                                  | binary_expression MINUS binary_expression
                                  | binary_expression RSHIFT binary_expression
                                  | binary_expression LSHIFT binary_expression
                                  | binary_expression LT binary_expression
                                  | binary_expression LE binary_expression
                                  | binary_expression GE binary_expression
                                  | binary_expression GT binary_expression
                                  | binary_expression EQ binary_expression
                                  | binary_expression NE binary_expression
                                  | binary_expression AND binary_expression
                                  | binary_expression OR binary_expression
                                  | binary_expression XOR binary_expression
                                  | binary_expression LAND binary_expression
                                  | binary_expression LOR binary_expression
        
p_block_item(self, p)

   block_item  : declaration
                          | statement
        
p_block_item_list(self, p)

   block_item_list : block_item
                              | block_item_list block_item
        
p_brace_close(self, p)

   brace_close :   RBRACE
        
p_brace_open(self, p)

   brace_open  :   LBRACE
        
p_cast_expression_1(self, p)

   cast_expression : unary_expression 
p_cast_expression_2(self, p)

   cast_expression : LPAREN type_name RPAREN cast_expression 
p_compound_statement_1(self, p)

   compound_statement : brace_open block_item_list_opt brace_close 
p_conditional_expression(self, p)

   conditional_expression  : binary_expression
                                      | binary_expression CONDOP expression COLON conditional_expression
        
p_constant_1(self, p)

   constant    : INT_CONST_DEC
                          | INT_CONST_OCT
                          | INT_CONST_HEX
                          | INT_CONST_BIN
                          | INT_CONST_CHAR
        
p_constant_2(self, p)

   constant    : FLOAT_CONST
                          | HEX_FLOAT_CONST
        
p_constant_3(self, p)

   constant    : CHAR_CONST
                          | WCHAR_CONST
        
p_constant_expression(self, p)

   constant_expression : conditional_expression 
p_decl_body(self, p)

   decl_body : declaration_specifiers init_declarator_list_opt
                        | declaration_specifiers_no_type id_init_declarator_list_opt
        
p_declaration(self, p)

   declaration : decl_body SEMI
        
p_declaration_list(self, p)

   declaration_list    : declaration
                                  | declaration_list declaration
        
p_declaration_specifiers_1(self, p)

   declaration_specifiers  : declaration_specifiers type_qualifier
        
p_declaration_specifiers_2(self, p)

   declaration_specifiers  : declaration_specifiers storage_class_specifier
        
p_declaration_specifiers_3(self, p)

   declaration_specifiers  : declaration_specifiers function_specifier
        
p_declaration_specifiers_4(self, p)

   declaration_specifiers  : declaration_specifiers type_specifier_no_typeid
        
p_declaration_specifiers_5(self, p)

   declaration_specifiers  : type_specifier
        
p_declaration_specifiers_6(self, p)

   declaration_specifiers  : declaration_specifiers_no_type type_specifier
        
p_declaration_specifiers_no_type_1(self, p)

   declaration_specifiers_no_type  : type_qualifier declaration_specifiers_no_type_opt
        
p_declaration_specifiers_no_type_2(self, p)

   declaration_specifiers_no_type  : storage_class_specifier declaration_specifiers_no_type_opt
        
p_declaration_specifiers_no_type_3(self, p)

   declaration_specifiers_no_type  : function_specifier declaration_specifiers_no_type_opt
        
p_declarator(self, p)

   declarator  : id_declarator
                          | typeid_declarator
        
p_designation(self, p)

   designation : designator_list EQUALS
        
p_designator(self, p)

   designator  : LBRACKET constant_expression RBRACKET
                          | PERIOD identifier
        
p_designator_list(self, p)

   designator_list : designator
                              | designator_list designator
        
p_direct_abstract_declarator_1(self, p)

   direct_abstract_declarator  : LPAREN abstract_declarator RPAREN 
p_direct_abstract_declarator_2(self, p)

   direct_abstract_declarator  : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET
        
p_direct_abstract_declarator_3(self, p)

   direct_abstract_declarator  : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        
p_direct_abstract_declarator_4(self, p)

   direct_abstract_declarator  : direct_abstract_declarator LBRACKET TIMES RBRACKET
        
p_direct_abstract_declarator_5(self, p)

   direct_abstract_declarator  : LBRACKET TIMES RBRACKET
        
p_direct_abstract_declarator_6(self, p)

   direct_abstract_declarator  : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN
        
p_direct_abstract_declarator_7(self, p)

   direct_abstract_declarator  : LPAREN parameter_type_list_opt RPAREN
        
p_direct_id_declarator_1(self, p)

   direct_id_declarator   : ID
        
p_direct_id_declarator_2(self, p)

   direct_id_declarator   : LPAREN id_declarator RPAREN
        
p_direct_id_declarator_3(self, p)

   direct_id_declarator   : direct_id_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        
p_direct_id_declarator_4(self, p)

   direct_id_declarator   : direct_id_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
                                      | direct_id_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
        
p_direct_id_declarator_5(self, p)

   direct_id_declarator   : direct_id_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
        
p_direct_id_declarator_6(self, p)

   direct_id_declarator   : direct_id_declarator LPAREN parameter_type_list RPAREN
                                      | direct_id_declarator LPAREN identifier_list_opt RPAREN
        
p_direct_typeid_declarator_1(self, p)

   direct_typeid_declarator   : TYPEID
        
p_direct_typeid_declarator_2(self, p)

   direct_typeid_declarator   : LPAREN typeid_declarator RPAREN
        
p_direct_typeid_declarator_3(self, p)

   direct_typeid_declarator   : direct_typeid_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        
p_direct_typeid_declarator_4(self, p)

   direct_typeid_declarator   : direct_typeid_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
                                      | direct_typeid_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
        
p_direct_typeid_declarator_5(self, p)

   direct_typeid_declarator   : direct_typeid_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
        
p_direct_typeid_declarator_6(self, p)

   direct_typeid_declarator   : direct_typeid_declarator LPAREN parameter_type_list RPAREN
                                      | direct_typeid_declarator LPAREN identifier_list_opt RPAREN
        
p_direct_typeid_noparen_declarator_1(self, p)

   direct_typeid_noparen_declarator   : TYPEID
        
p_direct_typeid_noparen_declarator_3(self, p)

   direct_typeid_noparen_declarator   : direct_typeid_noparen_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        
p_direct_typeid_noparen_declarator_4(self, p)

   direct_typeid_noparen_declarator   : direct_typeid_noparen_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
                                      | direct_typeid_noparen_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
        
p_direct_typeid_noparen_declarator_5(self, p)

   direct_typeid_noparen_declarator   : direct_typeid_noparen_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
        
p_direct_typeid_noparen_declarator_6(self, p)

   direct_typeid_noparen_declarator   : direct_typeid_noparen_declarator LPAREN parameter_type_list RPAREN
                                      | direct_typeid_noparen_declarator LPAREN identifier_list_opt RPAREN
        
p_empty(self, p)

  empty : 
p_enum_specifier_1(self, p)

   enum_specifier  : ENUM ID
                              | ENUM TYPEID
        
p_enum_specifier_2(self, p)

   enum_specifier  : ENUM brace_open enumerator_list brace_close
        
p_enum_specifier_3(self, p)

   enum_specifier  : ENUM ID brace_open enumerator_list brace_close
                              | ENUM TYPEID brace_open enumerator_list brace_close
        
p_enumerator(self, p)

   enumerator  : ID
                          | ID EQUALS constant_expression
        
p_enumerator_list(self, p)

   enumerator_list : enumerator
                              | enumerator_list COMMA
                              | enumerator_list COMMA enumerator
        
p_error(self, p)
p_expression(self, p)

   expression  : assignment_expression
                          | expression COMMA assignment_expression
        
p_expression_statement(self, p)

   expression_statement : expression_opt SEMI 
p_external_declaration_1(self, p)

   external_declaration    : function_definition
        
p_external_declaration_2(self, p)

   external_declaration    : declaration
        
p_external_declaration_3(self, p)

   external_declaration    : pp_directive
                                      | pppragma_directive
        
p_external_declaration_4(self, p)

   external_declaration    : SEMI
        
p_function_definition_1(self, p)

   function_definition : id_declarator declaration_list_opt compound_statement
        
p_function_definition_2(self, p)

   function_definition : declaration_specifiers id_declarator declaration_list_opt compound_statement
        
p_function_specifier(self, p)

   function_specifier  : INLINE
        
p_id_declarator_1(self, p)

   id_declarator  : direct_id_declarator
        
p_id_declarator_2(self, p)

   id_declarator  : pointer direct_id_declarator
        
p_id_init_declarator(self, p)

   id_init_declarator : id_declarator
                                 | id_declarator EQUALS initializer
        
p_id_init_declarator_list(self, p)

   id_init_declarator_list    : id_init_declarator
                                         | id_init_declarator_list COMMA init_declarator
        
p_identifier(self, p)

   identifier  : ID 
p_identifier_list(self, p)

   identifier_list : identifier
                              | identifier_list COMMA identifier
        
p_init_declarator(self, p)

   init_declarator : declarator
                              | declarator EQUALS initializer
        
p_init_declarator_list(self, p)

   init_declarator_list    : init_declarator
                                      | init_declarator_list COMMA init_declarator
        
p_initializer_1(self, p)

   initializer : assignment_expression
        
p_initializer_2(self, p)

   initializer : brace_open initializer_list_opt brace_close
                          | brace_open initializer_list COMMA brace_close
        
p_initializer_list(self, p)

   initializer_list    : designation_opt initializer
                                  | initializer_list COMMA designation_opt initializer
        
p_iteration_statement_1(self, p)

   iteration_statement : WHILE LPAREN expression RPAREN pragmacomp_or_statement 
p_iteration_statement_2(self, p)

   iteration_statement : DO pragmacomp_or_statement WHILE LPAREN expression RPAREN SEMI 
p_iteration_statement_3(self, p)

   iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement 
p_iteration_statement_4(self, p)

   iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement 
p_jump_statement_1(self, p)

   jump_statement  : GOTO ID SEMI 
p_jump_statement_2(self, p)

   jump_statement  : BREAK SEMI 
p_jump_statement_3(self, p)

   jump_statement  : CONTINUE SEMI 
p_jump_statement_4(self, p)

   jump_statement  : RETURN expression SEMI
                              | RETURN SEMI
        
p_labeled_statement_1(self, p)

   labeled_statement : ID COLON pragmacomp_or_statement 
p_labeled_statement_2(self, p)

   labeled_statement : CASE constant_expression COLON pragmacomp_or_statement 
p_labeled_statement_3(self, p)

   labeled_statement : DEFAULT COLON pragmacomp_or_statement 
p_offsetof_member_designator(self, p)

   offsetof_member_designator : identifier
                                           | offsetof_member_designator PERIOD identifier
                                           | offsetof_member_designator LBRACKET expression RBRACKET
        
p_parameter_declaration_1(self, p)

   parameter_declaration   : declaration_specifiers id_declarator
                                      | declaration_specifiers typeid_noparen_declarator
        
p_parameter_declaration_2(self, p)

   parameter_declaration   : declaration_specifiers abstract_declarator_opt
        
p_parameter_list(self, p)

   parameter_list  : parameter_declaration
                              | parameter_list COMMA parameter_declaration
        
p_parameter_type_list(self, p)

   parameter_type_list : parameter_list
                                  | parameter_list COMMA ELLIPSIS
        
p_pointer(self, p)

   pointer : TIMES type_qualifier_list_opt
                      | TIMES type_qualifier_list_opt pointer
        
p_postfix_expression_1(self, p)

   postfix_expression  : primary_expression 
p_postfix_expression_2(self, p)

   postfix_expression  : postfix_expression LBRACKET expression RBRACKET 
p_postfix_expression_3(self, p)

   postfix_expression  : postfix_expression LPAREN argument_expression_list RPAREN
                                  | postfix_expression LPAREN RPAREN
        
p_postfix_expression_4(self, p)

   postfix_expression  : postfix_expression PERIOD ID
                                  | postfix_expression PERIOD TYPEID
                                  | postfix_expression ARROW ID
                                  | postfix_expression ARROW TYPEID
        
p_postfix_expression_5(self, p)

   postfix_expression  : postfix_expression PLUSPLUS
                                  | postfix_expression MINUSMINUS
        
p_postfix_expression_6(self, p)

   postfix_expression  : LPAREN type_name RPAREN brace_open initializer_list brace_close
                                  | LPAREN type_name RPAREN brace_open initializer_list COMMA brace_close
        
p_pp_directive(self, p)

   pp_directive  : PPHASH
        
p_pppragma_directive(self, p)

   pppragma_directive      : PPPRAGMA
                                      | PPPRAGMA PPPRAGMASTR
        
p_pragmacomp_or_statement(self, p)

   pragmacomp_or_statement     : pppragma_directive statement
                                          | statement
        
p_primary_expression_1(self, p)

   primary_expression  : identifier 
p_primary_expression_2(self, p)

   primary_expression  : constant 
p_primary_expression_3(self, p)

   primary_expression  : unified_string_literal
                                  | unified_wstring_literal
        
p_primary_expression_4(self, p)

   primary_expression  : LPAREN expression RPAREN 
p_primary_expression_5(self, p)

   primary_expression  : OFFSETOF LPAREN type_name COMMA offsetof_member_designator RPAREN
        
p_selection_statement_1(self, p)

   selection_statement : IF LPAREN expression RPAREN pragmacomp_or_statement 
p_selection_statement_2(self, p)

   selection_statement : IF LPAREN expression RPAREN statement ELSE pragmacomp_or_statement 
p_selection_statement_3(self, p)

   selection_statement : SWITCH LPAREN expression RPAREN pragmacomp_or_statement 
p_specifier_qualifier_list_1(self, p)

   specifier_qualifier_list    : specifier_qualifier_list type_specifier_no_typeid
        
p_specifier_qualifier_list_2(self, p)

   specifier_qualifier_list    : specifier_qualifier_list type_qualifier
        
p_specifier_qualifier_list_3(self, p)

   specifier_qualifier_list  : type_specifier
        
p_specifier_qualifier_list_4(self, p)

   specifier_qualifier_list  : type_qualifier_list type_specifier
        
p_statement(self, p)

   statement   : labeled_statement
                          | expression_statement
                          | compound_statement
                          | selection_statement
                          | iteration_statement
                          | jump_statement
                          | pppragma_directive
        
p_storage_class_specifier(self, p)

   storage_class_specifier : AUTO
                                      | REGISTER
                                      | STATIC
                                      | EXTERN
                                      | TYPEDEF
        
p_struct_declaration_1(self, p)

   struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI
        
p_struct_declaration_2(self, p)

   struct_declaration : SEMI
        
p_struct_declaration_3(self, p)

   struct_declaration : pppragma_directive
        
p_struct_declaration_list(self, p)

   struct_declaration_list     : struct_declaration
                                          | struct_declaration_list struct_declaration
        
p_struct_declarator_1(self, p)

   struct_declarator : declarator
        
p_struct_declarator_2(self, p)

   struct_declarator   : declarator COLON constant_expression
                                  | COLON constant_expression
        
p_struct_declarator_list(self, p)

   struct_declarator_list  : struct_declarator
                                      | struct_declarator_list COMMA struct_declarator
        
p_struct_or_union(self, p)

   struct_or_union : STRUCT
                              | UNION
        
p_struct_or_union_specifier_1(self, p)

   struct_or_union_specifier   : struct_or_union ID
                                          | struct_or_union TYPEID
        
p_struct_or_union_specifier_2(self, p)

   struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close
                                        | struct_or_union brace_open brace_close
        
p_struct_or_union_specifier_3(self, p)

   struct_or_union_specifier   : struct_or_union ID brace_open struct_declaration_list brace_close
                                          | struct_or_union ID brace_open brace_close
                                          | struct_or_union TYPEID brace_open struct_declaration_list brace_close
                                          | struct_or_union TYPEID brace_open brace_close
        
p_translation_unit_1(self, p)

   translation_unit    : external_declaration
        
p_translation_unit_2(self, p)

   translation_unit    : translation_unit external_declaration
        
p_translation_unit_or_empty(self, p)

   translation_unit_or_empty   : translation_unit
                                          | empty
        
p_type_name(self, p)

   type_name   : specifier_qualifier_list abstract_declarator_opt
        
p_type_qualifier(self, p)

   type_qualifier  : CONST
                              | RESTRICT
                              | VOLATILE
        
p_type_qualifier_list(self, p)

   type_qualifier_list : type_qualifier
                                  | type_qualifier_list type_qualifier
        
p_type_specifier(self, p)

   type_specifier  : typedef_name
                              | enum_specifier
                              | struct_or_union_specifier
                              | type_specifier_no_typeid
        
p_type_specifier_no_typeid(self, p)

   type_specifier_no_typeid  : VOID
                                        | _BOOL
                                        | CHAR
                                        | SHORT
                                        | INT
                                        | LONG
                                        | FLOAT
                                        | DOUBLE
                                        | _COMPLEX
                                        | SIGNED
                                        | UNSIGNED
                                        | __INT128
        
p_typedef_name(self, p)

   typedef_name : TYPEID 
p_typeid_declarator_1(self, p)

   typeid_declarator  : direct_typeid_declarator
        
p_typeid_declarator_2(self, p)

   typeid_declarator  : pointer direct_typeid_declarator
        
p_typeid_noparen_declarator_1(self, p)

   typeid_noparen_declarator  : direct_typeid_noparen_declarator
        
p_typeid_noparen_declarator_2(self, p)

   typeid_noparen_declarator  : pointer direct_typeid_noparen_declarator
        
p_unary_expression_1(self, p)

   unary_expression    : postfix_expression 
p_unary_expression_2(self, p)

   unary_expression    : PLUSPLUS unary_expression
                                  | MINUSMINUS unary_expression
                                  | unary_operator cast_expression
        
p_unary_expression_3(self, p)

   unary_expression    : SIZEOF unary_expression
                                  | SIZEOF LPAREN type_name RPAREN
        
p_unary_operator(self, p)

   unary_operator  : AND
                              | TIMES
                              | PLUS
                              | MINUS
                              | NOT
                              | LNOT
        
p_unified_string_literal(self, p)

   unified_string_literal  : STRING_LITERAL
                                      | unified_string_literal STRING_LITERAL
        
p_unified_wstring_literal(self, p)

   unified_wstring_literal : WSTRING_LITERAL
                                      | unified_wstring_literal WSTRING_LITERAL
        
parse(self, text, filename='', debuglevel=0)

   Parses C code and returns an AST.

              text:
                  A string containing the C source code

              filename:
                  Name of the file being parsed (for meaningful
                  error messages)

              debuglevel:
                  Debug level to yacc
        
precedence = (('left', 'LOR'), ('left', 'LAND'), ('left', 'OR'), ('left', 'XOR'), ('left', 'AND'), ('left', 'EQ', 'NE'), ('left', 'GT', 'GE', 'LT', 'LE'), ('left', 'RSHIFT', 'LSHIFT'), ('left', 'PLUS', 'MINUS'), ('left', 'TIMES', 'DIVIDE', 'MOD'))

Coord

 Coordinates of a syntactic element. Consists of:
            - File name
            - Line number
            - (optional) column number, for the Lexer
    
column = <member 'column' of 'Coord' objects>
file = <member 'file' of 'Coord' objects>
line = <member 'line' of 'Coord' objects>

PLYParser

ParseError

with_traceback(...)

  Exception.with_traceback(tb) --
      set self.__traceback__ to tb and return self.
args = <attribute 'args' of 'BaseException' objects>

Functions

fix_switch_cases

fix_switch_cases(switch_node)

   The 'case' statements in a 'switch' come out of parsing with one
          child node, so subsequent statements are just tucked to the parent
          Compound. Additionally, consecutive (fall-through) case statements
          come out messy. This is a peculiarity of the C grammar. The following:

              switch (myvar) {
                  case 10:
                      k = 10;
                      p = k + 1;
                      return 10;
                  case 20:
                  case 30:
                      return 20;
                  default:
                      break;
              }

          Creates this tree (pseudo-dump):

              Switch
                  ID: myvar
                  Compound:
                      Case 10:
                          k = 10
                      p = k + 1
                      return 10
                      Case 20:
                          Case 30:
                              return 20
                      Default:
                          break

          The goal of this transform is to fix this mess, turning it into the
          following:

              Switch
                  ID: myvar
                  Compound:
                      Case 10:
                          k = 10
                          p = k + 1
                          return 10
                      Case 20:
                      Case 30:
                          return 20
                      Default:
                          break

          A fixed AST node is returned. The argument may be modified.
    

parameterized

parameterized(*params)

   Decorator to create parameterized rules.

      Parameterized rule methods must be named starting with 'p_' and contain
      'xxx', and their docstrings may contain 'xxx' and 'yyy'. These will be
      replaced by the given parameter tuples. For example, ``p_xxx_rule()`` with
      docstring 'xxx_rule  : yyy' when decorated with
      ``@parameterized(('id', 'ID'))`` produces ``p_id_rule()`` with the docstring
      'id_rule  : ID'. Using multiple tuples produces multiple rules.
    

template

template(cls)

   Class decorator to generate rules from parameterized rule templates.

      See `parameterized` for more information on parameterized rules.
    

Modules

c_ast

re

yacc