qasm-ts 1.1.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +13 -0
- package/.github/workflows/draft-pdf.yml +24 -0
- package/CONTRIBUTING.md +3 -0
- package/LICENSE +201 -0
- package/dist/errors.js +128 -2
- package/dist/lexer.js +110 -291
- package/dist/main.js +123 -18
- package/dist/parser.js +117 -482
- package/dist/{ast.js → qasm2/ast.js} +71 -2
- package/dist/qasm2/lexer.js +489 -0
- package/dist/qasm2/parser.js +659 -0
- package/dist/qasm2/token.js +160 -0
- package/dist/qasm3/ast.js +1081 -0
- package/dist/qasm3/lexer.js +673 -0
- package/dist/qasm3/parser.js +2083 -0
- package/dist/qasm3/token.js +425 -0
- package/dist/version.js +57 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/custom.css +3 -0
- package/docs/docs-readme.md +208 -0
- package/docs/index.html +17 -0
- package/docs/typedoc/.nojekyll +1 -0
- package/docs/typedoc/assets/custom.css +3 -0
- package/docs/typedoc/assets/hierarchy.js +1 -0
- package/docs/typedoc/assets/highlight.css +99 -0
- package/docs/typedoc/assets/icons.js +18 -0
- package/docs/typedoc/assets/icons.svg +1 -0
- package/docs/typedoc/assets/main.js +60 -0
- package/docs/typedoc/assets/navigation.js +1 -0
- package/docs/typedoc/assets/search.js +1 -0
- package/docs/typedoc/assets/style.css +1633 -0
- package/docs/typedoc/classes/Error_Handling.BadArgumentError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadBarrierError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadClassicalTypeError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadConditionalError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadCregError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadEqualsError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadExpressionError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadGateError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadIncludeError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadLoopError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadMeasurementError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadParameterError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadQregError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadQuantumInstructionError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadStringLiteralError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.BadSubroutineError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.MissingBraceError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.MissingSemicolonError.html +12 -0
- package/docs/typedoc/classes/Error_Handling.UnsupportedOpenQASMVersionError.html +12 -0
- package/docs/typedoc/classes/Version_Management.OpenQASMVersion.html +16 -0
- package/docs/typedoc/classes/qasm2_ast.ApplyGate.html +6 -0
- package/docs/typedoc/classes/qasm2_ast.AstNode.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Barrier.html +5 -0
- package/docs/typedoc/classes/qasm2_ast.CReg.html +5 -0
- package/docs/typedoc/classes/qasm2_ast.Cos.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Divide.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Exp.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Gate.html +7 -0
- package/docs/typedoc/classes/qasm2_ast.Id.html +4 -0
- package/docs/typedoc/classes/qasm2_ast.If.html +6 -0
- package/docs/typedoc/classes/qasm2_ast.Include.html +4 -0
- package/docs/typedoc/classes/qasm2_ast.Ln.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Measure.html +7 -0
- package/docs/typedoc/classes/qasm2_ast.Minus.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.NNInteger.html +4 -0
- package/docs/typedoc/classes/qasm2_ast.Opaque.html +6 -0
- package/docs/typedoc/classes/qasm2_ast.Pi.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Plus.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Power.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.QReg.html +5 -0
- package/docs/typedoc/classes/qasm2_ast.Real.html +4 -0
- package/docs/typedoc/classes/qasm2_ast.Sin.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Sqrt.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Tan.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Times.html +3 -0
- package/docs/typedoc/classes/qasm2_ast.Variable.html +4 -0
- package/docs/typedoc/classes/qasm2_ast.Version.html +4 -0
- package/docs/typedoc/classes/qasm2_lexer.default.html +57 -0
- package/docs/typedoc/classes/qasm2_parser.default.html +93 -0
- package/docs/typedoc/classes/qasm3_ast.AliasStatement.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.AngleType.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.Arithmetic.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.ArrayAccess.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.ArrayDeclaration.html +7 -0
- package/docs/typedoc/classes/qasm3_ast.ArrayInitializer.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.ArrayReference.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.AssignmentStatement.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.AstNode.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.Binary.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.BitType.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.BitstringLiteral.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.BoolType.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.BooleanLiteral.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.BoxDefinition.html +7 -0
- package/docs/typedoc/classes/qasm3_ast.BranchingStatement.html +8 -0
- package/docs/typedoc/classes/qasm3_ast.BreakStatement.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.CalibrationGrammarDeclaration.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.CaseStatement.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.Cast.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.ClassicalDeclaration.html +7 -0
- package/docs/typedoc/classes/qasm3_ast.ClassicalType.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.ComplexType.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.ContinueStatement.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.DefaultStatement.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.DurationLiteral.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.DurationOf.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.DurationType.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.Euler.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.Expression.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.ExternSignature.html +8 -0
- package/docs/typedoc/classes/qasm3_ast.FloatLiteral.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.FloatType.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.ForLoopStatement.html +12 -0
- package/docs/typedoc/classes/qasm3_ast.HardwareQubit.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.IODeclaration.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.Identifier.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.ImaginaryLiteral.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.Include.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.IndexSet.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.IntType.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.IntegerLiteral.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.MathFunction.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.NumericLiteral.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.Parameters.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.Pi.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.ProgramBlock.html +7 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumBarrier.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumBlock.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumDeclaration.html +8 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumDelay.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumGateCall.html +9 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumGateDefinition.html +9 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumGateModifier.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumMeasurement.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumMeasurementAssignment.html +8 -0
- package/docs/typedoc/classes/qasm3_ast.QuantumReset.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.Range.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.ReturnStatement.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.SizeOf.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.Statement.html +12 -0
- package/docs/typedoc/classes/qasm3_ast.StretchType.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.SubroutineBlock.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.SubroutineCall.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.SubroutineDefinition.html +10 -0
- package/docs/typedoc/classes/qasm3_ast.SubscriptedIdentifier.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.SwitchStatement.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.Tau.html +3 -0
- package/docs/typedoc/classes/qasm3_ast.TrigFunction.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.UIntType.html +4 -0
- package/docs/typedoc/classes/qasm3_ast.Unary.html +5 -0
- package/docs/typedoc/classes/qasm3_ast.Version.html +6 -0
- package/docs/typedoc/classes/qasm3_ast.WhileLoopStatement.html +6 -0
- package/docs/typedoc/classes/qasm3_lexer.default.html +71 -0
- package/docs/typedoc/classes/qasm3_parser.default.html +237 -0
- package/docs/typedoc/enums/Version_Management.OpenQASMMajorVersion.html +4 -0
- package/docs/typedoc/enums/qasm2_token.Token.html +42 -0
- package/docs/typedoc/enums/qasm3_ast.ArithmeticOp.html +9 -0
- package/docs/typedoc/enums/qasm3_ast.ArrayReferenceModifier.html +4 -0
- package/docs/typedoc/enums/qasm3_ast.BinaryOp.html +15 -0
- package/docs/typedoc/enums/qasm3_ast.DurationUnit.html +7 -0
- package/docs/typedoc/enums/qasm3_ast.IOModifier.html +4 -0
- package/docs/typedoc/enums/qasm3_ast.MathFunctionTypes.html +12 -0
- package/docs/typedoc/enums/qasm3_ast.QuantumGateModifierName.html +6 -0
- package/docs/typedoc/enums/qasm3_ast.TrigFunctionTypes.html +8 -0
- package/docs/typedoc/enums/qasm3_ast.UnaryOp.html +5 -0
- package/docs/typedoc/enums/qasm3_token.Token.html +113 -0
- package/docs/typedoc/functions/Lexing.lex.html +24 -0
- package/docs/typedoc/functions/Main_Functions.parseFile.html +13 -0
- package/docs/typedoc/functions/Main_Functions.parseString.html +19 -0
- package/docs/typedoc/functions/Parsing.parse.html +15 -0
- package/docs/typedoc/functions/qasm2_token.inverseLookup.html +3 -0
- package/docs/typedoc/functions/qasm2_token.lookup.html +4 -0
- package/docs/typedoc/functions/qasm2_token.notParam.html +3 -0
- package/docs/typedoc/functions/qasm3_token.inverseLookup.html +9 -0
- package/docs/typedoc/functions/qasm3_token.lookup.html +10 -0
- package/docs/typedoc/functions/qasm3_token.notParam.html +11 -0
- package/docs/typedoc/hierarchy.html +1 -0
- package/docs/typedoc/index.html +76 -0
- package/docs/typedoc/modules/Error_Handling.html +5 -0
- package/docs/typedoc/modules/Lexing.html +20 -0
- package/docs/typedoc/modules/Main_Functions.html +2 -0
- package/docs/typedoc/modules/Parsing.html +24 -0
- package/docs/typedoc/modules/Version_Management.html +8 -0
- package/docs/typedoc/modules/qasm2_ast.html +22 -0
- package/docs/typedoc/modules/qasm2_lexer.html +24 -0
- package/docs/typedoc/modules/qasm2_parser.html +21 -0
- package/docs/typedoc/modules/qasm2_token.html +15 -0
- package/docs/typedoc/modules/qasm3_ast.html +26 -0
- package/docs/typedoc/modules/qasm3_lexer.html +25 -0
- package/docs/typedoc/modules/qasm3_parser.html +25 -0
- package/docs/typedoc/modules/qasm3_token.html +15 -0
- package/docs/typedoc/modules.html +1 -0
- package/docs/typedoc/types/Error_Handling.ReturnErrorConstructor.html +2 -0
- package/docs/typedoc.json +47 -0
- package/package.json +10 -5
- package/paper/jats/paper.jats +464 -0
- package/paper/main.bib +191 -0
- package/paper/paper.md +166 -0
- package/paper/paper.pdf +0 -0
- package/readme.md +117 -47
- package/dist/example.js +0 -22
- package/dist/token.js +0 -89
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenQASM 3.0 Token Definitions and Utilities
|
|
4
|
+
*
|
|
5
|
+
* This module defines all the token types used in OpenQASM 3.0 syntax, which
|
|
6
|
+
* significantly extends OpenQASM 2.0 with modern programming language features.
|
|
7
|
+
*
|
|
8
|
+
* Major additions in OpenQASM 3.0:
|
|
9
|
+
* - **Classical types**: int, uint, float, bool, bit, complex
|
|
10
|
+
* - **Control flow**: if/else, for/while loops, switch/case
|
|
11
|
+
* - **Functions**: def, return, extern declarations
|
|
12
|
+
* - **Advanced features**: arrays, timing (delay, durationof), calibration
|
|
13
|
+
* - **Quantum extensions**: qubit declarations, gate modifiers, hardware qubits
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*
|
|
17
|
+
* @example OpenQASM 3.0 advanced tokens
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { lookup, Token } from './qasm3/token';
|
|
20
|
+
*
|
|
21
|
+
* console.log(lookup('qubit')); // Token.Qubit
|
|
22
|
+
* console.log(lookup('if')); // Token.If
|
|
23
|
+
* console.log(lookup('def')); // Token.Def
|
|
24
|
+
* console.log(lookup('complex')); // Token.Complex
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.Token = void 0;
|
|
29
|
+
exports.notParam = notParam;
|
|
30
|
+
exports.lookup = lookup;
|
|
31
|
+
exports.inverseLookup = inverseLookup;
|
|
32
|
+
/**
|
|
33
|
+
* Enumeration of all OpenQASM 3.0 token types.
|
|
34
|
+
*
|
|
35
|
+
* Each token represents a specific syntactic element in OpenQASM 3.0 code.
|
|
36
|
+
* The enum values correspond to different categories:
|
|
37
|
+
* - Literals: NNInteger, Real, String, BoolLiteral
|
|
38
|
+
* - Identifiers: Id
|
|
39
|
+
* - Keywords: Qubit, Gate, Measure, If, For, While, etc.
|
|
40
|
+
* - Operators: ArithmeticOp, BinaryOp, UnaryOp
|
|
41
|
+
* - Punctuation: Semicolon, Comma, LParen, RParen, etc.
|
|
42
|
+
* - Special: OpenQASM, Include, EndOfFile, Illegal
|
|
43
|
+
*/
|
|
44
|
+
var Token;
|
|
45
|
+
(function (Token) {
|
|
46
|
+
// 0; invalid or unrecognized token
|
|
47
|
+
Token[Token["Illegal"] = 0] = "Illegal";
|
|
48
|
+
// 1; end of file character
|
|
49
|
+
Token[Token["EndOfFile"] = 1] = "EndOfFile";
|
|
50
|
+
// 2; real number (floating point)
|
|
51
|
+
Token[Token["Real"] = 2] = "Real";
|
|
52
|
+
// 3; non-negative integer
|
|
53
|
+
Token[Token["NNInteger"] = 3] = "NNInteger";
|
|
54
|
+
// 4; integer that supports underscores and negatives
|
|
55
|
+
Token[Token["Integer"] = 4] = "Integer";
|
|
56
|
+
// 5; identifier (variables names, function names, etc.)
|
|
57
|
+
Token[Token["Id"] = 5] = "Id";
|
|
58
|
+
// 6; OPENQASM version declaration
|
|
59
|
+
Token[Token["OpenQASM"] = 6] = "OpenQASM";
|
|
60
|
+
// 7; include statement
|
|
61
|
+
Token[Token["Include"] = 7] = "Include";
|
|
62
|
+
// 8; semicolon to terminate statements
|
|
63
|
+
Token[Token["Semicolon"] = 8] = "Semicolon";
|
|
64
|
+
// 9; colon
|
|
65
|
+
Token[Token["Colon"] = 9] = "Colon";
|
|
66
|
+
// 10; comma
|
|
67
|
+
Token[Token["Comma"] = 10] = "Comma";
|
|
68
|
+
// 11; left paren (
|
|
69
|
+
Token[Token["LParen"] = 11] = "LParen";
|
|
70
|
+
// 12; left square bracket [
|
|
71
|
+
Token[Token["LSParen"] = 12] = "LSParen";
|
|
72
|
+
// 13; left curly brakcet {
|
|
73
|
+
Token[Token["LCParen"] = 13] = "LCParen";
|
|
74
|
+
// 14; right paren )
|
|
75
|
+
Token[Token["RParen"] = 14] = "RParen";
|
|
76
|
+
// 15; right square paren ]
|
|
77
|
+
Token[Token["RSParen"] = 15] = "RSParen";
|
|
78
|
+
// 16; right curly bracket }
|
|
79
|
+
Token[Token["RCParen"] = 16] = "RCParen";
|
|
80
|
+
// 17; assignment operator (=)
|
|
81
|
+
Token[Token["EqualsAssmt"] = 17] = "EqualsAssmt";
|
|
82
|
+
// 18; arrow (->) used in measurement operations
|
|
83
|
+
Token[Token["Arrow"] = 18] = "Arrow";
|
|
84
|
+
// 19; quantum register declaration
|
|
85
|
+
Token[Token["QReg"] = 19] = "QReg";
|
|
86
|
+
// 20; quantum register declaration (functionally equivalent to QReg but for OpenQASM version 3)
|
|
87
|
+
Token[Token["Qubit"] = 20] = "Qubit";
|
|
88
|
+
// 21; classical register declaration
|
|
89
|
+
Token[Token["CReg"] = 21] = "CReg";
|
|
90
|
+
// 22; classical register declaration (functionally equivalent to Creg but for OpenQASM version 3)
|
|
91
|
+
Token[Token["Bit"] = 22] = "Bit";
|
|
92
|
+
// 23; barrier operation
|
|
93
|
+
Token[Token["Barrier"] = 23] = "Barrier";
|
|
94
|
+
// 24; gate declaration or application
|
|
95
|
+
Token[Token["Gate"] = 24] = "Gate";
|
|
96
|
+
// 25; measurement operation
|
|
97
|
+
Token[Token["Measure"] = 25] = "Measure";
|
|
98
|
+
// 26; qubit reset operation
|
|
99
|
+
Token[Token["Reset"] = 26] = "Reset";
|
|
100
|
+
// 27; string literal
|
|
101
|
+
Token[Token["String"] = 27] = "String";
|
|
102
|
+
// 28; opaque keyword
|
|
103
|
+
Token[Token["Opaque"] = 28] = "Opaque";
|
|
104
|
+
// 29; defcalgrammar keyword
|
|
105
|
+
Token[Token["DefcalGrammar"] = 29] = "DefcalGrammar";
|
|
106
|
+
// 30; float type keyword
|
|
107
|
+
Token[Token["Float"] = 30] = "Float";
|
|
108
|
+
// 31; bool type keyword,
|
|
109
|
+
Token[Token["Bool"] = 31] = "Bool";
|
|
110
|
+
// 32; int type keyword
|
|
111
|
+
Token[Token["Int"] = 32] = "Int";
|
|
112
|
+
// 33; uint type keyword
|
|
113
|
+
Token[Token["UInt"] = 33] = "UInt";
|
|
114
|
+
// 34; mathematical constant pi
|
|
115
|
+
Token[Token["Pi"] = 34] = "Pi";
|
|
116
|
+
// 35; euler constant
|
|
117
|
+
Token[Token["Euler"] = 35] = "Euler";
|
|
118
|
+
// 36; tau constant
|
|
119
|
+
Token[Token["Tau"] = 36] = "Tau";
|
|
120
|
+
// 37; binary literal
|
|
121
|
+
Token[Token["BinaryLiteral"] = 37] = "BinaryLiteral";
|
|
122
|
+
// 38; octal literal
|
|
123
|
+
Token[Token["OctalLiteral"] = 38] = "OctalLiteral";
|
|
124
|
+
// 39; hex literal
|
|
125
|
+
Token[Token["HexLiteral"] = 39] = "HexLiteral";
|
|
126
|
+
// 40; arithmetic operators
|
|
127
|
+
Token[Token["ArithmeticOp"] = 40] = "ArithmeticOp";
|
|
128
|
+
// 41; compound arithmetic operators
|
|
129
|
+
Token[Token["CompoundArithmeticOp"] = 41] = "CompoundArithmeticOp";
|
|
130
|
+
// 42; boolean literal value
|
|
131
|
+
Token[Token["BoolLiteral"] = 42] = "BoolLiteral";
|
|
132
|
+
// 43; duration keyword
|
|
133
|
+
Token[Token["Duration"] = 43] = "Duration";
|
|
134
|
+
// 44; unary operator
|
|
135
|
+
Token[Token["UnaryOp"] = 44] = "UnaryOp";
|
|
136
|
+
// 45; binary operator
|
|
137
|
+
Token[Token["BinaryOp"] = 45] = "BinaryOp";
|
|
138
|
+
// 46; let keyword for aliasing
|
|
139
|
+
Token[Token["Let"] = 46] = "Let";
|
|
140
|
+
// 47; quantum gate modifier
|
|
141
|
+
Token[Token["QuantumModifier"] = 47] = "QuantumModifier";
|
|
142
|
+
// 48; delay keyword
|
|
143
|
+
Token[Token["Delay"] = 48] = "Delay";
|
|
144
|
+
// 49; return keyword
|
|
145
|
+
Token[Token["Return"] = 49] = "Return";
|
|
146
|
+
// 50; def keyword for subroutines
|
|
147
|
+
Token[Token["Def"] = 50] = "Def";
|
|
148
|
+
// 51; for loop keyword
|
|
149
|
+
Token[Token["For"] = 51] = "For";
|
|
150
|
+
// 52; in keyword
|
|
151
|
+
Token[Token["In"] = 52] = "In";
|
|
152
|
+
// 53; while loop keyword
|
|
153
|
+
Token[Token["While"] = 53] = "While";
|
|
154
|
+
// 54; break keyword
|
|
155
|
+
Token[Token["Break"] = 54] = "Break";
|
|
156
|
+
// 55; continue keyword
|
|
157
|
+
Token[Token["Continue"] = 55] = "Continue";
|
|
158
|
+
// 56; input keyword
|
|
159
|
+
Token[Token["Input"] = 56] = "Input";
|
|
160
|
+
// 57; output keyword
|
|
161
|
+
Token[Token["Output"] = 57] = "Output";
|
|
162
|
+
// 58; switch statement keyword
|
|
163
|
+
Token[Token["Switch"] = 58] = "Switch";
|
|
164
|
+
// 59; switch case keyword
|
|
165
|
+
Token[Token["Case"] = 59] = "Case";
|
|
166
|
+
// 60; switch default keyword
|
|
167
|
+
Token[Token["Default"] = 60] = "Default";
|
|
168
|
+
// 61; defcal keyword
|
|
169
|
+
Token[Token["Defcal"] = 61] = "Defcal";
|
|
170
|
+
// 62; constant keywork
|
|
171
|
+
Token[Token["Const"] = 62] = "Const";
|
|
172
|
+
// 63; if statement conditional
|
|
173
|
+
Token[Token["If"] = 63] = "If";
|
|
174
|
+
// 64; else keyword
|
|
175
|
+
Token[Token["Else"] = 64] = "Else";
|
|
176
|
+
// 65; end keyword
|
|
177
|
+
Token[Token["End"] = 65] = "End";
|
|
178
|
+
// 66; inverse cosine
|
|
179
|
+
Token[Token["Arccos"] = 66] = "Arccos";
|
|
180
|
+
// 67; inverse sine
|
|
181
|
+
Token[Token["Arcsin"] = 67] = "Arcsin";
|
|
182
|
+
// 68; inverse tangent
|
|
183
|
+
Token[Token["Arctan"] = 68] = "Arctan";
|
|
184
|
+
// 69; ceiling function
|
|
185
|
+
Token[Token["Ceiling"] = 69] = "Ceiling";
|
|
186
|
+
// 70; cosine function
|
|
187
|
+
Token[Token["Cos"] = 70] = "Cos";
|
|
188
|
+
// 71; exp keyword
|
|
189
|
+
Token[Token["Exp"] = 71] = "Exp";
|
|
190
|
+
// 72; floor function
|
|
191
|
+
Token[Token["Floor"] = 72] = "Floor";
|
|
192
|
+
// 73; logarithm base e
|
|
193
|
+
Token[Token["Log"] = 73] = "Log";
|
|
194
|
+
// 74; modulus
|
|
195
|
+
Token[Token["Mod"] = 74] = "Mod";
|
|
196
|
+
// 75; popcount function
|
|
197
|
+
Token[Token["Popcount"] = 75] = "Popcount";
|
|
198
|
+
// 76; power function
|
|
199
|
+
Token[Token["Pow"] = 76] = "Pow";
|
|
200
|
+
// 77; rotate bits left function
|
|
201
|
+
Token[Token["Rotl"] = 77] = "Rotl";
|
|
202
|
+
// 78; rotate bits right function
|
|
203
|
+
Token[Token["Rotr"] = 78] = "Rotr";
|
|
204
|
+
// 79; sine
|
|
205
|
+
Token[Token["Sin"] = 79] = "Sin";
|
|
206
|
+
// 80; sqaure root
|
|
207
|
+
Token[Token["Sqrt"] = 80] = "Sqrt";
|
|
208
|
+
// 81; tangent
|
|
209
|
+
Token[Token["Tan"] = 81] = "Tan";
|
|
210
|
+
// 82; angle type
|
|
211
|
+
Token[Token["Angle"] = 82] = "Angle";
|
|
212
|
+
// 83; ctrl gate modifier
|
|
213
|
+
Token[Token["Ctrl"] = 83] = "Ctrl";
|
|
214
|
+
// 84; negctrl gate modifier
|
|
215
|
+
Token[Token["NegCtrl"] = 84] = "NegCtrl";
|
|
216
|
+
// 85; inv gate modifier
|
|
217
|
+
Token[Token["Inv"] = 85] = "Inv";
|
|
218
|
+
// 86; pow gate modifier
|
|
219
|
+
Token[Token["PowM"] = 86] = "PowM";
|
|
220
|
+
// 87; @ symbol
|
|
221
|
+
Token[Token["At"] = 87] = "At";
|
|
222
|
+
// 88; complex number keyword
|
|
223
|
+
Token[Token["Complex"] = 88] = "Complex";
|
|
224
|
+
// 89; $ symbol
|
|
225
|
+
Token[Token["Dollar"] = 89] = "Dollar";
|
|
226
|
+
// 90; array keyword
|
|
227
|
+
Token[Token["Array"] = 90] = "Array";
|
|
228
|
+
// 91; durationof function keyword
|
|
229
|
+
Token[Token["DurationOf"] = 91] = "DurationOf";
|
|
230
|
+
// 92; stretch type keyword
|
|
231
|
+
Token[Token["Stretch"] = 92] = "Stretch";
|
|
232
|
+
// 93; box keyword
|
|
233
|
+
Token[Token["Box"] = 93] = "Box";
|
|
234
|
+
// 94; readonly keyword
|
|
235
|
+
Token[Token["ReadOnly"] = 94] = "ReadOnly";
|
|
236
|
+
// 95; mutable keyword
|
|
237
|
+
Token[Token["Mutable"] = 95] = "Mutable";
|
|
238
|
+
// 96; #dim array dimensions
|
|
239
|
+
Token[Token["Dim"] = 96] = "Dim";
|
|
240
|
+
// 97; scientific notation literal
|
|
241
|
+
Token[Token["ScientificNotation"] = 97] = "ScientificNotation";
|
|
242
|
+
// 98; sizeof function
|
|
243
|
+
Token[Token["SizeOf"] = 98] = "SizeOf";
|
|
244
|
+
// 99; extern keyword
|
|
245
|
+
Token[Token["Extern"] = 99] = "Extern";
|
|
246
|
+
// 100; compound binary operators
|
|
247
|
+
Token[Token["CompoundBinaryOp"] = 100] = "CompoundBinaryOp";
|
|
248
|
+
})(Token || (exports.Token = Token = {}));
|
|
249
|
+
/**
|
|
250
|
+
* Mapping of string keywords to their corresponding token types.
|
|
251
|
+
*
|
|
252
|
+
* This lookup table enables the lexer to quickly determine if a string
|
|
253
|
+
* represents a reserved keyword or should be treated as an identifier.
|
|
254
|
+
*
|
|
255
|
+
* @internal
|
|
256
|
+
*/
|
|
257
|
+
var lookupMap = {
|
|
258
|
+
pi: Token.Pi,
|
|
259
|
+
π: Token.Pi,
|
|
260
|
+
qreg: Token.QReg,
|
|
261
|
+
qubit: Token.Qubit,
|
|
262
|
+
creg: Token.CReg,
|
|
263
|
+
bit: Token.Bit,
|
|
264
|
+
barrier: Token.Barrier,
|
|
265
|
+
gate: Token.Gate,
|
|
266
|
+
measure: Token.Measure,
|
|
267
|
+
reset: Token.Reset,
|
|
268
|
+
include: Token.Include,
|
|
269
|
+
if: Token.If,
|
|
270
|
+
opaque: Token.Opaque,
|
|
271
|
+
defcalgrammar: Token.DefcalGrammar,
|
|
272
|
+
float: Token.Float,
|
|
273
|
+
bool: Token.Bool,
|
|
274
|
+
true: Token.BoolLiteral,
|
|
275
|
+
false: Token.BoolLiteral,
|
|
276
|
+
int: Token.Int,
|
|
277
|
+
uint: Token.UInt,
|
|
278
|
+
euler: Token.Euler,
|
|
279
|
+
ℇ: Token.Euler,
|
|
280
|
+
tau: Token.Tau,
|
|
281
|
+
τ: Token.Tau,
|
|
282
|
+
duration: Token.Duration,
|
|
283
|
+
let: Token.Let,
|
|
284
|
+
delay: Token.Delay,
|
|
285
|
+
return: Token.Return,
|
|
286
|
+
def: Token.Def,
|
|
287
|
+
for: Token.For,
|
|
288
|
+
in: Token.In,
|
|
289
|
+
while: Token.While,
|
|
290
|
+
break: Token.Break,
|
|
291
|
+
continue: Token.Continue,
|
|
292
|
+
input: Token.Input,
|
|
293
|
+
output: Token.Output,
|
|
294
|
+
switch: Token.Switch,
|
|
295
|
+
case: Token.Case,
|
|
296
|
+
default: Token.Default,
|
|
297
|
+
defcal: Token.Defcal,
|
|
298
|
+
const: Token.Const,
|
|
299
|
+
else: Token.Else,
|
|
300
|
+
end: Token.End,
|
|
301
|
+
"!": Token.UnaryOp,
|
|
302
|
+
"~": Token.UnaryOp,
|
|
303
|
+
"**": Token.ArithmeticOp,
|
|
304
|
+
"*": Token.ArithmeticOp,
|
|
305
|
+
"/": Token.ArithmeticOp,
|
|
306
|
+
"%": Token.ArithmeticOp,
|
|
307
|
+
"+": Token.ArithmeticOp,
|
|
308
|
+
"++": Token.ArithmeticOp,
|
|
309
|
+
"&": Token.BinaryOp,
|
|
310
|
+
"|": Token.BinaryOp,
|
|
311
|
+
"^": Token.BinaryOp,
|
|
312
|
+
"&&": Token.BinaryOp,
|
|
313
|
+
"||": Token.BinaryOp,
|
|
314
|
+
"<": Token.BinaryOp,
|
|
315
|
+
"<=": Token.BinaryOp,
|
|
316
|
+
">": Token.BinaryOp,
|
|
317
|
+
">=": Token.BinaryOp,
|
|
318
|
+
"==": Token.BinaryOp,
|
|
319
|
+
"!=": Token.BinaryOp,
|
|
320
|
+
"<<": Token.BinaryOp,
|
|
321
|
+
">>": Token.BinaryOp,
|
|
322
|
+
"**=": Token.CompoundArithmeticOp,
|
|
323
|
+
"/=": Token.CompoundArithmeticOp,
|
|
324
|
+
"%=": Token.CompoundArithmeticOp,
|
|
325
|
+
"+=": Token.CompoundArithmeticOp,
|
|
326
|
+
"-=": Token.CompoundArithmeticOp,
|
|
327
|
+
"*=": Token.CompoundArithmeticOp,
|
|
328
|
+
"^=": Token.CompoundArithmeticOp,
|
|
329
|
+
arccos: Token.Arccos,
|
|
330
|
+
arcsin: Token.Arcsin,
|
|
331
|
+
arctan: Token.Arctan,
|
|
332
|
+
ceiling: Token.Ceiling,
|
|
333
|
+
cos: Token.Cos,
|
|
334
|
+
exp: Token.Exp,
|
|
335
|
+
floor: Token.Floor,
|
|
336
|
+
log: Token.Log,
|
|
337
|
+
mod: Token.Mod,
|
|
338
|
+
popcount: Token.Popcount,
|
|
339
|
+
pow: Token.Pow,
|
|
340
|
+
rotl: Token.Rotl,
|
|
341
|
+
rotr: Token.Rotr,
|
|
342
|
+
sin: Token.Sin,
|
|
343
|
+
sqrt: Token.Sqrt,
|
|
344
|
+
tan: Token.Tan,
|
|
345
|
+
angle: Token.Angle,
|
|
346
|
+
"@": Token.At,
|
|
347
|
+
complex: Token.Complex,
|
|
348
|
+
$: Token.Dollar,
|
|
349
|
+
array: Token.Array,
|
|
350
|
+
durationof: Token.DurationOf,
|
|
351
|
+
stretch: Token.Stretch,
|
|
352
|
+
box: Token.Box,
|
|
353
|
+
readonly: Token.ReadOnly,
|
|
354
|
+
mutable: Token.Mutable,
|
|
355
|
+
sizeof: Token.SizeOf,
|
|
356
|
+
extern: Token.Extern,
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Returns the token type that corresponds to a given string.
|
|
360
|
+
*
|
|
361
|
+
* This function is used by the lexer to classify identifiers and keywords.
|
|
362
|
+
* If the string is a reserved keyword, it returns the appropriate token type.
|
|
363
|
+
* Otherwise, it returns Token.Id to indicate a user-defined identifier.
|
|
364
|
+
*
|
|
365
|
+
* @param ident - The string to look up
|
|
366
|
+
* @returns The corresponding token type
|
|
367
|
+
*
|
|
368
|
+
* @example Keyword lookup
|
|
369
|
+
* ```typescript
|
|
370
|
+
* lookup('qubit'); // Returns Token.Qubit
|
|
371
|
+
* lookup('measure'); // Returns Token.Measure
|
|
372
|
+
* lookup('myVar'); // Returns Token.Id
|
|
373
|
+
* lookup('π'); // Returns Token.Pi
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
function lookup(ident) {
|
|
377
|
+
return ident in lookupMap ? lookupMap[ident] : Token.Id;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Returns the string representation of a token type.
|
|
381
|
+
*
|
|
382
|
+
* This is useful for debugging and error reporting, allowing you to
|
|
383
|
+
* convert token enum values back to their string representations.
|
|
384
|
+
*
|
|
385
|
+
* @param token - The token type to convert
|
|
386
|
+
* @returns The string representation of the token, or undefined if not found
|
|
387
|
+
*
|
|
388
|
+
* @example Token to string conversion
|
|
389
|
+
* ```typescript
|
|
390
|
+
* inverseLookup(Token.Qubit); // Returns 'qubit'
|
|
391
|
+
* inverseLookup(Token.If); // Returns 'if'
|
|
392
|
+
* inverseLookup(Token.Pi); // Returns 'pi'
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
function inverseLookup(token) {
|
|
396
|
+
return Object.keys(lookupMap).find(function (ident) { return lookupMap[ident] == token; });
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Determines whether a token can be used as a parameter in expressions.
|
|
400
|
+
*
|
|
401
|
+
* This function helps the parser validate parameter lists by checking if
|
|
402
|
+
* a token type is allowed in parameter contexts. Parameters can include
|
|
403
|
+
* identifiers, numbers, and other value-bearing tokens, but not structural
|
|
404
|
+
* tokens like semicolons or braces.
|
|
405
|
+
*
|
|
406
|
+
* @param token - The token type to check
|
|
407
|
+
* @returns true if the token CANNOT be used as a parameter, false otherwise
|
|
408
|
+
*
|
|
409
|
+
* @example Parameter validation
|
|
410
|
+
* ```typescript
|
|
411
|
+
* notParam(Token.Id); // false - identifiers can be parameters
|
|
412
|
+
* notParam(Token.NNInteger); // false - numbers can be parameters
|
|
413
|
+
* notParam(Token.Semicolon); // true - semicolons cannot be parameters
|
|
414
|
+
* notParam(Token.LParen); // true - parentheses cannot be parameters
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
function notParam(token) {
|
|
418
|
+
if (token == Token.NNInteger ||
|
|
419
|
+
token == Token.Real ||
|
|
420
|
+
token == Token.Id ||
|
|
421
|
+
inverseLookup(token)) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
return true;
|
|
425
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenQASM version detection and management utilities
|
|
4
|
+
*
|
|
5
|
+
* Handles version detection from QASM source code and provides utilities
|
|
6
|
+
* for working with different OpenQASM versions. Supports automatic version
|
|
7
|
+
* detection from OPENQASM statements and manual version specification.
|
|
8
|
+
*
|
|
9
|
+
* @module Version Management
|
|
10
|
+
*
|
|
11
|
+
* @example Version detection
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const version = new OpenQASMVersion(3, 0);
|
|
14
|
+
* console.log(version.toString()); // "3.0"
|
|
15
|
+
* console.log(version.isVersion3()); // true
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.OpenQASMVersion = exports.OpenQASMMajorVersion = void 0;
|
|
20
|
+
/** Enum representing the major OpenQASM versions. */
|
|
21
|
+
var OpenQASMMajorVersion;
|
|
22
|
+
(function (OpenQASMMajorVersion) {
|
|
23
|
+
OpenQASMMajorVersion[OpenQASMMajorVersion["Version2"] = 2] = "Version2";
|
|
24
|
+
OpenQASMMajorVersion[OpenQASMMajorVersion["Version3"] = 3] = "Version3";
|
|
25
|
+
})(OpenQASMMajorVersion || (exports.OpenQASMMajorVersion = OpenQASMMajorVersion = {}));
|
|
26
|
+
/** Class representing the OpenQASM version. */
|
|
27
|
+
var OpenQASMVersion = /** @class */ (function () {
|
|
28
|
+
/**
|
|
29
|
+
* Creates an OpenQASMVersion instance.
|
|
30
|
+
* @param major - The OpenQASM major version. (optional)
|
|
31
|
+
* @param minor - The OpenQASM minor version (optional)
|
|
32
|
+
*/
|
|
33
|
+
function OpenQASMVersion(major, minor) {
|
|
34
|
+
this.major = major ? major : OpenQASMMajorVersion.Version3;
|
|
35
|
+
this.minor = minor ? minor : 0;
|
|
36
|
+
}
|
|
37
|
+
/** Returns the version as a formatted string. */
|
|
38
|
+
OpenQASMVersion.prototype.toString = function () {
|
|
39
|
+
return "".concat(this.major, ".").concat(this.minor);
|
|
40
|
+
};
|
|
41
|
+
/** Returns whether the version is 3.x */
|
|
42
|
+
OpenQASMVersion.prototype.isVersion3 = function () {
|
|
43
|
+
if (this.major === OpenQASMMajorVersion.Version3) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
/** Returns whether the version is 2.x */
|
|
49
|
+
OpenQASMVersion.prototype.isVersion2 = function () {
|
|
50
|
+
if (this.major === OpenQASMMajorVersion.Version2) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
return OpenQASMVersion;
|
|
56
|
+
}());
|
|
57
|
+
exports.OpenQASMVersion = OpenQASMVersion;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
window.hierarchyData = "eJyrVirKzy8pVrKKjtVRKkpNy0lNLsnMzwMKVNfWAgCbHgqm"
|
package/docs/custom.css
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# QASM TypeScript Documentation
|
|
2
|
+
|
|
3
|
+
OpenQASM, the low-level programming language for quantum circuit specification, implemented in TypeScript.
|
|
4
|
+
|
|
5
|
+
QASM-TS 2.0 is an implementation of a compiler frontend for OpenQASM 2.0 and 3.0. It includes a lexer and a parser of the OpenQASM language. The source is parsed into an Intermediate Representation (IR): an Abstract Syntax Tree (AST) that captures program structure including control flow and data flow.
|
|
6
|
+
|
|
7
|
+
The package is aimed at enabling implementations of verification and validation software (such as semantic and static analyzers), compilers and more. These tools may be instrumental in the formalization of hybrid quantum-classical computing.
|
|
8
|
+
|
|
9
|
+
Language documentation is provided by IBM [here](https://openqasm.com).
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install qasm-ts
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
|
|
21
|
+
Parse from an OpenQASM string snippet:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { parseString } from "qasm-ts";
|
|
25
|
+
|
|
26
|
+
const qasmCode = `
|
|
27
|
+
OPENQASM 3.0;
|
|
28
|
+
include "stdgates.inc";
|
|
29
|
+
qubit[2] q;
|
|
30
|
+
h q[0];
|
|
31
|
+
cx q[0], q[1];
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const ast = parseString(qasmCode);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Parse from an OpenQASM file:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { parseFile } from "qasm-ts";
|
|
41
|
+
|
|
42
|
+
const ast = parseFile("./my-circuit.qasm");
|
|
43
|
+
|
|
44
|
+
// Specify OpenQASM version explicitly
|
|
45
|
+
const ast2 = parseFile("./legacy-circuit.qasm", 2); // OpenQASM 2.0
|
|
46
|
+
const ast3 = parseFile("./modern-circuit.qasm", 3); // OpenQASM 3.0
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Working with the AST
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Get verbose output with class names
|
|
53
|
+
const verboseAst = parseString(qasmCode, 3, true);
|
|
54
|
+
|
|
55
|
+
// Get stringified JSON output
|
|
56
|
+
const jsonAst = parseString(qasmCode, 3, false, true);
|
|
57
|
+
|
|
58
|
+
// Both verbose and stringified
|
|
59
|
+
const verboseJsonAst = parseString(qasmCode, 3, true, true);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Example I/O
|
|
63
|
+
|
|
64
|
+
### Input: `alignment.qasm` ([source](https://github.com/openqasm/openqasm/blob/main/examples/alignment.qasm))
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
include "stdgates.inc";
|
|
68
|
+
|
|
69
|
+
stretch g;
|
|
70
|
+
|
|
71
|
+
qubit[3] q;
|
|
72
|
+
barrier q;
|
|
73
|
+
cx q[0], q[1];
|
|
74
|
+
delay[g] q[2];
|
|
75
|
+
U(pi/4, 0, pi/2) q[2];
|
|
76
|
+
delay[2*g] q[2];
|
|
77
|
+
barrier q;
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Output: Abstract Syntax Tree
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
[
|
|
85
|
+
Include { filename: '"stdgates.inc"' },
|
|
86
|
+
ClassicalDeclaration {
|
|
87
|
+
classicalType: StretchType {},
|
|
88
|
+
identifier: Identifier { name: 'g' },
|
|
89
|
+
initializer: null,
|
|
90
|
+
isConst: false
|
|
91
|
+
},
|
|
92
|
+
QuantumDeclaration {
|
|
93
|
+
identifier: Identifier { name: 'q' },
|
|
94
|
+
size: IntegerLiteral { value: 3 }
|
|
95
|
+
},
|
|
96
|
+
QuantumBarrier { qubits: [ [Identifier] ] },
|
|
97
|
+
QuantumGateCall {
|
|
98
|
+
quantumGateName: Identifier { name: 'cx' },
|
|
99
|
+
qubits: [ [SubscriptedIdentifier], [SubscriptedIdentifier] ],
|
|
100
|
+
parameters: null,
|
|
101
|
+
modifiers: []
|
|
102
|
+
},
|
|
103
|
+
QuantumDelay {
|
|
104
|
+
duration: Identifier { name: 'g' },
|
|
105
|
+
qubits: [ [SubscriptedIdentifier] ]
|
|
106
|
+
},
|
|
107
|
+
QuantumGateCall {
|
|
108
|
+
quantumGateName: Identifier { name: 'U' },
|
|
109
|
+
qubits: [ [SubscriptedIdentifier] ],
|
|
110
|
+
parameters: Parameters { args: [Array] },
|
|
111
|
+
modifiers: []
|
|
112
|
+
},
|
|
113
|
+
QuantumDelay {
|
|
114
|
+
duration: Arithmetic { op: '*', left: [IntegerLiteral], right: [Identifier] },
|
|
115
|
+
qubits: [ [SubscriptedIdentifier] ]
|
|
116
|
+
},
|
|
117
|
+
QuantumBarrier { qubits: [ [Identifier] ] }
|
|
118
|
+
]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## API Documentation Navigation
|
|
122
|
+
|
|
123
|
+
### Core Functions
|
|
124
|
+
|
|
125
|
+
Start here for the main parsing functions:
|
|
126
|
+
|
|
127
|
+
- **[parseString](functions/Main_Functions.parseString.html)** - Parse OpenQASM code from a string
|
|
128
|
+
- **[parseFile](functions/Main_Functions.parseFile.html)** - Parse OpenQASM code from a file
|
|
129
|
+
|
|
130
|
+
### Tokenization
|
|
131
|
+
|
|
132
|
+
Understand the tokenization process and available token types:
|
|
133
|
+
|
|
134
|
+
- **[OpenQASM 3.0 Tokens](modules/qasm3_token.html)** - Modern OpenQASM token set
|
|
135
|
+
- **[OpenQASM 2.0 Tokens](modules/qasm2_token.html)** - Legacy OpenQASM token set
|
|
136
|
+
|
|
137
|
+
### Lexing
|
|
138
|
+
|
|
139
|
+
Understand the Lexer:
|
|
140
|
+
|
|
141
|
+
- **[OpenQASM 3.0 Lexer](modules/qasm3_lexer.html)** - Modern OpenQASM lexer
|
|
142
|
+
- **[OpenQASM 2.0 Lexer](modules/qasm2_lexer.html)** - Legacy OpenQASM lexer
|
|
143
|
+
|
|
144
|
+
### AST Structure
|
|
145
|
+
|
|
146
|
+
Understand the abstract syntax tree nodes:
|
|
147
|
+
|
|
148
|
+
- **[OpenQASM 3.0 AST Nodes](modules/qasm3_ast.html)** - Modern OpenQASM syntax tree
|
|
149
|
+
- **[OpenQASM 2.0 AST Nodes](modules/qasm2_ast.html)** - Legacy OpenQASM syntax tree
|
|
150
|
+
|
|
151
|
+
### Parsing
|
|
152
|
+
|
|
153
|
+
Understand the Parser:
|
|
154
|
+
|
|
155
|
+
- **[OpenQASM 3.0 Parser](modules/qasm3_parser.html)** - Modern OpenQASM parser
|
|
156
|
+
- **[OpenQASM 2.0 Parser](modules/qasm2_parser.html)** - Legacy OpenQASM parser
|
|
157
|
+
|
|
158
|
+
### Utilities and Internals
|
|
159
|
+
|
|
160
|
+
- **[Error Handling](modules/Error_Handling.html)** - All error types and their usage
|
|
161
|
+
- **[Version Management](modules/Version_Management.html)** - Version detection and handling
|
|
162
|
+
|
|
163
|
+
Navigate using the sidebar or search functionality to find specific functions and classes.
|
|
164
|
+
|
|
165
|
+
## New In Version 2.0.0
|
|
166
|
+
|
|
167
|
+
- Support for the OpenQASM 3.0 spec while retaining OpenQASM 2.0 backwards compatibility.
|
|
168
|
+
|
|
169
|
+
## Source Code
|
|
170
|
+
|
|
171
|
+
Feel free to clone, fork, comment or contribute on [GitHub](https://github.com/comp-phys-marc/qasm-ts)!
|
|
172
|
+
|
|
173
|
+
## References
|
|
174
|
+
|
|
175
|
+
The original OpenQASM authors:
|
|
176
|
+
|
|
177
|
+
- Andrew W. Cross, Lev S. Bishop, John A. Smolin, Jay M. Gambetta "Open Quantum Assembly Language" [arXiv:1707.03429](https://web.archive.org/web/20210121114036/https://arxiv.org/abs/1707.03429)
|
|
178
|
+
- Andrew W. Cross, Ali Javadi-Abhari, Thomas Alexander, Niel de Beaudrap, Lev S. Bishop, Steven Heidel, Colm A. Ryan, Prasahnt Sivarajah, John Smolin, Jay M. Gambetta, Blake R. Johnson "OpenQASM 3: A broader and deeper quantum assembly language" [arXiv:2104.14722](https://arxiv.org/abs/2104.14722)
|
|
179
|
+
|
|
180
|
+
Another strongly typed implementation from which this project took some inspiration:
|
|
181
|
+
|
|
182
|
+
- [Adam Kelly's Rust QASM Parser](https://github.com/libtangle/qasm-rust)
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
Copyright 2019 Marcus Edwards
|
|
187
|
+
|
|
188
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
|
|
189
|
+
|
|
190
|
+
```http://www.apache.org/licenses/LICENSE-2.0```
|
|
191
|
+
|
|
192
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
193
|
+
|
|
194
|
+
## How to Cite
|
|
195
|
+
|
|
196
|
+
If you are using QASM-TS for research we appreciate any citations. Please read and cite our pre-print at https://arxiv.org/abs/2412.12578.
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
@misc{kim2024enablingverificationformalizationhybrid,
|
|
200
|
+
title={Enabling the Verification and Formalization of Hybrid Quantum-Classical Computing with OpenQASM 3.0 compatible QASM-TS 2.0},
|
|
201
|
+
author={Sean Kim and Marcus Edwards},
|
|
202
|
+
year={2024},
|
|
203
|
+
eprint={2412.12578},
|
|
204
|
+
archivePrefix={arXiv},
|
|
205
|
+
primaryClass={cs.PL},
|
|
206
|
+
url={https://arxiv.org/abs/2412.12578},
|
|
207
|
+
}
|
|
208
|
+
```
|