def p_parameter_declaration(p): """ parameter-declaration : decl-specifier-seq declarator | decl-specifier-seq abstract-declarator | decl-specifier-seq | decl-specifier-seq ASSIGNMENT initializer-clause """ row = p[1].row col = p[1].col if len(p) == 2: p[0] = risha_ast.SimpleDeclaration(specifiers=p[1], declarators=None, row=row, col=col, need_a_semicolon=False) elif len(p) == 3: p[0] = risha_ast.SimpleDeclaration(specifiers=p[1], declarators=p[2], row=row, col=col, need_a_semicolon=False) elif len(p) == 4: p[0] = risha_ast.SimpleDeclaration( specifiers=p[1], declarators=risha_ast.EqualInitializer(initializer_clause=p[3], row=p.lineno(2), col=p.lexpos(2)), row=row, col=col, need_a_semicolon=False)
def p_member_declaration_declarators(p): """ member-declaration : member-declarator-list SEMICOLON | decl-specifier-seq member-declarator-list SEMICOLON """ if len(p) == 3: p[0] = risha_ast.SimpleDeclaration(None, p[1], row=p[1].row, col=p[1].col) else: p[0] = risha_ast.SimpleDeclaration(p[1], p[2], row=p[1].row, col=p[1].col)
def p_for_range_declaration(p): """ for-range-declaration : decl-specifier-seq declarator """ p[0] = risha_ast.SimpleDeclaration(specifiers=p[1], declarators=p[2], row=p[1].row, col=p[1].col, need_a_semicolon=False)
def p_simple_declaration_with_specifiers(p): """ simple-declaration : decl-specifier-seq init-declarator-list SEMICOLON | decl-specifier-seq SEMICOLON """ specifiers = p[1] declarators = p[2] if len(p) == 4 else None p[0] = risha_ast.SimpleDeclaration(specifiers=specifiers, declarators=declarators, row=p[1].row, col=p[1].col)
def p_type_id(p): """ type-id : type-specifier-seq | type-specifier-seq abstract-declarator """ specifiers = p[1] declarators = p[2] if len(p) == 3 else None p[0] = risha_ast.SimpleDeclaration(specifiers=specifiers, declarators=declarators, row=p[1].row, col=p[1].col, need_a_semicolon=False)
def p_simple_declaration(p): """ simple-declaration : init-declarator-list SEMICOLON | SEMICOLON """ specifiers = None declarators = p[1] if len(p) == 3 else None row = p.lineno(1) if len(p) == 2 else p[1].row col = p.lexpos(1) if len(p) == 2 else p[1].col p[0] = risha_ast.SimpleDeclaration(specifiers=specifiers, declarators=declarators, row=row, col=col)
def p_parameter_declaration_with_initializer(p): """ parameter-declaration : decl-specifier-seq declarator ASSIGNMENT initializer-clause | decl-specifier-seq abstract-declarator ASSIGNMENT initializer-clause """ declarator = risha_ast.InitDeclarator( declarator=p[2], initializer=risha_ast.EqualInitializer(initializer_clause=p[4], row=p.lineno(3), col=p.lexpos(3)), row=p[1].row, col=p[1].col) p[0] = risha_ast.SimpleDeclaration(specifiers=p[1], declarators=declarator, row=p[1].row, col=p[1].col, need_a_semicolon=False)
def p_condition(p): """ condition : expression | decl-specifier-seq declarator brace-or-equal-initializer """ if len(p) == 2: p[0] = p[1] else: simple_decl = risha_ast.SimpleDeclaration(specifiers=p[1], declarators=p[2], row=p[1].row, col=p[1].col, need_a_semicolon=False) p[0] = risha_ast.ConditionWithDeclaration( declarator_with_specifiers=simple_decl, initializer=p[3], row=p[1].row, col=p[1].col)
def p_member_declaration_declarators_specifiers(p): """ member-declaration : decl-specifier-seq SEMICOLON """ p[0] = risha_ast.SimpleDeclaration(p[1], None, row=p[1].row, col=p[1].col)