python2igcse
Version:
Convert Python code to IGCSE Pseudocode format
100 lines • 3.24 kB
TypeScript
import { IGCSEDataType } from './igcse';
/**
* Basic interface for Intermediate Representation (IR)
* 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;
}
/**
* Types of IR nodes
*/
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';
/**
* Detailed argument information (distinguishes string literals from variables)
*/
export interface IRArgument {
/** Argument value */
value: string;
/** Argument type */
type: 'literal' | 'variable' | 'expression';
/** Data type */
dataType?: IGCSEDataType;
}
/**
* Metadata for IR nodes
*/
export interface IRMeta {
/** Name (variable name, function name, etc.) */
name?: string;
/** Parameter list */
params?: string[];
/** Whether has return value (for FUNCTION determination) */
hasReturn?: boolean;
/** Line number of original Python code */
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 is a string literal */
isStringLiteral?: boolean;
/** Whether has inline comment */
hasInlineComment?: boolean;
/** Detailed argument information (distinguishes type and value) */
arguments?: IRArgument[];
/** Array element type */
elementType?: string;
/** Array elements */
elements?: any[];
/** Whether input function has prompt */
hasPrompt?: boolean;
/** Prompt string for input function */
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 the depth of IR tree
*/
export declare function getIRDepth(ir: IR): number;
/**
* Calculate the 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