/** * Main parser interface for generating AST from tokens * * The parser is responsible for transforming a stream of tokens into an Abstract * Syntax Tree (AST) that represents the structure of the OpenQASM program. It acts * as a dispatcher, selecting the appropriate version-specific parser based on the * OpenQASM version being used. * * The parsing process follows these steps: * 1. Receive tokenized input from the lexer * 2. Determine OpenQASM version (2.0 or 3.0) * 3. Select appropriate parser implementation * 4. Generate version-specific AST nodes * * The specific Parser implementations can be found at: * - {@link Qasm3Parser} * - {@link Qasm2Parser} * * @module Parsing * * @example Basic parsing workflow * ```typescript * import { lex } from './lexer'; * import { parse } from './parser'; * * const qasmCode = 'OPENQASM 3.0; h q[0];'; * const tokens = lex(qasmCode, undefined, 3); * const ast = parse(tokens, 3); * console.log(ast); // Array of AST nodes * ``` * * @example Version-specific parsing * ```typescript * // Parse as OpenQASM 2.0 * const ast2 = parse(tokens, 2); * * // Parse as OpenQASM 3.0 * const ast3 = parse(tokens, 3); * * // Use OpenQASMVersion object * const version = new OpenQASMVersion(3, 0); * const ast = parse(tokens, version); * ``` */ import { Token as Qasm2Token } from "./qasm2/token"; import { Token as Qasm3Token } from "./qasm3/token"; import { OpenQASMVersion, OpenQASMMajorVersion } from "./version"; /** * Parses an array of tokens into an Abstract Syntax Tree (AST). * * This is the main entry point for parsing tokenized OpenQASM code. It automatically * selects the appropriate parser implementation based on the specified version and * returns an AST that can be used for further analysis, compilation, or execution. * * @group Parsing * @param tokens - Array of tokens generated by the lexer * @param version - OpenQASM version to use for parsing (defaults to 3.0) * @returns Abstract Syntax Tree representing the parsed program * @throws {UnsupportedOpenQASMVersionError} When an unsupported version is specified * * @example Parse OpenQASM 3.0 tokens * ```typescript * const tokens = lex('OPENQASM 3.0; qubit q; h q;'); * const ast = parse(tokens, 3); * // Returns array of OpenQASM 3.0 AST nodes * ``` * * @example Parse OpenQASM 2.0 tokens * ```typescript * const tokens = lex('OPENQASM 2.0; qreg q[1]; h q[0];'); * const ast = parse(tokens, 2); * // Returns array of OpenQASM 2.0 AST nodes * ``` */ export declare function parse(tokens: Array<[Qasm2Token | Qasm3Token, (number | string)?]>, version?: OpenQASMVersion | OpenQASMMajorVersion | number): import("./qasm2/ast").AstNode[];