UNPKG

python2igcse

Version:

Convert Python code to IGCSE Pseudocode format

177 lines 4.37 kB
import { IR, IRKind, IRMeta } from '../types/ir'; import { BaseParser } from './base-parser'; import { ParseResult } from '../types/parser'; /** * Basic interface for Python AST nodes */ interface ASTNode { type: string; lineno?: number; col_offset?: number; [key: string]: any; } /** * Visitor class responsible for processing statements */ export declare class StatementVisitor extends BaseParser { /** * Execute parsing (not used in StatementVisitor) */ parse(_source: string): ParseResult; private expressionVisitor; visitNode: ((node: ASTNode) => IR) | undefined; constructor(); /** * Set context */ setContext(context: any): void; /** * Process assignment statements */ visitAssign(node: ASTNode): IR; /** * Process input() function assignments */ private handleInputAssignment; /** * Find input() from nested function calls */ private findInputCall; /** * Check if node contains input() call */ private containsInputCall; /** * Process augmented assignment statements */ visitAugAssign(node: ASTNode): IR; /** * Process annotated assignment statements (items: list[str] = []) */ visitAnnAssign(node: ASTNode): IR; /** * Process IF statements */ visitIf(node: ASTNode): IR; /** * Process FOR statements */ visitFor(node: ASTNode): IR; /** * Process WHILE statements */ visitWhile(node: ASTNode): IR; /** * Check if a while loop matches the REPEAT-UNTIL pattern * Pattern: while True with a conditional break at the end */ private isRepeatUntilPattern; /** * Create a REPEAT-UNTIL IR from a while True loop with conditional break */ private createRepeatUntilIR; /** * Process function call statements */ visitCall(node: ASTNode): IR; /** * Process RETURN statements */ visitReturn(node: ASTNode): IR; /** * Process expression statements */ visitExpr(node: ASTNode): IR; /** * Process comments */ visitComment(node: ASTNode): IR; /** * Process PASS statements */ visitPass(_node: ASTNode): IR; /** * Process BREAK statements */ visitBreak(_node: ASTNode): IR; /** * Process CONTINUE statements */ visitContinue(_node: ASTNode): IR; /** * Process IMPORT statements */ visitImport(_node: ASTNode): IR; /** * Process TRY statements */ visitTry(_node: ASTNode): IR; /** * Process RAISE statements */ visitRaise(_node: ASTNode): IR; /** * Process WITH statements */ visitWith(_node: ASTNode): IR; /** * Process ASSERT statements */ visitAssert(_node: ASTNode): IR; /** * Process GLOBAL statements */ visitGlobal(_node: ASTNode): IR; /** * Process DELETE statements */ visitDelete(_node: ASTNode): IR; private handleRangeFor; private handleArrayInitialization; private reconstructObjectCalls; private isObjectCall; private extractClassName; private extractArguments; private isClassInstantiation; private handleClassInstantiation; private convertOperator; /** * Process array element assignment (data[1] = 100) */ private handleElementAssign; /** * Process attribute assignment (obj.field = value) */ private handleAttributeAssign; /** * Convert index from 0-based to 1-based */ private convertIndexToOneBased; /** * Determine if type annotation is list type */ private isListTypeAnnotation; /** * Extract element type from list type annotation */ private extractListElementType; /** * Convert type annotation to IGCSE type */ private convertAnnotationToIGCSEType; /** * Convert Python type name to IGCSE type */ private convertPythonTypeToIGCSE; /** * Get attribute names from class definition */ private getClassAttributes; /** * Capitalize first letter of string */ private capitalizeFirstLetter; protected createIRNode(kind: IRKind, text: string, children?: IR[], meta?: IRMeta): IR; } export {}; //# sourceMappingURL=statement-visitor.d.ts.map