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

    Function parse

    • 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.

      Parameters

      • tokens: [Token | Token, (string | number)?][]

        Array of tokens generated by the lexer

      • Optionalversion: number | OpenQASMVersion

        OpenQASM version to use for parsing (defaults to 3.0)

      Returns AstNode[]

      Abstract Syntax Tree representing the parsed program

      When an unsupported version is specified

      const tokens = lex('OPENQASM 3.0; qubit q; h q;');
      const ast = parse(tokens, 3);
      // Returns array of OpenQASM 3.0 AST nodes
      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