/** * OpenQASM 3.0 Token Definitions and Utilities * * This module defines all the token types used in OpenQASM 3.0 syntax, which * significantly extends OpenQASM 2.0 with modern programming language features. * * Major additions in OpenQASM 3.0: * - **Classical types**: int, uint, float, bool, bit, complex * - **Control flow**: if/else, for/while loops, switch/case * - **Functions**: def, return, extern declarations * - **Advanced features**: arrays, timing (delay, durationof), calibration * - **Quantum extensions**: qubit declarations, gate modifiers, hardware qubits * * @module * * @example OpenQASM 3.0 advanced tokens * ```typescript * import { lookup, Token } from './qasm3/token'; * * console.log(lookup('qubit')); // Token.Qubit * console.log(lookup('if')); // Token.If * console.log(lookup('def')); // Token.Def * console.log(lookup('complex')); // Token.Complex * ``` */ /** * Enumeration of all OpenQASM 3.0 token types. * * Each token represents a specific syntactic element in OpenQASM 3.0 code. * The enum values correspond to different categories: * - Literals: NNInteger, Real, String, BoolLiteral * - Identifiers: Id * - Keywords: Qubit, Gate, Measure, If, For, While, etc. * - Operators: ArithmeticOp, BinaryOp, UnaryOp * - Punctuation: Semicolon, Comma, LParen, RParen, etc. * - Special: OpenQASM, Include, EndOfFile, Illegal */ declare enum Token { Illegal = 0, EndOfFile = 1, Real = 2, NNInteger = 3, Integer = 4, Id = 5, OpenQASM = 6, Include = 7, Semicolon = 8, Colon = 9, Comma = 10, LParen = 11, LSParen = 12, LCParen = 13, RParen = 14, RSParen = 15, RCParen = 16, EqualsAssmt = 17, Arrow = 18, QReg = 19, Qubit = 20, CReg = 21, Bit = 22, Barrier = 23, Gate = 24, Measure = 25, Reset = 26, String = 27, Opaque = 28, DefcalGrammar = 29, Float = 30, Bool = 31, Int = 32, UInt = 33, Pi = 34, Euler = 35, Tau = 36, BinaryLiteral = 37, OctalLiteral = 38, HexLiteral = 39, ArithmeticOp = 40, CompoundArithmeticOp = 41, BoolLiteral = 42, Duration = 43, UnaryOp = 44, BinaryOp = 45, Let = 46, QuantumModifier = 47, Delay = 48, Return = 49, Def = 50, For = 51, In = 52, While = 53, Break = 54, Continue = 55, Input = 56, Output = 57, Switch = 58, Case = 59, Default = 60, Defcal = 61, Const = 62, If = 63, Else = 64, End = 65, Arccos = 66, Arcsin = 67, Arctan = 68, Ceiling = 69, Cos = 70, Exp = 71, Floor = 72, Log = 73, Mod = 74, Popcount = 75, Pow = 76, Rotl = 77, Rotr = 78, Sin = 79, Sqrt = 80, Tan = 81, Angle = 82, Ctrl = 83, NegCtrl = 84, Inv = 85, PowM = 86, At = 87, Complex = 88, Dollar = 89, Array = 90, DurationOf = 91, Stretch = 92, Box = 93, ReadOnly = 94, Mutable = 95, Dim = 96, ScientificNotation = 97, SizeOf = 98, Extern = 99, CompoundBinaryOp = 100 } /** * Returns the token type that corresponds to a given string. * * This function is used by the lexer to classify identifiers and keywords. * If the string is a reserved keyword, it returns the appropriate token type. * Otherwise, it returns Token.Id to indicate a user-defined identifier. * * @param ident - The string to look up * @returns The corresponding token type * * @example Keyword lookup * ```typescript * lookup('qubit'); // Returns Token.Qubit * lookup('measure'); // Returns Token.Measure * lookup('myVar'); // Returns Token.Id * lookup('π'); // Returns Token.Pi * ``` */ declare function lookup(ident: string): Token; /** * Returns the string representation of a token type. * * This is useful for debugging and error reporting, allowing you to * convert token enum values back to their string representations. * * @param token - The token type to convert * @returns The string representation of the token, or undefined if not found * * @example Token to string conversion * ```typescript * inverseLookup(Token.Qubit); // Returns 'qubit' * inverseLookup(Token.If); // Returns 'if' * inverseLookup(Token.Pi); // Returns 'pi' * ``` */ declare function inverseLookup(token: Token): string; /** * Determines whether a token can be used as a parameter in expressions. * * This function helps the parser validate parameter lists by checking if * a token type is allowed in parameter contexts. Parameters can include * identifiers, numbers, and other value-bearing tokens, but not structural * tokens like semicolons or braces. * * @param token - The token type to check * @returns true if the token CANNOT be used as a parameter, false otherwise * * @example Parameter validation * ```typescript * notParam(Token.Id); // false - identifiers can be parameters * notParam(Token.NNInteger); // false - numbers can be parameters * notParam(Token.Semicolon); // true - semicolons cannot be parameters * notParam(Token.LParen); // true - parentheses cannot be parameters * ``` */ declare function notParam(token: Token): boolean; export { Token, notParam, lookup, inverseLookup };