Parses an alias statement.
Remaining tokens to parse.
A tuple containing the AliasStatement and the number of tokens consumed.
Parses an array statement.
Tokens to parse.
An ArrayDeclaration node and the number of tokens consumed.
Parses an assignment statement.
Remaining tokens to parse.
The parsed AssignmentStatement AstNode and the number of consumed tokens.
Parses a barrier statement.
Tokens to parse.
An QuantumBarrier node and the number of tokens consumed.
Parses a binary expression.
Remaining tokens to parse.
A tuple containing the parsed Expression and the number of tokens consumed.
Parses a box statement.
Tokens to parse.
An BoxDefinition node and the number of tokens consumed.
Parses a classical type declaration.
Remaining tokens to parse.
Optional
isConst: booleanWhether the declaration is for a constant, defaults to False.
The parsed ClassicalDeclaration AstNode and the number of consumed tokens.
Creates a classical type.
The token that represents the type.
Optional
width: number | ExpressionThe type's width or size, if applicable.
The created ClassicalType.
Creates a math or trigonometric function node.
The token representing the function.
The expression to which the function is applied.
The created MathFunction or TrigFunction node and the number of consumed tokens.
Parses a defcalgrammar
declaration.
calibrationGrammarStatement: DEFCALGRAMMAR StringLiteral SEMICOLON
Remaining tokens to parse.
The parsed CalibrationGrammarDeclaration AstNode node and the number of consumed tokens.
Parses a delay statement.
Tokens to parse.
A QuantumDelay node and the number of tokens consumed.
Parses a durationof function call.
Tokens to parse.
A DurationOf node and the number of tokens consumed.
Parses an extern signature.
Remaining tokens to parse.
A tuple containing the ExternSignature and the number of tokens consumed.
Parses a for loop.
Tokens to parse.
A ForLoopStatement node and the number of tokens consumed.
Parses a branching condition (if) statement.
Tokens to parse.
A BranchingStatement node representing the if statement and the number of tokens consumed.
Parses an IO declaration statement.
Remaining tokens to parse.
A tuple containing the parsed IODeclaration and the number of tokens consumed.
Parses a measure statement.
Remaining tokens to parse.
A tuple containing the QuantumMeasurementAssignment or QuantumMeasurement and the number of tokens consumed.
Parses the token stream and generates an abstract syntax tree.
The abstract syntax tree.
Parses an array access.
Tokens to parse.
An ArrayAccess node and the number of tokens consumed.
Parses an array initializer.
Tokens to parse.
An ArrayInitializer node and the number of tokens consumed.
Parses an array reference.
Remaining tokens to parse.
A tuple containing the ArrayReference and the number of tokens consumed.
Parses a case statement.
Tokens to parse.
A CaseStatement node and the number of tokens consumed.
Parses a classical type.
The ClassicalType and the number of consumed tokens.
Parses a default statement.
Tokens to parse.
A DefaultStatement node and the number of tokens consumed.
Parses a hardware qubit.
Remaining tokens to parse.
A tuple containing the HardwareQubit and the number of tokens consumed.
Parses a single statement or declaration by delegating the parsing of the next set of tokens to the appropriate method.
Remaining tokens to parse.
Whether encountered identifiers should be consider variable initializations or references.
A set of AST nodes and the number of consumed tokens.
Parses a set of parameters.
Remaining tokens to parse.
A tuple containing the Parameters and the number of tokens consumed.
Parses a gate modifier.
Remaining tokens to parse.
A tuple containing the gate modifier and the number of tokens consumed.
Parses a list of qubits.
Remaining tokens to parse.
A tuple containing the list of qubits and the number of tokens consumed.
Parses a set declaration.
The resulting Identifier, IndexSet, or Range node and the number of consumed tokens.
Parses a subscript expression as a Range.
Remaining tokens to parse.
A tuple containing the parsed Expression or Range and the number of tokens consumed.
Parses a type cast expression.
Remaining tokens to parse.
A tuple containing the parsed Cast Expression and the number of tokens consumed.
Parses a program block.
Tokens to parse.
A ProgramBlock node and the number of tokens consumed.
Parses a quantum declaration.
Tokens to parse.
A QuantumDeclaration node and the number of tokens consumed.
Parses a quantum gate call.
Remaining tokens to parse.
A tuple containing the QuantumGateCall and the number of tokens consumed.
Parses a quantum gate definition.
Remaining tokens to parse.
A tuple containing the QuantumGateDefinition and the number of tokens consumed.
Parses a quantum reset.
Remaining tokens to parse.
A tuple containing the QuantumReset and the number of tokens consumed.
Parses a subroutine return statement.
Remaining tokens to parse.
A tuple containing the SubroutineDefinition and the number of tokens consumed.
Loads the standard library gates.
Parses a subroutine call.
Remaining tokens to parse.
A tuple containing the SubroutineCall and the number of tokens consumed.
Parses a subroutine definition.
Remaining tokens to parse.
A tuple containing the SubroutineDefinition and the number of tokens consumed.
Parses a switch statement.
Tokens to parse.
A SwitchStatement node and the number of tokens consumed.
Parses a unary expression.
Remaining tokens to parse.
A tuple containing the parsed Expression and the number of tokens consumed.
Parses a while loop.
Tokens to parse.
A ForLoopStatement node and the number of tokens consumed.
User defined aliases.
User defined arrays.
Custom defined gates.
The built in gates.
Index of the current token.
The default machine precision float width.
The default machine int size.
Standard library gates.
Custom defined subroutines.
The tokens to parse.
OpenQASM 3.0 Recursive Descent Parser
Implements a comprehensive parser for the OpenQASM 3.0 language specification. The parser uses recursive descent parsing with appropriate error recovery and maintains symbol tables for gates, subroutines, and variables.
Parser state includes:
Example: Creating and using the parser