qasm-ts - v2.0.0
    Preparing search index...

    Module Parsing

    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:

    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
    // 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);

    Parsing

    parse