UNPKG

python2igcse

Version:

Convert Python code to IGCSE Pseudocode format

100 lines 3.19 kB
import { IGCSEDataType } from './igcse'; /** * Intermediate Representation (IR) basic interface * Represents nested code blocks with recursive structure */ export interface IR { /** Type of IR node */ kind: IRKind; /** Output text */ text: string; /** Child IR nodes (for nested structure) */ children: IR[]; /** Additional metadata */ meta?: IRMeta; } /** * IR node types */ export type IRKind = 'program' | 'assign' | 'element_assign' | 'attribute_assign' | 'output' | 'input' | 'comment' | 'if' | 'else' | 'elseif' | 'endif' | 'for' | 'while' | 'endwhile' | 'repeat' | 'until' | 'break' | 'procedure' | 'function' | 'return' | 'array' | 'array_literal' | 'type' | 'class' | 'block' | 'case' | 'statement' | 'expression' | 'compound' | 'module'; /** * Argument details (distinguishing string literals from variables) */ export interface IRArgument { /** Argument value */ value: string; /** Argument type */ type: 'literal' | 'variable' | 'expression'; /** Data type */ dataType?: IGCSEDataType; } /** * IR node metadata */ export interface IRMeta { /** Name (variable name, function name, etc.) */ name?: string; /** Parameter list */ params?: string[]; /** Whether it has a return value (for FUNCTION determination) */ hasReturn?: boolean; /** Original Python code line number */ lineNumber?: number; /** Data type */ dataType?: IGCSEDataType; /** Start value (for FOR statement) */ startValue?: string; /** End value (for FOR statement) */ endValue?: string; /** Step value (for FOR statement) */ stepValue?: string; /** Condition expression */ condition?: string; /** THEN side statements (for IF statement) */ consequent?: IR[]; /** ELSE side statements (for IF statement) */ alternate?: IR[]; /** Base class name (for class inheritance) */ baseClass?: string; /** Return type */ returnType?: IGCSEDataType; /** Array size */ size?: number; /** Array index */ index?: number | string; /** Whether it's a string literal */ isStringLiteral?: boolean; /** Whether it has inline comment */ hasInlineComment?: boolean; /** Argument details (distinguishing type and value) */ arguments?: IRArgument[]; /** Array element type */ elementType?: string; /** Array elements */ elements?: any[]; /** Whether input function has prompt */ hasPrompt?: boolean; /** Input function prompt string */ prompt?: string; /** End text (ENDPROCEDURE, ENDFUNCTION, etc.) */ endText?: string; /** Variable name (loop variable for FOR statement, etc.) */ variable?: string; } /** * Helper function for creating IR nodes */ export declare function createIR(kind: IRKind, text: string, children?: IR[], meta?: IRMeta): IR; /** * Calculate IR tree depth */ export declare function getIRDepth(ir: IR): number; /** * Calculate number of nodes in IR tree */ export declare function countIRNodes(ir: IR): number; /** * Search for IR nodes of specific type */ export declare function findIRNodes(ir: IR, kind: IRKind): IR[]; //# sourceMappingURL=ir.d.ts.map