UNPKG

python2igcse

Version:

Convert Python code to IGCSE Pseudocode format

135 lines 3.35 kB
import { IR, IRKind, IRMeta } from '../types/ir'; import { IGCSEDataType } from '../types/igcse'; import { BaseParser } from './base-parser'; /** * Basic interface for Python AST nodes */ interface ASTNode { type: string; lineno?: number; col_offset?: number; inlineComment?: string; [key: string]: any; } /** * Visitor for converting Python AST to IR */ export declare class PythonASTVisitor extends BaseParser { private statementVisitor; private definitionVisitor; constructor(); /** * Main parse function */ parse(source: string): import('../types/parser').ParseResult; /** * First pass: collect function call information */ private collectFunctionCalls; /** * Infer type from value */ private inferTypeFromValue; /** * Record function call */ recordFunctionCall(functionName: string, argumentTypes: IGCSEDataType[]): void; /** * Simple AST parser (in actual implementation, use external library) */ private parseToAST; /** * Parse statement and its child blocks */ private parseStatement; /** * Convert single line to AST node */ private parseLineToASTNode; /** * Parse augmented assignment statements */ private parseAugAssignStatement; /** * Get augmented assignment operator type */ private getAugAssignOpType; private parseIfStatement; /** * Parse condition expression */ private parseCondition; /** * Convert comparison operator string to AST type */ private getComparisonOpType; private parseForStatement; private parseWhileStatement; private parseMatchStatement; private parseCaseStatement; private parseAssignStatement; /** * Parse expression and convert to AST node */ private parseExpression; /** * Parse simple expressions (variables, literals) */ private parseSimpleExpression; /** * Get AST node for comparison operators */ private getCompareOpNode; /** * Get AST node for arithmetic operators */ private getArithOpNode; private parsePrintStatement; /** * Convert AST node to IR */ visitNode(node: ASTNode): IR; private visitModule; /** * Parse function definition */ private parseFunctionDef; /** * Parse argument list */ private parseArguments; /** * Split arguments considering parentheses balance */ private splitArgumentsRespectingParentheses; /** * Parse parameter list */ private parseParameters; /** * Parse return statement */ private parseReturnStatement; /** * Parse class definition */ private parseClassDef; /** * Register class definition to context */ private registerClassDefinition; /** * Pre-register all class definitions (first pass of two-pass processing) */ private preRegisterAllClasses; /** * Helper for creating IR nodes */ protected createIRNode(kind: IRKind, text: string, children?: IR[], meta?: IRMeta): IR; /** * Create parse result */ protected createParseResult(ir: IR[]): import('../types/parser').ParseResult; } export {}; //# sourceMappingURL=visitor.d.ts.map