UNPKG

python2igcse

Version:

Convert Python code to IGCSE Pseudocode format

212 lines 5.22 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 assignment */ 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 type-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; /** * Try to convert while True + break pattern to REPEAT-UNTIL */ private tryConvertToRepeatUntil; /** * Check if specified statement type exists in body */ private hasStatementType; /** * Get array size */ private getArraySize; /** * Set array size */ private setArraySize; /** * 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 statement */ visitRaise(_node: ASTNode): IR; /** * Process WITH statement */ visitWith(_node: ASTNode): IR; /** * Process ASSERT statement */ visitAssert(_node: ASTNode): IR; /** * Process GLOBAL statement */ visitGlobal(_node: ASTNode): IR; /** * Process MATCH statement (Python 3.10+) */ visitMatch(node: ASTNode): IR; /** * Process DELETE statement */ visitDelete(_node: ASTNode): IR; private handleRangeFor; /** * Check if it's array multiplication initialization ([0] * 5, etc.) */ private isArrayMultiplication; /** * Process array multiplication initialization ([0] * 5, etc.) */ private handleArrayMultiplication; 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; /** * Check if type annotation is a 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 the first letter of a string */ private capitalizeFirstLetter; /** * Check if IF-ELIF-ELSE statement can be converted to CASE statement, and convert if possible */ private tryConvertToCase; /** * Check if IF-ELIF-ELSE statement can be converted to CASE statement */ private canConvertToCase; /** * Extract variable used in CASE statement */ private extractCaseVariable; /** * Process each condition in CASE statement */ private processCaseConditions; protected createIRNode(kind: IRKind, text: string, children?: IR[], meta?: IRMeta): IR; } export {}; //# sourceMappingURL=statement-visitor.d.ts.map