Creates a lexer.
The string to lex.
The starting cursor position.
Returns the current line of code where the cursor is located.
The current cursor position in the input string.
The specific line where the cursor is located.
Returns the line number where the current cursor is located.
The current cursor position in the input string.
The line number.
Calling this method lexes the code represented by the provided string.
An array of tokens and their corresponding values.
Lexes the next token.
The next token and its corresponding value.
Reads a character without advancing the cursor.
Determines whether the next character to process equals a given character.
The given character.
Whether the next character equals the given character.
Reads a character and advances the cursor.
Optional cursor position modifier.
Reads an identifier.
The identifier as a string.
Reads a numeric value.
The numeric value as a string.
Reads a string literal.
The literal's termination character.
The literal as a string.
Advances the cusor past the next comment.
Advances the cusor past the next block of whitespace.
Verifies that all appropriate lines end with a semicolon.
A tuple of the status and if False, returns the problematic line.
OpenQASM 2.0 Lexical Analyzer
A simpler lexer implementation focused on the core quantum circuit description features of OpenQASM 2.0. This lexer handles the essential constructs needed for basic quantum programming without the complexity of classical programming language features.
Example: Basic OpenQASM 2.0 tokenization