From 68cc2f20e023fea341f082c927ad743f18ad6416 Mon Sep 17 00:00:00 2001 From: Gabriele Messina Date: Sat, 13 Apr 2024 16:21:22 +0000 Subject: [PATCH] Grammar refactor --- playground/examples/test.qut | 8 +- specification/grammar/qutes_lexer.g4 | 13 +- specification/grammar/qutes_parser.g4 | 86 +- src/grammar_frontend/expression.py | 123 +- src/grammar_frontend/literal.py | 89 +- src/grammar_frontend/operation.py | 397 ++--- src/grammar_frontend/statement.py | 82 +- src/quantum_circuit/qutes_gates.py | 1 + src/qutes_antlr/qutes_lexer.py | 609 +++---- src/qutes_antlr/qutes_lexer.tokens | 210 +-- src/qutes_antlr/qutes_parser.py | 2015 +++++++++++++---------- src/qutes_antlr/qutes_parser.tokens | 210 +-- src/qutes_antlr/qutes_parserListener.py | 151 +- src/qutes_antlr/qutes_parserVisitor.py | 79 +- src/tests/test_grammar.py | 2 - 15 files changed, 2193 insertions(+), 1882 deletions(-) diff --git a/playground/examples/test.qut b/playground/examples/test.qut index a9eb854..e4ac807 100644 --- a/playground/examples/test.qut +++ b/playground/examples/test.qut @@ -1,4 +1,6 @@ -qubit a = 0q; -bool b = a; +int a = 10; +int b = -4; -print b; \ No newline at end of file +int c = a + b; + +print c; \ No newline at end of file diff --git a/specification/grammar/qutes_lexer.g4 b/specification/grammar/qutes_lexer.g4 index 8d8487b..a8a7261 100644 --- a/specification/grammar/qutes_lexer.g4 +++ b/specification/grammar/qutes_lexer.g4 @@ -16,9 +16,12 @@ VOID_TYPE : 'void' ; RETURN : 'return' ; MULTIPLY : '*' ; DIVIDE : '/' ; +MODULE : '%' ; ADD : '+' ; SUB : '-' ; NOT : 'not' ; +AND : 'and' ; +OR : 'or' ; BY : 'by' ; SWAP : 'swap' ; PAULIY : 'pauliy' ; @@ -33,11 +36,19 @@ MEASURE : 'measure' ; PRINT : 'print' ; BARRIER : 'barrier' ; EQUAL : '==' ; +NOT_EQUAL : '!=' ; GREATER : '>' ; GREATEREQUAL : '>=' ; LOWER : '<' ; LOWEREQUAL : '<=' ; ASSIGN : '=' ; +AUTO_INCREMENT : '++' ; +AUTO_DECREMENT : '--' ; +AUTO_SUM : '+=' ; +AUTO_SUB : '-=' ; +AUTO_MULTIPLY : '*=' ; +AUTO_DIVIDE : '/=' ; +AUTO_MODULE : '%=' ; END_OF_STATEMENT : ';' ; VAR_STATEMENT : 'var' ; FOR_STATEMENT : 'for' ; @@ -98,7 +109,7 @@ BOOL_LITERAL ; INT_LITERAL - : DIGIT+ + : MATH_SIGN? DIGIT+ ; FLOAT_LITERAL diff --git a/specification/grammar/qutes_parser.g4 b/specification/grammar/qutes_parser.g4 index e1e846d..dcc8c9d 100644 --- a/specification/grammar/qutes_parser.g4 +++ b/specification/grammar/qutes_parser.g4 @@ -22,9 +22,10 @@ statement | qualifiedName ASSIGN expr END_OF_STATEMENT #AssignmentStatement | RETURN expr END_OF_STATEMENT #ReturnStatement | expr END_OF_STATEMENT #ExpressionStatement + | (MEASURE | BARRIER) #FactStatement | END_OF_STATEMENT #EmptyStatement ; - + functionDeclarationParams : variableDeclaration (COMMA functionDeclarationParams)? ; @@ -33,55 +34,39 @@ variableDeclaration : variableType variableName (ASSIGN expr)? ; -functionCallParams - : qualifiedName (COMMA functionCallParams)? - ; - expr - : term - | functionCall - | test - | parenExpr - | groverExpr - ; - -groverExpr - : termList op=IN_STATEMENT qualifiedName - ; - -functionCall //Function name should be a qualifiedName here. - : functionName ROUND_PARENTHESIS_OPEN functionCallParams? ROUND_PARENTHESIS_CLOSE + : ROUND_PARENTHESIS_OPEN expr ROUND_PARENTHESIS_CLOSE #ParentesizeExpression + | literal #LiteralExpression + | qualifiedName #QualifiedNameExpression + // Array access + | functionName ROUND_PARENTHESIS_OPEN functionCallParams? ROUND_PARENTHESIS_CLOSE #FunctionCallExpression + | expr op=(AUTO_INCREMENT | AUTO_DECREMENT) #PostfixOperator + | op=(NOT | ADD | SUB | AUTO_INCREMENT | AUTO_DECREMENT) expr #PrefixOperator + // cast operation + | expr op=(MULTIPLY | DIVIDE | MODULE) expr #MultiplicativeOperator + | expr op=(ADD | SUB) expr #SumOperator + | expr op=(GREATEREQUAL | LOWEREQUAL | GREATER | LOWER ) expr #RelationalOperator + | expr op=(EQUAL | NOT_EQUAL) expr #EqualityOperator + | expr op=AND expr #LogicAndOperator + | expr op=OR expr #LogicOrOperator + // | expr op=(AUTO_SUM | AUTO_DECREMENT | AUTO_MODULE | AUTO_DIVIDE | AUTO_MODULE) expr #AutoAssignmentOperator + | op=(MCX | MCZ | MCY | SWAP) termList #MultipleUnaryOperator + | op=(PRINT | PAULIY | PAULIZ | HADAMARD | MEASURE) expr #UnaryOperator + | op=MCP termList BY expr #MultipleUnaryPhaseOperator + | termList op=IN_STATEMENT qualifiedName #GroverOperator ; -parenExpr - : ROUND_PARENTHESIS_OPEN expr ROUND_PARENTHESIS_CLOSE +functionCallParams + : (literal | qualifiedName) (COMMA functionCallParams)? ; -test - : term - | term op=(GREATER | LOWER | EQUAL | GREATEREQUAL | LOWEREQUAL) term +termList + : (literal | qualifiedName) (COMMA termList)? ; -term - : term op=(MULTIPLY | DIVIDE) term #BinaryPriorityOperator - | term op=(ADD | SUB) term #BinaryOperator - | op=(PRINT | NOT | PAULIY | PAULIZ | HADAMARD | MEASURE | ADD | SUB) term #UnaryOperator - | op=(MCX | MCZ | MCY | SWAP) termList #MultipleUnaryOperator - | op=MCP termList BY expr #MultipleUnaryPhaseOperator - | (boolean - | integer - | float - | qubit - | quint - | qustring +variableType + : type | qualifiedName - | MEASURE - | BARRIER - | string) #IdentityOperator - ; - -termList - : term (COMMA termList)? ; type @@ -95,13 +80,10 @@ type | VOID_TYPE ; -variableType - : type - | qualifiedName - ; - qualifiedName : SYMBOL_LITERAL (DOT SYMBOL_LITERAL)* + | variableName + | functionName ; variableName @@ -112,6 +94,16 @@ functionName : SYMBOL_LITERAL ; +literal + : boolean + | integer + | float + | qubit + | quint + | qustring + | string + ; + string : STRING_LITERAL ; diff --git a/src/grammar_frontend/expression.py b/src/grammar_frontend/expression.py index c5be7ec..eeae5bc 100644 --- a/src/grammar_frontend/expression.py +++ b/src/grammar_frontend/expression.py @@ -3,21 +3,26 @@ from symbols.symbol import Symbol, SymbolClass from symbols.scope_handler import ScopeHandlerForSymbolsUpdate from symbols.variables_handler import VariablesHandler -from symbols.types import Qubit, Quint, QutesDataType from quantum_circuit import QuantumCircuitHandler from grammar_frontend.qutes_base_visitor import QutesBaseVisitor -import math class QutesGrammarExpressionVisitor(QutesBaseVisitor): def __init__(self, symbols_tree:ScopeTreeNode, quantum_circuit_handler : QuantumCircuitHandler, scope_handler:ScopeHandlerForSymbolsUpdate, variables_handler:VariablesHandler, verbose:bool = False): super().__init__(symbols_tree, quantum_circuit_handler, scope_handler, variables_handler, verbose) - # Visit a parse tree produced by qutesParser#expr. def visitExpr(self, ctx:qutes_parser.ExprContext): - return self.__visit("visitExpr", lambda : self.visitChildren(ctx)) + return self.visitChildren(ctx) + + def visitParentesizeExpression(self, ctx:qutes_parser.ParentesizeExpressionContext): + return self.visitChildren(ctx) + + def visitLiteralExpression(self, ctx:qutes_parser.LiteralExpressionContext): + return self.visitChildren(ctx) + + def visitQualifiedNameExpression(self, ctx:qutes_parser.QualifiedNameExpressionContext): + return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#functionCall. - def visitFunctionCall(self, ctx:qutes_parser.FunctionCallContext): + def visitFunctionCallExpression(self, ctx:qutes_parser.FunctionCallExpressionContext): function_name = self.visit(ctx.functionName()) function_params:list[Symbol] = [] if(ctx.functionCallParams()): @@ -57,109 +62,3 @@ def __visitFunctionCall(self, function_name, function_params, tokenIndex): self.scope_handler.end_function() return result - - # Visit a parse tree produced by qutes_parser#functionCallParams. - def visitFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): - param = self.visit(ctx.qualifiedName()) - params = [] - if(ctx.functionCallParams()): - params = self.__visit("functionCallParams", lambda : self.visit(ctx.functionCallParams())) - if(not isinstance(params, list)): - params = [params] - params.append(param) - return params[::-1] - - # Visit a parse tree produced by qutesParser#parenExpr. - def visitParenExpr(self, ctx:qutes_parser.ParenExprContext): - return self.__visit("visitparenExpr", lambda : self.__visit_paren_expr(ctx)) - - def __visit_paren_expr(self, ctx:qutes_parser.ParenExprContext): - result = None - if(ctx.expr()): - if(self.log_trace_enabled): print("visitParenExpr -> expr") - result = self.visitChildren(ctx.expr()) - return result - - # Visit a parse tree produced by qutes_parser#GroverOperator. - def visitGroverExpr(self, ctx:qutes_parser.GroverExprContext): - return self.__visitGroverOperator(ctx) - - grover_count = iter(range(1, 1000)) - def __visitGroverOperator(self, ctx:qutes_parser.GroverExprContext): - current_grover_count = next(self.grover_count) - target_symbol:Symbol = self.visit(ctx.qualifiedName()) - if(not QutesDataType.is_quantum_type(target_symbol.casted_static_type)): - #TODO: Handle promotion to quantum type? - return - if(ctx.IN_STATEMENT()): - array_register = target_symbol.quantum_register - self.quantum_circuit_handler.start_quantum_function() - termList:list[Symbol] = self.visit(ctx.termList()) - array_size = len(target_symbol.quantum_register) - - grover_result = self.quantum_circuit_handler.declare_quantum_register("grover_phase_ancilla", Qubit()) - oracle_registers = [array_register] - registers_to_measure = [] - if(self.log_grover_verbose): - registers_to_measure.append(array_register) - rotation_register = None - phase_kickback_ancilla = None - - for term in termList: - if(not QutesDataType.is_array_type(target_symbol.casted_static_type)): - self.quantum_circuit_handler.push_equals_operation(array_register, term.value) - if(len(array_register) == 1): - if(phase_kickback_ancilla == None): - phase_kickback_ancilla = self.quantum_circuit_handler.declare_quantum_register(f"phase_kickback_ancilla_{current_grover_count}", Qubit(0,1)) - oracle_registers.append(phase_kickback_ancilla) - self.quantum_circuit_handler.push_MCZ_operation([*array_register, phase_kickback_ancilla]) - else: - self.quantum_circuit_handler.push_MCZ_operation([*array_register]) - self.quantum_circuit_handler.push_equals_operation(array_register, term.value) - else: - term_to_quantum = QutesDataType.promote_classical_to_quantum_value(term.value) - block_size = target_symbol.value.default_block_size - array_size = int(len(target_symbol.quantum_register)/block_size) - logn = max(int(math.log2(array_size)),1) - if(term_to_quantum.size == 1): - if(phase_kickback_ancilla == None): - phase_kickback_ancilla = self.quantum_circuit_handler.declare_quantum_register(f"phase_kickback_ancilla_{current_grover_count}", Qubit(0,1)) - oracle_registers.append(phase_kickback_ancilla) - if(rotation_register == None): - rotation_register = self.quantum_circuit_handler.declare_quantum_register(f"rotation(grover:{current_grover_count})", Quint.init_from_integer(0,logn,True)) - oracle_registers.append(rotation_register) - if(self.log_grover_verbose): - registers_to_measure.append(rotation_register) - self.quantum_circuit_handler.push_ESM_operation(array_register, rotation_register, term_to_quantum, phase_kickback_ancilla) - - oracle_registers.append(grover_result) - quantum_function = self.quantum_circuit_handler.end_quantum_function(*oracle_registers, gate_name=f"grover_oracle_{current_grover_count}", create_gate=False) - - qubits_involved_in_grover = [*range(quantum_function.num_qubits)] - if(rotation_register != None): - qubits_involved_in_grover = [*range(quantum_function.num_qubits-len(rotation_register)-1, quantum_function.num_qubits-1), quantum_function.num_qubits-1] - - for n_results in range(1, array_size+1): - oracle_result = self.quantum_circuit_handler.push_grover_operation(*oracle_registers, quantum_function=quantum_function, register_involved_indexes=qubits_involved_in_grover, dataset_size=array_size, n_results=n_results, verbose=self.log_grover_verbose) - registers_to_measure.append(oracle_result) - circuit_runs = 3 - self.quantum_circuit_handler.get_run_and_measure_results(registers_to_measure.copy(), repetition=circuit_runs) - - positive_results = [(index, result) for index, result in enumerate(oracle_result.measured_classical_register.measured_values) if "1" in result] - any_positive_results = len(positive_results) > 0 - if (any_positive_results): - if(self.log_grover_verbose and rotation_register.measured_classical_register is not None): - print(f"Solution found with rotation {rotation_register.measured_classical_register.measured_values[positive_results[0][0]]} (for the first hit)") - return True - registers_to_measure.remove(oracle_result) - return False - - # Utility method for logging and scaffolding operation - def __visit(self, parent_caller_name, func, push_pop_scope:bool = False): - if(self.log_trace_enabled): print("start " + parent_caller_name) - if(push_pop_scope): self.scope_handler.push_scope() - result = func() - if(push_pop_scope): self.scope_handler.pop_scope() - if(self.log_trace_enabled): print("end " + parent_caller_name) - if(self.log_step_by_step_results_enabled): print(result) - return result \ No newline at end of file diff --git a/src/grammar_frontend/literal.py b/src/grammar_frontend/literal.py index df55166..64a2631 100644 --- a/src/grammar_frontend/literal.py +++ b/src/grammar_frontend/literal.py @@ -10,101 +10,104 @@ class QutesGrammarLiteralVisitor(QutesBaseVisitor): def __init__(self, symbols_tree:ScopeTreeNode, quantum_circuit_handler : QuantumCircuitHandler, scope_handler:ScopeHandlerForSymbolsUpdate, variables_handler:VariablesHandler, verbose:bool = False): super().__init__(symbols_tree, quantum_circuit_handler, scope_handler, variables_handler, verbose) - # Visit a parse tree produced by qutes_parser#variableType. + def visitType(self, ctx:qutes_parser.TypeContext): + return self.visitChildren(ctx) + + def visitFunctionDeclarationParams(self, ctx:qutes_parser.FunctionDeclarationParamsContext): + param = self.visit(ctx.variableDeclaration()) + params = [] + if(ctx.functionDeclarationParams()): + params = self.visit(ctx.functionDeclarationParams()) + if(not isinstance(params, list)): + params = [params] + params.append(param) + return params[::-1] + + def visitFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): + param = self.visit(ctx.qualifiedName()) + params = [] + if(ctx.functionCallParams()): + params = self.visit(ctx.functionCallParams()) + if(not isinstance(params, list)): + params = [params] + params.append(param) + return params[::-1] + + def visitTermList(self, ctx:qutes_parser.TermListContext): + term = self.visit(ctx.literal()) + terms = [] + if(ctx.termList()): + terms = self.visit(ctx.termList()) + if(not isinstance(terms, list)): + terms = [terms] + terms.append(term) + return terms[::-1] + def visitVariableType(self, ctx:qutes_parser.VariableTypeContext): value = str(ctx.getText()) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitVariableType", lambda : value) - + return value - # Visit a parse tree produced by qutes_parser#qualifiedName. def visitQualifiedName(self, ctx:qutes_parser.QualifiedNameContext): var_name = str(ctx.getText()) token_index = ctx.start.tokenIndex symbol_to_resolve = self.variables_handler.get_variable_symbol(var_name, token_index) if(self.log_code_structure): print(symbol_to_resolve, end=None) - return self.__visit("visitQualifiedName", lambda : self.variables_handler.get_variable_symbol(var_name, token_index)) - + return self.variables_handler.get_variable_symbol(var_name, token_index) - # Visit a parse tree produced by qutes_parser#functionName. def visitFunctionName(self, ctx:qutes_parser.FunctionNameContext): #TODO: this should be aligned to visitQualifiedName which returns a symbol value = str(ctx.getText()) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitFunctionName", lambda : value) + return value + def visitLiteral(self, ctx:qutes_parser.LiteralContext): + return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#id. def visitString(self, ctx:qutes_parser.StringContext): string_literal_enclosure = qutes_parser.literal_to_string(qutes_parser.STRING_ENCLOSURE) value = ctx.getText().removeprefix(string_literal_enclosure).removesuffix(string_literal_enclosure) symbol = self.variables_handler.create_anonymous_symbol(QutesDataType.string, value, ctx.start.tokenIndex) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitString", lambda : symbol) + return symbol - - # Visit a parse tree produced by qutes_parser#qubit. def visitQubit(self, ctx:qutes_parser.QubitContext): value = Qubit.from_string(ctx.getText()) symbol = self.variables_handler.create_anonymous_symbol(QutesDataType.qubit, value, ctx.start.tokenIndex) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitQubit", lambda : symbol) + return symbol - - # Visit a parse tree produced by qutes_parser#quint. def visitQuint(self, ctx:qutes_parser.QuintContext): value = Quint.init_from_string(ctx.getText()) symbol = self.variables_handler.create_anonymous_symbol(QutesDataType.quint, value, ctx.start.tokenIndex) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitQuint", lambda : symbol) + return symbol - - # Visit a parse tree produced by qutes_parser#qustring. def visitQustring(self, ctx:qutes_parser.QustringContext): value = Qustring.init_from_string(ctx.getText()) symbol = self.variables_handler.create_anonymous_symbol(QutesDataType.qustring, value, ctx.start.tokenIndex) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitQustring", lambda : symbol) + return symbol - - # Visit a parse tree produced by qutes_parser#float. def visitFloat(self, ctx:qutes_parser.FloatContext): value = float(ctx.getText()) symbol = self.variables_handler.create_anonymous_symbol(QutesDataType.float, value, ctx.start.tokenIndex) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitFloat", lambda : symbol) + return symbol - - # Visit a parse tree produced by qutes_parser#integer. def visitInteger(self, ctx:qutes_parser.IntegerContext): value = int(ctx.getText()) symbol = self.variables_handler.create_anonymous_symbol(QutesDataType.int, value, ctx.start.tokenIndex) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitInteger", lambda : symbol) - + return symbol - # Visit a parse tree produced by qutes_parser#boolean. def visitBoolean(self, ctx:qutes_parser.BooleanContext): value = ctx.getText().lower() == "true" or ctx.getText() == "1" symbol = self.variables_handler.create_anonymous_symbol(QutesDataType.bool, value, ctx.start.tokenIndex) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitBoolean", lambda : symbol) + return symbol - # Visit a parse tree produced by qutesParser#integer. def visitVariableName(self, ctx:qutes_parser.VariableNameContext): value = str(ctx.getText()) if(self.log_code_structure): print(value, end=None) - return self.__visit("visitVariableName", lambda : value) - - def visitType(self, ctx:qutes_parser.TypeContext): - return self.visitChildren(ctx) - - # Utility method for logging and scaffolding operation - def __visit(self, parent_caller_name, func, push_pop_scope:bool = False): - if(self.log_trace_enabled): print("start " + parent_caller_name) - if(push_pop_scope): self.scope_handler.push_scope() - result = func() - if(push_pop_scope): self.scope_handler.pop_scope() - if(self.log_trace_enabled): print("end " + parent_caller_name) - if(self.log_step_by_step_results_enabled): print(result) - return result \ No newline at end of file + return value diff --git a/src/grammar_frontend/operation.py b/src/grammar_frontend/operation.py index 48bb7af..6d7eb27 100644 --- a/src/grammar_frontend/operation.py +++ b/src/grammar_frontend/operation.py @@ -6,64 +6,126 @@ from symbols.types import Qustring, QutesDataType from quantum_circuit import QuantumCircuitHandler from grammar_frontend.qutes_base_visitor import QutesBaseVisitor +from symbols.types import Qubit, Quint, QutesDataType +import math class QutesGrammarOperationVisitor(QutesBaseVisitor): def __init__(self, symbols_tree:ScopeTreeNode, quantum_circuit_handler : QuantumCircuitHandler, scope_handler:ScopeHandlerForSymbolsUpdate, variables_handler:VariablesHandler, verbose:bool = False): super().__init__(symbols_tree, quantum_circuit_handler, scope_handler, variables_handler, verbose) + + def visitPostfixOperator(self, ctx:qutes_parser.PostfixOperatorContext): + return self.__visit_unary_operator(ctx) - # Visit a parse tree produced by qutes_parser#test. - def visitTest(self, ctx:qutes_parser.TestContext): - return self.__visit("visitTest", lambda : self.__visit_test(ctx)) + def visitPrefixOperator(self, ctx:qutes_parser.PrefixOperatorContext): + return self.__visit_unary_operator(ctx) + + def visitMultiplicativeOperator(self, ctx:qutes_parser.MultiplicativeOperatorContext): + return self.__visit_binary_operator(ctx) - def __visit_test(self, ctx:qutes_parser.TestContext): + def visitSumOperator(self, ctx:qutes_parser.SumOperatorContext): + return self.__visit_binary_operator(ctx) + + def visitRelationalOperator(self, ctx:qutes_parser.RelationalOperatorContext): + return self.__visit_boolean_operation(ctx) + + def visitEqualityOperator(self, ctx:qutes_parser.EqualityOperatorContext): + return self.__visit_boolean_operation(ctx) + + def visitLogicAndOperator(self, ctx:qutes_parser.LogicAndOperatorContext): + return self.__visit_boolean_operation(ctx) + + def visitLogicOrOperator(self, ctx:qutes_parser.LogicOrOperatorContext): + return self.__visit_boolean_operation(ctx) + + def visitMultipleUnaryOperator(self, ctx:qutes_parser.MultipleUnaryOperatorContext): + return self.__visitMultipleUnaryOperator(ctx) + + def visitUnaryOperator(self, ctx:qutes_parser.UnaryOperatorContext): + return self.__visit_unary_operator(ctx) + + def visitMultipleUnaryPhaseOperator(self, ctx:qutes_parser.MultipleUnaryPhaseOperatorContext): + return self.__visitMultipleUnaryPhaseOperator(ctx) + + def __visit_binary_operator(self, ctx:qutes_parser.SumOperatorContext | qutes_parser.MultiplicativeOperatorContext | qutes_parser.RelationalOperatorContext | qutes_parser.EqualityOperatorContext | qutes_parser.LogicAndOperatorContext | qutes_parser.LogicOrOperatorContext): result = None - first_term_symbol = self.visitChildren(ctx.term(0)) - second_term_symbol = self.visitChildren(ctx.term(1)) + first_term_symbol = self.visitChildren(ctx.expr(0)) + second_term_symbol = self.visitChildren(ctx.expr(1)) first_term = self.variables_handler.get_value(first_term_symbol) second_term = self.variables_handler.get_value(second_term_symbol) - if(ctx.GREATER()): - if(self.log_code_structure): print(f"{first_term_symbol} > {second_term_symbol}", end=None) - if(self.log_trace_enabled): print("visitTest -> greater") - result = first_term > second_term - elif(ctx.LOWER()): - if(self.log_code_structure): print(f"{first_term_symbol} < {second_term_symbol}", end=None) - if(self.log_trace_enabled): print("visitTest -> lower") - result = first_term < second_term - elif(ctx.EQUAL()): - if(self.log_code_structure): print(f"{first_term_symbol} == {second_term_symbol}", end=None) - if(self.log_trace_enabled): print("visitTest -> equal") - if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type) - and second_term_symbol and not QutesDataType.is_quantum_type(second_term_symbol.symbol_declaration_static_type)): - # At the moment this only works for comparing quantum variables to classical values. - result = self.quantum_circuit_handler.push_equals_operation(first_term_symbol.quantum_register, second_term_symbol.value) - else: - result = first_term == second_term - elif(ctx.GREATEREQUAL()): - if(self.log_code_structure): print(f"{first_term_symbol} >= {second_term_symbol}", end=None) - if(self.log_trace_enabled): print("visitTest -> greater equal") - result = first_term >= second_term - elif(ctx.LOWEREQUAL()): - if(self.log_code_structure): print(f"{first_term_symbol} <= {second_term_symbol}", end=None) - if(self.log_trace_enabled): print("visitTest -> lower equal") - result = first_term <= second_term - else: - if(self.log_code_structure): print(f"{first_term_symbol}", end=None) - if(self.log_trace_enabled): print("visitTest -> test no operator") - result = first_term + if(self.log_code_structure): print(f"{first_term_symbol} {ctx.op.text} {second_term_symbol}", end=None) + + if(isinstance(ctx, qutes_parser.SumOperatorContext)): + if(ctx.ADD()): + if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type) + and second_term_symbol and QutesDataType.is_quantum_type(second_term_symbol.symbol_declaration_static_type)): + #TODO: we should measure the circuit and assign the value to the result variable. + #But we don't want to measure the circuit at every operation, so we need to return a kind of promise + #Promise that will be measured only when needed + #At first i was thinking about measure on assignment, but that is not actually needed, + #We can measure only when classical computation is required + #Or when explicitly required by the user. + result = self.qutes_gates.sum(first_term_symbol, second_term_symbol) + else: + result = first_term + second_term + if(ctx.SUB()): + if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): + #TODO: handle sub operation of quantum variables + pass + result = first_term - second_term + if(isinstance(ctx, qutes_parser.MultiplicativeOperatorContext)): + if(ctx.MULTIPLY()): + if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): + #TODO: handle multiply operation of quantum variables + pass + result = first_term * second_term + if(ctx.DIVIDE()): + if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): + #TODO: handle divide operation of quantum variables + pass + result = first_term / second_term return result + + def __visit_boolean_operation(self, ctx:qutes_parser.RelationalOperatorContext | qutes_parser.EqualityOperatorContext | qutes_parser.LogicAndOperatorContext | qutes_parser.LogicOrOperatorContext): + result = None + first_term_symbol = self.visitChildren(ctx.expr(0)) + second_term_symbol = self.visitChildren(ctx.expr(1)) + first_term = self.variables_handler.get_value(first_term_symbol) + second_term = self.variables_handler.get_value(second_term_symbol) - # Visit a parse tree produced by qutes_parser#MultipleUnaryPhaseOperator. - def visitMultipleUnaryPhaseOperator(self, ctx:qutes_parser.MultipleUnaryPhaseOperatorContext): - return self.__visit("visitMultipleUnaryPhaseOperator", lambda : self.__visitMultipleUnaryPhaseOperator(ctx)) + if(self.log_code_structure): print(f"{first_term_symbol} {ctx.op.text} {second_term_symbol}", end=None) - # Visit a parse tree produced by qutes_parser#MultipleUnaryOperator. - def visitMultipleUnaryOperator(self, ctx:qutes_parser.MultipleUnaryOperatorContext): - return self.__visit("visitMultipleUnaryOperator", lambda : self.__visitMultipleUnaryOperator(ctx)) + if(isinstance(ctx, qutes_parser.EqualityOperatorContext)): + if(ctx.EQUAL()): + if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type) + and second_term_symbol and not QutesDataType.is_quantum_type(second_term_symbol.symbol_declaration_static_type)): + # At the moment this only works for comparing quantum variables to classical values. + result = self.quantum_circuit_handler.push_equals_operation(first_term_symbol.quantum_register, second_term_symbol.value) + else: + result = first_term == second_term + if(ctx.NOT_EQUAL()): + result = first_term != second_term + elif(isinstance(ctx, qutes_parser.RelationalOperatorContext)): + if(ctx.GREATER()): + result = first_term > second_term + elif(ctx.LOWER()): + result = first_term < second_term + elif(ctx.GREATEREQUAL()): + result = first_term >= second_term + elif(ctx.LOWEREQUAL()): + result = first_term <= second_term + elif(isinstance(ctx, qutes_parser.LogicAndOperatorContext)): + if(ctx.AND()): + result = first_term and second_term + elif(isinstance(ctx, qutes_parser.LogicOrOperatorContext)): + if(ctx.OR()): + result = first_term or second_term + return result def __visitMultipleUnaryOperator(self, ctx:qutes_parser.MultipleUnaryOperatorContext): terms:list[Symbol] = self.visit(ctx.termList()) registers = [register.quantum_register for register in terms] + if(self.log_code_structure): print(f"{ctx.op.text} {registers}", end=None) if(ctx.MCZ()): self.quantum_circuit_handler.push_MCZ_operation(registers) if(ctx.MCX()): @@ -72,78 +134,26 @@ def __visitMultipleUnaryOperator(self, ctx:qutes_parser.MultipleUnaryOperatorCon self.quantum_circuit_handler.push_MCY_operation(registers) if(ctx.SWAP()): self.quantum_circuit_handler.push_swap_operation(registers[0], registers[1]) + return None def __visitMultipleUnaryPhaseOperator(self, ctx:qutes_parser.MultipleUnaryPhaseOperatorContext): terms:list[Symbol] = self.visit(ctx.termList()) registers = [register.quantum_register for register in terms] + theta = self.visit(ctx.expr()) + if(self.log_code_structure): print(f"{ctx.op.text} {registers} by {theta}", end=None) if(ctx.MCP()): - theta = self.visit(ctx.expr()) self.quantum_circuit_handler.push_MCP_operation(theta, registers) + return None - # Visit a parse tree produced by qutes_parser#termList. - def visitTermList(self, ctx:qutes_parser.TermListContext): - term = self.visit(ctx.term()) - terms = [] - if(ctx.termList()): - terms = self.__visit("visitTermList", lambda : self.visit(ctx.termList())) - if(not isinstance(terms, list)): - terms = [terms] - terms.append(term) - return terms[::-1] - - # Visit a parse tree produced by qutes_parser#IdentityOperator. - def visitIdentityOperator(self, ctx:qutes_parser.IdentityOperatorContext): - result = self.__visit_identity_operator(ctx) - if(self.log_code_structure): print(result, end=None) - return self.__visit("visitIdentityOperator", lambda : result) - - def __visit_identity_operator(self, ctx:qutes_parser.IdentityOperatorContext): - result = self.visitChildren(ctx) - if(ctx.boolean()): - if(self.log_trace_enabled): print("visitTerm -> boolean") - if(ctx.integer()): - if(self.log_trace_enabled): print("visitTerm -> integer") - if(ctx.float_()): - if(self.log_trace_enabled): print("visitTerm -> float") - if(ctx.qubit()): - if(self.log_trace_enabled): print("visitTerm -> qubit") - if(ctx.quint()): - if(self.log_trace_enabled): print("visitTerm -> quint") - if(ctx.qustring()): - if(self.log_trace_enabled): print("visitTerm -> qustring") - if(ctx.qualifiedName()): - if(self.log_trace_enabled): print("visitTerm -> qualifiedName") - if(ctx.string()): - if(self.log_trace_enabled): print("visitTerm -> string") - if(ctx.MEASURE()): - if(self.log_trace_enabled): print("visitTerm -> measure") - self.quantum_circuit_handler.push_measure_operation() - if(ctx.BARRIER()): - if(self.log_trace_enabled): print("visitTerm -> barrier") - self.quantum_circuit_handler.push_barrier_operation() - return result - - - # Visit a parse tree produced by qutes_parser#UnaryOperator. - def visitUnaryOperator(self, ctx:qutes_parser.UnaryOperatorContext): - return self.__visit("visitUnaryOperator", lambda : self.__visit_unary_operator(ctx)) - - def __visit_unary_operator(self, ctx:qutes_parser.UnaryOperatorContext): + def __visit_unary_operator(self, ctx:qutes_parser.UnaryOperatorContext | qutes_parser.PrefixOperatorContext | qutes_parser.PostfixOperatorContext): result = None - if(ctx.term()): - if(self.log_trace_enabled): print("visitTerm -> unary operation") - first_term = self.visitChildren(ctx.term()) - first_term_symbol : Symbol | None = None - - if(isinstance(first_term, Symbol)): - first_term_symbol = first_term - first_term = first_term.value + first_term_symbol = self.visitChildren(ctx.expr()) + first_term = self.variables_handler.get_value(first_term_symbol) - first_term_print = f"{first_term if first_term_symbol == None else first_term_symbol}" + if(self.log_code_structure): print(f"{first_term_symbol} {ctx.op.text}", end=None) + if(isinstance(ctx, qutes_parser.UnaryOperatorContext)): if(ctx.PRINT()): - if(self.log_code_structure): print(f"print {first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> PRINT") if(first_term_symbol): if(QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): classical_register = self.quantum_circuit_handler.run_and_measure([first_term_symbol.quantum_register]) @@ -165,115 +175,112 @@ def __visit_unary_operator(self, ctx:qutes_parser.UnaryOperatorContext): print(first_term_symbol) else: print(first_term) - if(ctx.ADD()): - if(self.log_code_structure): print(f"+{first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> ADD") - if(ctx.SUB()): - if(self.log_code_structure): print(f"-{first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> SUB") - if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): - result = self.quantum_circuit_handler.push_pauliz_operation(first_term_symbol.quantum_register) - result = -first_term - if(ctx.NOT()): - if(self.log_code_structure): print(f"NOT{first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> NOT") - if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): - result = self.quantum_circuit_handler.push_not_operation(first_term_symbol.quantum_register) - else: - result = not first_term if(ctx.PAULIY()): - if(self.log_code_structure): print(f"NOT{first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> NOT") if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): result = self.quantum_circuit_handler.push_pauliy_operation(first_term_symbol.quantum_register) if(ctx.PAULIZ()): - if(self.log_code_structure): print(f"PAULIZ{first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> PAULIZ") if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): result = self.quantum_circuit_handler.push_pauliz_operation(first_term_symbol.quantum_register) if(ctx.HADAMARD()): - if(self.log_code_structure): print(f"HADAMARD{first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> HADAMARD") if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): result = self.quantum_circuit_handler.push_hadamard_operation(first_term_symbol.quantum_register) if(ctx.MEASURE()): - if(self.log_code_structure): print(f"MEASURE{first_term_print}", end=None) - if(self.log_trace_enabled): print("visitUnaryOperator -> MEASURE") if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): result = self.quantum_circuit_handler.push_measure_operation([first_term_symbol.quantum_register]) + if(isinstance(ctx, qutes_parser.PrefixOperatorContext)): + if(ctx.ADD()): + pass + if(ctx.SUB()): + if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): + result = self.quantum_circuit_handler.push_pauliz_operation(first_term_symbol.quantum_register) + result = -first_term + if(ctx.AUTO_INCREMENT()): + #TODO: handle quantum + result = first_term + 1 + if(ctx.AUTO_DECREMENT()): + #TODO: handle quantum + result = first_term - 1 + if(ctx.NOT()): + if(self.log_trace_enabled): print("visitUnaryOperator -> NOT") + if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): + result = self.quantum_circuit_handler.push_not_operation(first_term_symbol.quantum_register) + else: + result = not first_term + if(isinstance(ctx, qutes_parser.PostfixOperatorContext)): + #TODO: handle quantum + #TODO: handle postfix expected behaviour + if(ctx.AUTO_INCREMENT()): + result = first_term + 1 + if(ctx.AUTO_DECREMENT()): + result = first_term - 1 return result + grover_count = iter(range(1, 1000)) + def visitGroverOperator(self, ctx:qutes_parser.GroverOperatorContext): + current_grover_count = next(self.grover_count) + target_symbol:Symbol = self.visit(ctx.qualifiedName()) + if(not QutesDataType.is_quantum_type(target_symbol.casted_static_type)): + #TODO: Handle promotion to quantum type? + return None + if(ctx.IN_STATEMENT()): + array_register = target_symbol.quantum_register + self.quantum_circuit_handler.start_quantum_function() + termList:list[Symbol] = self.visit(ctx.termList()) + array_size = len(target_symbol.quantum_register) - # Visit a parse tree produced by qutes_parser#BinaryPriorityOperator. - def visitBinaryPriorityOperator(self, ctx:qutes_parser.BinaryPriorityOperatorContext): - return self.__visit("visitBinaryPriorityOperator", lambda : self.__visit_binary_operator(ctx)) - - # Visit a parse tree produced by qutes_parser#BinaryOperator. - def visitBinaryOperator(self, ctx:qutes_parser.BinaryOperatorContext): - return self.__visit("visitBinaryOperator", lambda : self.__visit_binary_operator(ctx)) - - def __visit_binary_operator(self, ctx:qutes_parser.BinaryOperatorContext|qutes_parser.BinaryPriorityOperatorContext): - result = None - if(ctx.term(0) and ctx.term(1)): - if(self.log_trace_enabled): print("visitTerm -> binary operation") - first_term = self.visitChildren(ctx.term(0)) - second_term = self.visitChildren(ctx.term(1)) - first_term_symbol : Symbol | None = None - second_term_symbol : Symbol | None = None + grover_result = self.quantum_circuit_handler.declare_quantum_register("grover_phase_ancilla", Qubit()) + oracle_registers = [array_register] + registers_to_measure = [] + if(self.log_grover_verbose): + registers_to_measure.append(array_register) + rotation_register = None + phase_kickback_ancilla = None - if(isinstance(first_term, Symbol)): - first_term_symbol = first_term - first_term = first_term.value - if(isinstance(second_term, Symbol)): - second_term_symbol = second_term - second_term = second_term.value + for term in termList: + if(not QutesDataType.is_array_type(target_symbol.casted_static_type)): + self.quantum_circuit_handler.push_equals_operation(array_register, term.value) + if(len(array_register) == 1): + if(phase_kickback_ancilla == None): + phase_kickback_ancilla = self.quantum_circuit_handler.declare_quantum_register(f"phase_kickback_ancilla_{current_grover_count}", Qubit(0,1)) + oracle_registers.append(phase_kickback_ancilla) + self.quantum_circuit_handler.push_MCZ_operation([*array_register, phase_kickback_ancilla]) + else: + self.quantum_circuit_handler.push_MCZ_operation([*array_register]) + self.quantum_circuit_handler.push_equals_operation(array_register, term.value) + else: + term_to_quantum = QutesDataType.promote_classical_to_quantum_value(term.value) + block_size = target_symbol.value.default_block_size + array_size = int(len(target_symbol.quantum_register)/block_size) + logn = max(int(math.log2(array_size)),1) + if(term_to_quantum.size == 1): + if(phase_kickback_ancilla == None): + phase_kickback_ancilla = self.quantum_circuit_handler.declare_quantum_register(f"phase_kickback_ancilla_{current_grover_count}", Qubit(0,1)) + oracle_registers.append(phase_kickback_ancilla) + if(rotation_register == None): + rotation_register = self.quantum_circuit_handler.declare_quantum_register(f"rotation(grover:{current_grover_count})", Quint.init_from_integer(0,logn,True)) + oracle_registers.append(rotation_register) + if(self.log_grover_verbose): + registers_to_measure.append(rotation_register) + self.quantum_circuit_handler.push_ESM_operation(array_register, rotation_register, term_to_quantum, phase_kickback_ancilla) + + oracle_registers.append(grover_result) + quantum_function = self.quantum_circuit_handler.end_quantum_function(*oracle_registers, gate_name=f"grover_oracle_{current_grover_count}", create_gate=False) - first_term_print = f"{first_term if first_term_symbol == None else first_term_symbol}" - second_term_print = f"{second_term if second_term_symbol == None else second_term_symbol}" + qubits_involved_in_grover = [*range(quantum_function.num_qubits)] + if(rotation_register != None): + qubits_involved_in_grover = [*range(quantum_function.num_qubits-len(rotation_register)-1, quantum_function.num_qubits-1), quantum_function.num_qubits-1] - if(isinstance(ctx, qutes_parser.BinaryOperatorContext) and ctx.ADD()): - if(self.log_code_structure): print(f"{first_term_print} + {second_term_print}", end=None) - if(self.log_trace_enabled): print("visitBinaryOperator -> ADD") - if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type) - and second_term_symbol and QutesDataType.is_quantum_type(second_term_symbol.symbol_declaration_static_type)): - #TODO: we should measure the circuit and assign the value to the result variable. - #But we don't want to measure the circuit at every operation, so we need to return a kind of promise - #Promise that will be measured only when needed - #At first i was thinking about measure on assignment, but that is not actually needed, - #We can measure only when classical computation is required - #Or when explicitly required by the user. - result = self.qutes_gates.sum(first_term_symbol, second_term_symbol) - else: - result = first_term + second_term - if(isinstance(ctx, qutes_parser.BinaryOperatorContext) and ctx.SUB()): - if(self.log_code_structure): print(f"{first_term_print} - {second_term_print}", end=None) - if(self.log_trace_enabled): print("visitBinaryOperator -> SUB") - if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): - #TODO: handle sub operation of quantum variables - pass - result = first_term - second_term - if(isinstance(ctx, qutes_parser.BinaryPriorityOperatorContext) and ctx.MULTIPLY()): - if(self.log_code_structure): print(f"{first_term_print} - {second_term_print}", end=None) - if(self.log_trace_enabled): print("visitBinaryOperator -> SUB") - if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): - #TODO: handle multiply operation of quantum variables - pass - result = first_term * second_term - if(isinstance(ctx, qutes_parser.BinaryPriorityOperatorContext) and ctx.DIVIDE()): - if(self.log_code_structure): print(f"{first_term_print} - {second_term_print}", end=None) - if(self.log_trace_enabled): print("visitBinaryOperator -> SUB") - if (first_term_symbol and QutesDataType.is_quantum_type(first_term_symbol.symbol_declaration_static_type)): - #TODO: handle divide operation of quantum variables - pass - result = first_term / second_term - return result + for n_results in range(1, array_size+1): + oracle_result = self.quantum_circuit_handler.push_grover_operation(*oracle_registers, quantum_function=quantum_function, register_involved_indexes=qubits_involved_in_grover, dataset_size=array_size, n_results=n_results, verbose=self.log_grover_verbose) + registers_to_measure.append(oracle_result) + circuit_runs = 3 + self.quantum_circuit_handler.get_run_and_measure_results(registers_to_measure.copy(), repetition=circuit_runs) - # Utility method for logging and scaffolding operation - def __visit(self, parent_caller_name, func, push_pop_scope:bool = False): - if(self.log_trace_enabled): print("start " + parent_caller_name) - if(push_pop_scope): self.scope_handler.push_scope() - result = func() - if(push_pop_scope): self.scope_handler.pop_scope() - if(self.log_trace_enabled): print("end " + parent_caller_name) - if(self.log_step_by_step_results_enabled): print(result) - return result \ No newline at end of file + positive_results = [(index, result) for index, result in enumerate(oracle_result.measured_classical_register.measured_values) if "1" in result] + any_positive_results = len(positive_results) > 0 + if (any_positive_results): + if(self.log_grover_verbose and rotation_register.measured_classical_register is not None): + print(f"Solution found with rotation {rotation_register.measured_classical_register.measured_values[positive_results[0][0]]} (for the first hit)") + return True + registers_to_measure.remove(oracle_result) + return False diff --git a/src/grammar_frontend/statement.py b/src/grammar_frontend/statement.py index 8c07d17..f36dd08 100644 --- a/src/grammar_frontend/statement.py +++ b/src/grammar_frontend/statement.py @@ -11,11 +11,7 @@ class QutesGrammarStatementVisitor(QutesBaseVisitor): def __init__(self, symbols_tree:ScopeTreeNode, quantum_circuit_handler : QuantumCircuitHandler, scope_handler:ScopeHandlerForSymbolsUpdate, variables_handler:VariablesHandler, verbose:bool = False): super().__init__(symbols_tree, quantum_circuit_handler, scope_handler, variables_handler, verbose) - #Visit a parse tree produced by qutesParser#IfStatement. def visitIfStatement(self, ctx:qutes_parser.IfStatementContext): - return self.__visit_if_statement(ctx) - - def __visit_if_statement(self, ctx:qutes_parser.IfStatementContext): self.scope_handler.push_scope() condition = self.visitChildren(ctx.expr()) if(condition != None): @@ -27,12 +23,8 @@ def __visit_if_statement(self, ctx:qutes_parser.IfStatementContext): self.scope_handler.pop_scope() self.scope_handler.pop_scope() return None - - # Visit a parse tree produced by qutesParser#IfElseStatement. - def visitIfElseStatement(self, ctx:qutes_parser.IfElseStatementContext): - return self.__visit("visitIfElseStatement", lambda : self.__visit_if_else_statement(ctx)) - def __visit_if_else_statement(self, ctx:qutes_parser.IfStatementContext): + def visitIfElseStatement(self, ctx:qutes_parser.IfElseStatementContext): self.scope_handler.push_scope() condition = self.visitChildren(ctx.expr()) if(condition != None): @@ -49,12 +41,10 @@ def __visit_if_else_statement(self, ctx:qutes_parser.IfStatementContext): self.scope_handler.pop_scope() self.visit(ctx.statement(1)) self.scope_handler.pop_scope() - return None + return None - - # Visit a parse tree produced by qutesParser#WhileStatement. def visitWhileStatement(self, ctx:qutes_parser.WhileStatementContext): - return self.__visit("visitWhileStatement", lambda : self.__visit_while_statement(ctx)) + return self.__visit_while_statement(ctx) def __visit_while_statement(self, ctx:qutes_parser.IfStatementContext): self.scope_handler.push_scope() @@ -79,31 +69,24 @@ def __visit_while_statement(self, ctx:qutes_parser.IfStatementContext): return None - # Visit a parse tree produced by qutesParser#DoWhileStatement. def visitDoWhileStatement(self, ctx:qutes_parser.DoWhileStatementContext): - return self.__visit("visitDoWhileStatement", lambda : self.visitChildren(ctx)) + #TODO: implement + return self.visitChildren(ctx) - # Visit a parse tree produced by qutesParser#BlockStatement. def visitBlockStatement(self, ctx:qutes_parser.BlockStatementContext): self.scope_handler.push_scope() - result = self.__visit("visitBlockStatement", lambda : self.__visitBlock(ctx)) - self.scope_handler.pop_scope() - return result - - # Visit a parse tree produced by qutes_parser#block. - def __visitBlock(self, ctx:qutes_parser.BlockStatementContext): log_string = str() statement_count = 0 for child in ctx.getChildren(lambda child : isinstance(child, qutes_parser.StatementContext)): statement_count += 1 - new_value = self.__visit("visitBlockStatement", lambda i=child : self.visit(i)) + new_value = self.visit(child) log_string = f'{log_string}\n\tStatement[{statement_count}]: {new_value}' if(self.log_code_structure): print(log_string, end=None) if(isinstance(new_value, Symbol) and new_value.is_return_value_of_function): return new_value + self.scope_handler.pop_scope() return None - # Visit a parse tree produced by qutes_parser#FunctionStatement. def visitFunctionStatement(self, ctx:qutes_parser.FunctionStatementContext): self.scope_handler.push_scope() function_name = self.visit(ctx.functionName()) @@ -113,36 +96,19 @@ def visitFunctionStatement(self, ctx:qutes_parser.FunctionStatementContext): self.scope_handler.pop_scope() return None - # Visit a parse tree produced by qutes_parser#functionParams. - def visitFunctionDeclarationParams(self, ctx:qutes_parser.FunctionDeclarationParamsContext): - param = self.visit(ctx.variableDeclaration()) - params = [] - if(ctx.functionDeclarationParams()): - params = self.__visit("functionDeclarationParams", lambda : self.visit(ctx.functionDeclarationParams())) - if(not isinstance(params, list)): - params = [params] - params.append(param) - return params[::-1] - - # Visit a parse tree produced by qutesParser#DeclarationStatement. def visitDeclarationStatement(self, ctx:qutes_parser.DeclarationStatementContext): - return self.__visit("visitDeclarationStatement", lambda : self.visitChildren(ctx)) + return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#variableDeclaration. def visitVariableDeclaration(self, ctx:qutes_parser.VariableDeclarationContext): var_type = self.visit(ctx.variableType()) # we already know the variable type thanks to the discovery listener. var_name = self.visit(ctx.variableName()) var_value = None + return self.__visit_assignment_statement(var_name, var_value, ctx) - return self.__visit("visitVariableDeclaration", lambda : self.__visit_assignment_statement(var_name, var_value, ctx)) - - - # Visit a parse tree produced by qutesParser#AssignmentStatement. def visitAssignmentStatement(self, ctx:qutes_parser.AssignmentStatementContext): var_name = self.visit(ctx.qualifiedName()) var_value = None - return self.__visit("visitAssignmentStatement", lambda : self.__visit_assignment_statement(var_name, var_value, ctx)) - + return self.__visit_assignment_statement(var_name, var_value, ctx) def __visit_assignment_statement(self, var_name : str | Symbol, var_value, ctx:(qutes_parser.AssignmentStatementContext | qutes_parser.VariableDeclarationContext)): if(ctx.expr()): @@ -168,27 +134,23 @@ def __visit_assignment_statement(self, var_name : str | Symbol, var_value, ctx:( if(self.log_code_structure): print(f"{var_symbol.symbol_declaration_static_type.name} {str(var_name)}", end=None) return var_symbol - # Visit a parse tree produced by qutes_parser#ReturnStatement. def visitReturnStatement(self, ctx:qutes_parser.ReturnStatementContext): - result = self.__visit("visitReturnStatement", lambda : self.visitChildren(ctx.expr())) + result = self.visitChildren(ctx.expr()) if(isinstance(result, Symbol)): result.is_return_value_of_function = True return result - # Visit a parse tree produced by qutesParser#ExpressionStatement. def visitExpressionStatement(self, ctx:qutes_parser.ExpressionStatementContext): - return self.__visit("visitExpressionStatement", lambda : self.visitChildren(ctx.expr())) + return self.visitChildren(ctx) + + def visitFactStatement(self, ctx:qutes_parser.FactStatementContext): + if(self.log_code_structure): print(f"{ctx.op.text}", end=None) + + if(ctx.MEASURE()): + self.quantum_circuit_handler.push_measure_operation() + if(ctx.BARRIER()): + self.quantum_circuit_handler.push_barrier_operation() + return self.visitChildren(ctx) - # Visit a parse tree produced by qutesParser#EmptyStatement. def visitEmptyStatement(self, ctx:qutes_parser.EmptyStatementContext): - return self.__visit("visitEmptyStatement", lambda : self.visitChildren(ctx)) - - # Utility method for logging and scaffolding operation - def __visit(self, parent_caller_name, func, push_pop_scope:bool = False): - if(self.log_trace_enabled): print("start " + parent_caller_name) - if(push_pop_scope): self.scope_handler.push_scope() - result = func() - if(push_pop_scope): self.scope_handler.pop_scope() - if(self.log_trace_enabled): print("end " + parent_caller_name) - if(self.log_step_by_step_results_enabled): print(result) - return result \ No newline at end of file + return self.visitChildren(ctx) diff --git a/src/quantum_circuit/qutes_gates.py b/src/quantum_circuit/qutes_gates.py index 7c1d829..b5e2394 100644 --- a/src/quantum_circuit/qutes_gates.py +++ b/src/quantum_circuit/qutes_gates.py @@ -41,6 +41,7 @@ def __full_adder_gate(self): return gate_add def sum(self, var_a_symbol:'Symbol', var_b_symbol:'Symbol') -> 'Symbol': + #TODO: this should be a push_sum_operation in circuit handler? self.count+=1 handler = self.ciruit_handler diff --git a/src/qutes_antlr/qutes_lexer.py b/src/qutes_antlr/qutes_lexer.py index bf0255a..28cce84 100644 --- a/src/qutes_antlr/qutes_lexer.py +++ b/src/qutes_antlr/qutes_lexer.py @@ -10,7 +10,7 @@ def serializedATN(): return [ - 4,0,64,587,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, + 4,0,75,645,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2, 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7, 19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2, @@ -20,215 +20,236 @@ def serializedATN(): 45,2,46,7,46,2,47,7,47,2,48,7,48,2,49,7,49,2,50,7,50,2,51,7,51,2, 52,7,52,2,53,7,53,2,54,7,54,2,55,7,55,2,56,7,56,2,57,7,57,2,58,7, 58,2,59,7,59,2,60,7,60,2,61,7,61,2,62,7,62,2,63,7,63,2,64,7,64,2, - 65,7,65,2,66,7,66,2,67,7,67,2,68,7,68,2,69,7,69,1,0,1,0,1,0,1,0, - 1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3, - 1,3,1,3,1,4,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5, - 1,5,1,6,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8, - 1,8,1,8,1,8,1,9,1,9,1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,13,1,13, - 1,13,1,14,1,14,1,14,1,15,1,15,1,15,1,15,1,15,1,16,1,16,1,16,1,16, - 1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,18,1,18,1,18, - 1,18,1,18,1,18,1,18,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,21, - 1,21,1,21,1,21,1,22,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,23,1,23, - 1,23,1,23,1,23,1,24,1,24,1,24,1,24,1,24,1,24,1,24,1,24,1,25,1,25, - 1,25,1,25,1,25,1,25,1,26,1,26,1,26,1,26,1,26,1,26,1,26,1,26,1,27, - 1,27,1,27,1,28,1,28,1,29,1,29,1,29,1,30,1,30,1,31,1,31,1,31,1,32, - 1,32,1,33,1,33,1,34,1,34,1,34,1,34,1,35,1,35,1,35,1,35,1,36,1,36, - 1,36,1,36,1,36,1,36,1,36,1,37,1,37,1,37,1,38,1,38,1,38,1,38,1,38, - 1,38,1,39,1,39,1,39,1,40,1,40,1,40,1,40,1,40,1,41,1,41,1,41,1,41, - 1,41,1,41,1,42,1,42,1,42,1,43,1,43,1,44,1,44,1,45,1,45,1,46,1,46, - 1,47,1,47,1,48,1,48,1,49,1,49,1,50,1,50,1,51,1,51,1,52,1,52,1,52, - 1,52,5,52,365,8,52,10,52,12,52,368,9,52,1,52,1,52,1,52,1,52,1,52, - 1,52,5,52,376,8,52,10,52,12,52,379,9,52,3,52,381,8,52,1,53,1,53, - 1,53,1,53,1,53,1,54,1,54,1,54,1,54,1,54,1,54,1,55,1,55,1,56,1,56, - 1,57,1,57,1,57,1,57,1,57,1,57,1,57,1,57,1,57,1,57,1,57,1,57,3,57, - 410,8,57,1,58,1,58,1,58,3,58,415,8,58,1,59,4,59,418,8,59,11,59,12, - 59,419,1,60,3,60,423,8,60,1,60,4,60,426,8,60,11,60,12,60,427,1,60, - 1,60,5,60,432,8,60,10,60,12,60,435,9,60,1,60,3,60,438,8,60,1,60, - 1,60,4,60,442,8,60,11,60,12,60,443,3,60,446,8,60,1,61,1,61,1,61, - 1,61,4,61,452,8,61,11,61,12,61,453,1,62,1,62,1,62,4,62,459,8,62, - 11,62,12,62,460,1,63,1,63,1,63,3,63,466,8,63,1,63,1,63,5,63,470, - 8,63,10,63,12,63,473,9,63,1,63,1,63,3,63,477,8,63,3,63,479,8,63, - 1,63,1,63,1,63,1,63,1,63,1,63,1,63,1,63,1,63,1,63,3,63,491,8,63, - 1,63,1,63,3,63,495,8,63,1,63,3,63,498,8,63,1,64,1,64,1,64,1,64,1, - 64,5,64,505,8,64,10,64,12,64,508,9,64,1,64,1,64,5,64,512,8,64,10, - 64,12,64,515,9,64,1,64,1,64,1,64,1,64,1,64,1,64,5,64,523,8,64,10, - 64,12,64,526,9,64,1,64,1,64,5,64,530,8,64,10,64,12,64,533,9,64,1, - 64,1,64,1,64,1,64,3,64,539,8,64,1,64,4,64,542,8,64,11,64,12,64,543, - 1,64,1,64,3,64,548,8,64,1,65,1,65,1,65,1,66,1,66,5,66,555,8,66,10, - 66,12,66,558,9,66,1,67,1,67,1,67,1,67,1,67,1,67,5,67,566,8,67,10, - 67,12,67,569,9,67,1,67,1,67,1,68,4,68,574,8,68,11,68,12,68,575,1, - 68,3,68,579,8,68,1,68,1,68,1,69,3,69,584,8,69,1,69,1,69,1,366,0, - 70,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25, - 13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47, - 24,49,25,51,26,53,27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69, - 35,71,36,73,37,75,38,77,39,79,40,81,41,83,42,85,43,87,44,89,45,91, - 46,93,47,95,48,97,49,99,50,101,51,103,52,105,0,107,0,109,0,111,0, - 113,0,115,0,117,53,119,54,121,55,123,56,125,57,127,58,129,59,131, - 60,133,61,135,62,137,63,139,64,1,0,33,2,0,73,73,105,105,2,0,78,78, - 110,110,2,0,84,84,116,116,2,0,66,66,98,98,2,0,79,79,111,111,2,0, - 76,76,108,108,2,0,83,83,115,115,2,0,82,82,114,114,2,0,71,71,103, - 103,2,0,81,81,113,113,2,0,85,85,117,117,2,0,70,70,102,102,2,0,65, - 65,97,97,2,0,86,86,118,118,2,0,68,68,100,100,2,0,69,69,101,101,2, - 0,89,89,121,121,2,0,87,87,119,119,2,0,80,80,112,112,2,0,90,90,122, - 122,2,0,77,77,109,109,2,0,67,67,99,99,2,0,88,88,120,120,2,0,72,72, - 104,104,2,0,10,10,13,13,1,0,48,57,2,0,43,43,45,45,2,0,65,70,97,102, - 1,0,48,49,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,2, - 0,34,34,92,92,3,0,9,10,13,13,32,32,623,0,1,1,0,0,0,0,3,1,0,0,0,0, - 5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15, - 1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25, - 1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35, - 1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45, - 1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55, - 1,0,0,0,0,57,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65, - 1,0,0,0,0,67,1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75, - 1,0,0,0,0,77,1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85, - 1,0,0,0,0,87,1,0,0,0,0,89,1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95, - 1,0,0,0,0,97,1,0,0,0,0,99,1,0,0,0,0,101,1,0,0,0,0,103,1,0,0,0,0, + 65,7,65,2,66,7,66,2,67,7,67,2,68,7,68,2,69,7,69,2,70,7,70,2,71,7, + 71,2,72,7,72,2,73,7,73,2,74,7,74,2,75,7,75,2,76,7,76,2,77,7,77,2, + 78,7,78,2,79,7,79,2,80,7,80,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1, + 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,3,1,3,1,4,1,4,1,4, + 1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,6, + 1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9, + 1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,13,1,14,1,14,1,14,1,14,1,15, + 1,15,1,15,1,15,1,16,1,16,1,16,1,17,1,17,1,17,1,18,1,18,1,18,1,18, + 1,18,1,19,1,19,1,19,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,20, + 1,20,1,20,1,21,1,21,1,21,1,21,1,21,1,21,1,21,1,22,1,22,1,22,1,22, + 1,23,1,23,1,23,1,23,1,24,1,24,1,24,1,24,1,25,1,25,1,25,1,25,1,26, + 1,26,1,26,1,26,1,26,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27, + 1,27,1,27,1,27,1,28,1,28,1,28,1,28,1,28,1,28,1,29,1,29,1,29,1,29, + 1,29,1,29,1,29,1,29,1,30,1,30,1,30,1,31,1,31,1,31,1,32,1,32,1,33, + 1,33,1,33,1,34,1,34,1,35,1,35,1,35,1,36,1,36,1,37,1,37,1,37,1,38, + 1,38,1,38,1,39,1,39,1,39,1,40,1,40,1,40,1,41,1,41,1,41,1,42,1,42, + 1,42,1,43,1,43,1,43,1,44,1,44,1,45,1,45,1,45,1,45,1,46,1,46,1,46, + 1,46,1,47,1,47,1,47,1,47,1,47,1,47,1,47,1,48,1,48,1,48,1,49,1,49, + 1,49,1,49,1,49,1,49,1,50,1,50,1,50,1,51,1,51,1,51,1,51,1,51,1,52, + 1,52,1,52,1,52,1,52,1,52,1,53,1,53,1,53,1,54,1,54,1,55,1,55,1,56, + 1,56,1,57,1,57,1,58,1,58,1,59,1,59,1,60,1,60,1,61,1,61,1,62,1,62, + 1,63,1,63,1,63,1,63,5,63,420,8,63,10,63,12,63,423,9,63,1,63,1,63, + 1,63,1,63,1,63,1,63,5,63,431,8,63,10,63,12,63,434,9,63,3,63,436, + 8,63,1,64,1,64,1,64,1,64,1,64,1,65,1,65,1,65,1,65,1,65,1,65,1,66, + 1,66,1,67,1,67,1,68,1,68,1,68,1,68,1,68,1,68,1,68,1,68,1,68,1,68, + 1,68,1,68,3,68,465,8,68,1,69,1,69,1,69,3,69,470,8,69,1,70,3,70,473, + 8,70,1,70,4,70,476,8,70,11,70,12,70,477,1,71,3,71,481,8,71,1,71, + 4,71,484,8,71,11,71,12,71,485,1,71,1,71,5,71,490,8,71,10,71,12,71, + 493,9,71,1,71,3,71,496,8,71,1,71,1,71,4,71,500,8,71,11,71,12,71, + 501,3,71,504,8,71,1,72,1,72,1,72,1,72,4,72,510,8,72,11,72,12,72, + 511,1,73,1,73,1,73,4,73,517,8,73,11,73,12,73,518,1,74,1,74,1,74, + 3,74,524,8,74,1,74,1,74,5,74,528,8,74,10,74,12,74,531,9,74,1,74, + 1,74,3,74,535,8,74,3,74,537,8,74,1,74,1,74,1,74,1,74,1,74,1,74,1, + 74,1,74,1,74,1,74,3,74,549,8,74,1,74,1,74,3,74,553,8,74,1,74,3,74, + 556,8,74,1,75,1,75,1,75,1,75,1,75,5,75,563,8,75,10,75,12,75,566, + 9,75,1,75,1,75,5,75,570,8,75,10,75,12,75,573,9,75,1,75,1,75,1,75, + 1,75,1,75,1,75,5,75,581,8,75,10,75,12,75,584,9,75,1,75,1,75,5,75, + 588,8,75,10,75,12,75,591,9,75,1,75,1,75,1,75,1,75,3,75,597,8,75, + 1,75,4,75,600,8,75,11,75,12,75,601,1,75,1,75,3,75,606,8,75,1,76, + 1,76,1,76,1,77,1,77,5,77,613,8,77,10,77,12,77,616,9,77,1,78,1,78, + 1,78,1,78,1,78,1,78,5,78,624,8,78,10,78,12,78,627,9,78,1,78,1,78, + 1,79,4,79,632,8,79,11,79,12,79,633,1,79,3,79,637,8,79,1,79,1,79, + 1,80,3,80,642,8,80,1,80,1,80,1,421,0,81,1,1,3,2,5,3,7,4,9,5,11,6, + 13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35, + 18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,55,28,57, + 29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75,38,77,39,79, + 40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,49,99,50,101, + 51,103,52,105,53,107,54,109,55,111,56,113,57,115,58,117,59,119,60, + 121,61,123,62,125,63,127,0,129,0,131,0,133,0,135,0,137,0,139,64, + 141,65,143,66,145,67,147,68,149,69,151,70,153,71,155,72,157,73,159, + 74,161,75,1,0,33,2,0,73,73,105,105,2,0,78,78,110,110,2,0,84,84,116, + 116,2,0,66,66,98,98,2,0,79,79,111,111,2,0,76,76,108,108,2,0,83,83, + 115,115,2,0,82,82,114,114,2,0,71,71,103,103,2,0,81,81,113,113,2, + 0,85,85,117,117,2,0,70,70,102,102,2,0,65,65,97,97,2,0,86,86,118, + 118,2,0,68,68,100,100,2,0,69,69,101,101,2,0,89,89,121,121,2,0,87, + 87,119,119,2,0,80,80,112,112,2,0,90,90,122,122,2,0,77,77,109,109, + 2,0,67,67,99,99,2,0,88,88,120,120,2,0,72,72,104,104,2,0,10,10,13, + 13,1,0,48,57,2,0,43,43,45,45,2,0,65,70,97,102,1,0,48,49,3,0,65,90, + 95,95,97,122,4,0,48,57,65,90,95,95,97,122,2,0,34,34,92,92,3,0,9, + 10,13,13,32,32,682,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0, + 0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0, + 0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0, + 0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0, + 0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,0, + 0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,1,0,0, + 0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,1,0,0, + 0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,1,0,0, + 0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,0, + 0,0,89,1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,0, + 0,0,99,1,0,0,0,0,101,1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,0,107,1, + 0,0,0,0,109,1,0,0,0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,0,0,0, 117,1,0,0,0,0,119,1,0,0,0,0,121,1,0,0,0,0,123,1,0,0,0,0,125,1,0, - 0,0,0,127,1,0,0,0,0,129,1,0,0,0,0,131,1,0,0,0,0,133,1,0,0,0,0,135, - 1,0,0,0,0,137,1,0,0,0,0,139,1,0,0,0,1,141,1,0,0,0,3,145,1,0,0,0, - 5,150,1,0,0,0,7,157,1,0,0,0,9,163,1,0,0,0,11,169,1,0,0,0,13,178, - 1,0,0,0,15,184,1,0,0,0,17,189,1,0,0,0,19,196,1,0,0,0,21,198,1,0, - 0,0,23,200,1,0,0,0,25,202,1,0,0,0,27,204,1,0,0,0,29,208,1,0,0,0, - 31,211,1,0,0,0,33,216,1,0,0,0,35,223,1,0,0,0,37,230,1,0,0,0,39,237, - 1,0,0,0,41,241,1,0,0,0,43,245,1,0,0,0,45,249,1,0,0,0,47,253,1,0, - 0,0,49,262,1,0,0,0,51,270,1,0,0,0,53,276,1,0,0,0,55,284,1,0,0,0, - 57,287,1,0,0,0,59,289,1,0,0,0,61,292,1,0,0,0,63,294,1,0,0,0,65,297, - 1,0,0,0,67,299,1,0,0,0,69,301,1,0,0,0,71,305,1,0,0,0,73,309,1,0, - 0,0,75,316,1,0,0,0,77,319,1,0,0,0,79,325,1,0,0,0,81,328,1,0,0,0, - 83,333,1,0,0,0,85,339,1,0,0,0,87,342,1,0,0,0,89,344,1,0,0,0,91,346, - 1,0,0,0,93,348,1,0,0,0,95,350,1,0,0,0,97,352,1,0,0,0,99,354,1,0, - 0,0,101,356,1,0,0,0,103,358,1,0,0,0,105,380,1,0,0,0,107,382,1,0, - 0,0,109,387,1,0,0,0,111,393,1,0,0,0,113,395,1,0,0,0,115,409,1,0, - 0,0,117,414,1,0,0,0,119,417,1,0,0,0,121,445,1,0,0,0,123,447,1,0, - 0,0,125,455,1,0,0,0,127,497,1,0,0,0,129,547,1,0,0,0,131,549,1,0, - 0,0,133,552,1,0,0,0,135,559,1,0,0,0,137,578,1,0,0,0,139,583,1,0, - 0,0,141,142,7,0,0,0,142,143,7,1,0,0,143,144,7,2,0,0,144,2,1,0,0, - 0,145,146,7,3,0,0,146,147,7,4,0,0,147,148,7,4,0,0,148,149,7,5,0, - 0,149,4,1,0,0,0,150,151,7,6,0,0,151,152,7,2,0,0,152,153,7,7,0,0, - 153,154,7,0,0,0,154,155,7,1,0,0,155,156,7,8,0,0,156,6,1,0,0,0,157, - 158,7,9,0,0,158,159,7,10,0,0,159,160,7,3,0,0,160,161,7,0,0,0,161, - 162,7,2,0,0,162,8,1,0,0,0,163,164,7,9,0,0,164,165,7,10,0,0,165,166, - 7,0,0,0,166,167,7,1,0,0,167,168,7,2,0,0,168,10,1,0,0,0,169,170,7, - 9,0,0,170,171,7,10,0,0,171,172,7,6,0,0,172,173,7,2,0,0,173,174,7, - 7,0,0,174,175,7,0,0,0,175,176,7,1,0,0,176,177,7,8,0,0,177,12,1,0, - 0,0,178,179,7,11,0,0,179,180,7,5,0,0,180,181,7,4,0,0,181,182,7,12, - 0,0,182,183,7,2,0,0,183,14,1,0,0,0,184,185,7,13,0,0,185,186,7,4, - 0,0,186,187,7,0,0,0,187,188,7,14,0,0,188,16,1,0,0,0,189,190,7,7, - 0,0,190,191,7,15,0,0,191,192,7,2,0,0,192,193,7,10,0,0,193,194,7, - 7,0,0,194,195,7,1,0,0,195,18,1,0,0,0,196,197,5,42,0,0,197,20,1,0, - 0,0,198,199,5,47,0,0,199,22,1,0,0,0,200,201,5,43,0,0,201,24,1,0, - 0,0,202,203,5,45,0,0,203,26,1,0,0,0,204,205,7,1,0,0,205,206,7,4, - 0,0,206,207,7,2,0,0,207,28,1,0,0,0,208,209,7,3,0,0,209,210,7,16, - 0,0,210,30,1,0,0,0,211,212,7,6,0,0,212,213,7,17,0,0,213,214,7,12, - 0,0,214,215,7,18,0,0,215,32,1,0,0,0,216,217,7,18,0,0,217,218,7,12, - 0,0,218,219,7,10,0,0,219,220,7,5,0,0,220,221,7,0,0,0,221,222,7,16, - 0,0,222,34,1,0,0,0,223,224,7,18,0,0,224,225,7,12,0,0,225,226,7,10, - 0,0,226,227,7,5,0,0,227,228,7,0,0,0,228,229,7,19,0,0,229,36,1,0, - 0,0,230,231,7,8,0,0,231,232,7,7,0,0,232,233,7,4,0,0,233,234,7,13, - 0,0,234,235,7,15,0,0,235,236,7,7,0,0,236,38,1,0,0,0,237,238,7,20, - 0,0,238,239,7,21,0,0,239,240,7,19,0,0,240,40,1,0,0,0,241,242,7,20, - 0,0,242,243,7,21,0,0,243,244,7,22,0,0,244,42,1,0,0,0,245,246,7,20, - 0,0,246,247,7,21,0,0,247,248,7,16,0,0,248,44,1,0,0,0,249,250,7,20, - 0,0,250,251,7,21,0,0,251,252,7,18,0,0,252,46,1,0,0,0,253,254,7,23, - 0,0,254,255,7,12,0,0,255,256,7,14,0,0,256,257,7,12,0,0,257,258,7, - 20,0,0,258,259,7,12,0,0,259,260,7,7,0,0,260,261,7,14,0,0,261,48, - 1,0,0,0,262,263,7,20,0,0,263,264,7,15,0,0,264,265,7,12,0,0,265,266, - 7,6,0,0,266,267,7,10,0,0,267,268,7,7,0,0,268,269,7,15,0,0,269,50, - 1,0,0,0,270,271,7,18,0,0,271,272,7,7,0,0,272,273,7,0,0,0,273,274, - 7,1,0,0,274,275,7,2,0,0,275,52,1,0,0,0,276,277,7,3,0,0,277,278,7, - 12,0,0,278,279,7,7,0,0,279,280,7,7,0,0,280,281,7,0,0,0,281,282,7, - 15,0,0,282,283,7,7,0,0,283,54,1,0,0,0,284,285,5,61,0,0,285,286,5, - 61,0,0,286,56,1,0,0,0,287,288,5,62,0,0,288,58,1,0,0,0,289,290,5, - 62,0,0,290,291,5,61,0,0,291,60,1,0,0,0,292,293,5,60,0,0,293,62,1, - 0,0,0,294,295,5,60,0,0,295,296,5,61,0,0,296,64,1,0,0,0,297,298,5, - 61,0,0,298,66,1,0,0,0,299,300,5,59,0,0,300,68,1,0,0,0,301,302,7, - 13,0,0,302,303,7,12,0,0,303,304,7,7,0,0,304,70,1,0,0,0,305,306,7, - 11,0,0,306,307,7,4,0,0,307,308,7,7,0,0,308,72,1,0,0,0,309,310,7, - 6,0,0,310,311,7,15,0,0,311,312,7,12,0,0,312,313,7,7,0,0,313,314, - 7,21,0,0,314,315,7,23,0,0,315,74,1,0,0,0,316,317,7,0,0,0,317,318, - 7,1,0,0,318,76,1,0,0,0,319,320,7,17,0,0,320,321,7,23,0,0,321,322, - 7,15,0,0,322,323,7,7,0,0,323,324,7,15,0,0,324,78,1,0,0,0,325,326, - 7,0,0,0,326,327,7,11,0,0,327,80,1,0,0,0,328,329,7,15,0,0,329,330, - 7,5,0,0,330,331,7,6,0,0,331,332,7,15,0,0,332,82,1,0,0,0,333,334, - 7,17,0,0,334,335,7,23,0,0,335,336,7,0,0,0,336,337,7,5,0,0,337,338, - 7,15,0,0,338,84,1,0,0,0,339,340,7,14,0,0,340,341,7,4,0,0,341,86, - 1,0,0,0,342,343,5,123,0,0,343,88,1,0,0,0,344,345,5,125,0,0,345,90, - 1,0,0,0,346,347,5,40,0,0,347,92,1,0,0,0,348,349,5,41,0,0,349,94, - 1,0,0,0,350,351,5,91,0,0,351,96,1,0,0,0,352,353,5,93,0,0,353,98, - 1,0,0,0,354,355,5,46,0,0,355,100,1,0,0,0,356,357,5,34,0,0,357,102, - 1,0,0,0,358,359,5,44,0,0,359,104,1,0,0,0,360,361,5,47,0,0,361,362, - 5,42,0,0,362,366,1,0,0,0,363,365,9,0,0,0,364,363,1,0,0,0,365,368, - 1,0,0,0,366,367,1,0,0,0,366,364,1,0,0,0,367,369,1,0,0,0,368,366, - 1,0,0,0,369,370,5,42,0,0,370,381,5,47,0,0,371,372,5,47,0,0,372,373, - 5,47,0,0,373,377,1,0,0,0,374,376,8,24,0,0,375,374,1,0,0,0,376,379, - 1,0,0,0,377,375,1,0,0,0,377,378,1,0,0,0,378,381,1,0,0,0,379,377, - 1,0,0,0,380,360,1,0,0,0,380,371,1,0,0,0,381,106,1,0,0,0,382,383, - 7,2,0,0,383,384,7,7,0,0,384,385,7,10,0,0,385,386,7,15,0,0,386,108, - 1,0,0,0,387,388,7,11,0,0,388,389,7,12,0,0,389,390,7,5,0,0,390,391, - 7,6,0,0,391,392,7,15,0,0,392,110,1,0,0,0,393,394,7,25,0,0,394,112, - 1,0,0,0,395,396,7,26,0,0,396,114,1,0,0,0,397,398,5,124,0,0,398,399, - 5,48,0,0,399,410,5,62,0,0,400,401,5,124,0,0,401,402,5,49,0,0,402, - 410,5,62,0,0,403,404,5,124,0,0,404,405,5,43,0,0,405,410,5,62,0,0, - 406,407,5,124,0,0,407,408,5,45,0,0,408,410,5,62,0,0,409,397,1,0, - 0,0,409,400,1,0,0,0,409,403,1,0,0,0,409,406,1,0,0,0,410,116,1,0, - 0,0,411,415,3,107,53,0,412,415,3,109,54,0,413,415,2,48,49,0,414, - 411,1,0,0,0,414,412,1,0,0,0,414,413,1,0,0,0,415,118,1,0,0,0,416, - 418,3,111,55,0,417,416,1,0,0,0,418,419,1,0,0,0,419,417,1,0,0,0,419, - 420,1,0,0,0,420,120,1,0,0,0,421,423,3,113,56,0,422,421,1,0,0,0,422, - 423,1,0,0,0,423,425,1,0,0,0,424,426,3,111,55,0,425,424,1,0,0,0,426, - 427,1,0,0,0,427,425,1,0,0,0,427,428,1,0,0,0,428,429,1,0,0,0,429, - 433,5,46,0,0,430,432,3,111,55,0,431,430,1,0,0,0,432,435,1,0,0,0, - 433,431,1,0,0,0,433,434,1,0,0,0,434,446,1,0,0,0,435,433,1,0,0,0, - 436,438,3,113,56,0,437,436,1,0,0,0,437,438,1,0,0,0,438,439,1,0,0, - 0,439,441,5,46,0,0,440,442,3,111,55,0,441,440,1,0,0,0,442,443,1, - 0,0,0,443,441,1,0,0,0,443,444,1,0,0,0,444,446,1,0,0,0,445,422,1, - 0,0,0,445,437,1,0,0,0,446,122,1,0,0,0,447,448,5,48,0,0,448,451,7, - 22,0,0,449,452,7,27,0,0,450,452,3,111,55,0,451,449,1,0,0,0,451,450, - 1,0,0,0,452,453,1,0,0,0,453,451,1,0,0,0,453,454,1,0,0,0,454,124, - 1,0,0,0,455,456,5,48,0,0,456,458,7,3,0,0,457,459,7,28,0,0,458,457, - 1,0,0,0,459,460,1,0,0,0,460,458,1,0,0,0,460,461,1,0,0,0,461,126, - 1,0,0,0,462,465,3,95,47,0,463,466,3,117,58,0,464,466,2,48,49,0,465, - 463,1,0,0,0,465,464,1,0,0,0,466,478,1,0,0,0,467,471,3,103,51,0,468, - 470,5,32,0,0,469,468,1,0,0,0,470,473,1,0,0,0,471,469,1,0,0,0,471, - 472,1,0,0,0,472,476,1,0,0,0,473,471,1,0,0,0,474,477,3,117,58,0,475, - 477,2,48,49,0,476,474,1,0,0,0,476,475,1,0,0,0,477,479,1,0,0,0,478, - 467,1,0,0,0,478,479,1,0,0,0,479,480,1,0,0,0,480,481,3,97,48,0,481, - 482,7,9,0,0,482,498,1,0,0,0,483,484,3,121,60,0,484,485,3,103,51, - 0,485,486,3,121,60,0,486,487,7,9,0,0,487,498,1,0,0,0,488,498,3,115, - 57,0,489,491,3,113,56,0,490,489,1,0,0,0,490,491,1,0,0,0,491,494, - 1,0,0,0,492,495,3,117,58,0,493,495,2,48,49,0,494,492,1,0,0,0,494, - 493,1,0,0,0,495,496,1,0,0,0,496,498,7,9,0,0,497,462,1,0,0,0,497, - 483,1,0,0,0,497,488,1,0,0,0,497,490,1,0,0,0,498,128,1,0,0,0,499, - 548,3,127,63,0,500,501,3,95,47,0,501,513,3,127,63,0,502,506,3,103, - 51,0,503,505,5,32,0,0,504,503,1,0,0,0,505,508,1,0,0,0,506,504,1, - 0,0,0,506,507,1,0,0,0,507,509,1,0,0,0,508,506,1,0,0,0,509,510,3, - 127,63,0,510,512,1,0,0,0,511,502,1,0,0,0,512,515,1,0,0,0,513,511, - 1,0,0,0,513,514,1,0,0,0,514,516,1,0,0,0,515,513,1,0,0,0,516,517, - 3,97,48,0,517,548,1,0,0,0,518,519,3,95,47,0,519,531,3,119,59,0,520, - 524,3,103,51,0,521,523,5,32,0,0,522,521,1,0,0,0,523,526,1,0,0,0, - 524,522,1,0,0,0,524,525,1,0,0,0,525,527,1,0,0,0,526,524,1,0,0,0, - 527,528,3,119,59,0,528,530,1,0,0,0,529,520,1,0,0,0,530,533,1,0,0, - 0,531,529,1,0,0,0,531,532,1,0,0,0,532,534,1,0,0,0,533,531,1,0,0, - 0,534,535,3,97,48,0,535,536,7,9,0,0,536,548,1,0,0,0,537,539,3,113, - 56,0,538,537,1,0,0,0,538,539,1,0,0,0,539,541,1,0,0,0,540,542,3,111, - 55,0,541,540,1,0,0,0,542,543,1,0,0,0,543,541,1,0,0,0,543,544,1,0, - 0,0,544,545,1,0,0,0,545,546,7,9,0,0,546,548,1,0,0,0,547,499,1,0, - 0,0,547,500,1,0,0,0,547,518,1,0,0,0,547,538,1,0,0,0,548,130,1,0, - 0,0,549,550,3,135,67,0,550,551,7,9,0,0,551,132,1,0,0,0,552,556,7, - 29,0,0,553,555,7,30,0,0,554,553,1,0,0,0,555,558,1,0,0,0,556,554, - 1,0,0,0,556,557,1,0,0,0,557,134,1,0,0,0,558,556,1,0,0,0,559,567, - 5,34,0,0,560,561,5,92,0,0,561,566,9,0,0,0,562,563,5,34,0,0,563,566, - 5,34,0,0,564,566,8,31,0,0,565,560,1,0,0,0,565,562,1,0,0,0,565,564, - 1,0,0,0,566,569,1,0,0,0,567,565,1,0,0,0,567,568,1,0,0,0,568,570, - 1,0,0,0,569,567,1,0,0,0,570,571,5,34,0,0,571,136,1,0,0,0,572,574, - 7,32,0,0,573,572,1,0,0,0,574,575,1,0,0,0,575,573,1,0,0,0,575,576, - 1,0,0,0,576,579,1,0,0,0,577,579,3,105,52,0,578,573,1,0,0,0,578,577, - 1,0,0,0,579,580,1,0,0,0,580,581,6,68,0,0,581,138,1,0,0,0,582,584, - 5,13,0,0,583,582,1,0,0,0,583,584,1,0,0,0,584,585,1,0,0,0,585,586, - 5,10,0,0,586,140,1,0,0,0,36,0,366,377,380,409,414,419,422,427,433, - 437,443,445,451,453,460,465,471,476,478,490,494,497,506,513,524, - 531,538,543,547,556,565,567,575,578,583,1,6,0,0 + 0,0,0,139,1,0,0,0,0,141,1,0,0,0,0,143,1,0,0,0,0,145,1,0,0,0,0,147, + 1,0,0,0,0,149,1,0,0,0,0,151,1,0,0,0,0,153,1,0,0,0,0,155,1,0,0,0, + 0,157,1,0,0,0,0,159,1,0,0,0,0,161,1,0,0,0,1,163,1,0,0,0,3,167,1, + 0,0,0,5,172,1,0,0,0,7,179,1,0,0,0,9,185,1,0,0,0,11,191,1,0,0,0,13, + 200,1,0,0,0,15,206,1,0,0,0,17,211,1,0,0,0,19,218,1,0,0,0,21,220, + 1,0,0,0,23,222,1,0,0,0,25,224,1,0,0,0,27,226,1,0,0,0,29,228,1,0, + 0,0,31,232,1,0,0,0,33,236,1,0,0,0,35,239,1,0,0,0,37,242,1,0,0,0, + 39,247,1,0,0,0,41,254,1,0,0,0,43,261,1,0,0,0,45,268,1,0,0,0,47,272, + 1,0,0,0,49,276,1,0,0,0,51,280,1,0,0,0,53,284,1,0,0,0,55,293,1,0, + 0,0,57,301,1,0,0,0,59,307,1,0,0,0,61,315,1,0,0,0,63,318,1,0,0,0, + 65,321,1,0,0,0,67,323,1,0,0,0,69,326,1,0,0,0,71,328,1,0,0,0,73,331, + 1,0,0,0,75,333,1,0,0,0,77,336,1,0,0,0,79,339,1,0,0,0,81,342,1,0, + 0,0,83,345,1,0,0,0,85,348,1,0,0,0,87,351,1,0,0,0,89,354,1,0,0,0, + 91,356,1,0,0,0,93,360,1,0,0,0,95,364,1,0,0,0,97,371,1,0,0,0,99,374, + 1,0,0,0,101,380,1,0,0,0,103,383,1,0,0,0,105,388,1,0,0,0,107,394, + 1,0,0,0,109,397,1,0,0,0,111,399,1,0,0,0,113,401,1,0,0,0,115,403, + 1,0,0,0,117,405,1,0,0,0,119,407,1,0,0,0,121,409,1,0,0,0,123,411, + 1,0,0,0,125,413,1,0,0,0,127,435,1,0,0,0,129,437,1,0,0,0,131,442, + 1,0,0,0,133,448,1,0,0,0,135,450,1,0,0,0,137,464,1,0,0,0,139,469, + 1,0,0,0,141,472,1,0,0,0,143,503,1,0,0,0,145,505,1,0,0,0,147,513, + 1,0,0,0,149,555,1,0,0,0,151,605,1,0,0,0,153,607,1,0,0,0,155,610, + 1,0,0,0,157,617,1,0,0,0,159,636,1,0,0,0,161,641,1,0,0,0,163,164, + 7,0,0,0,164,165,7,1,0,0,165,166,7,2,0,0,166,2,1,0,0,0,167,168,7, + 3,0,0,168,169,7,4,0,0,169,170,7,4,0,0,170,171,7,5,0,0,171,4,1,0, + 0,0,172,173,7,6,0,0,173,174,7,2,0,0,174,175,7,7,0,0,175,176,7,0, + 0,0,176,177,7,1,0,0,177,178,7,8,0,0,178,6,1,0,0,0,179,180,7,9,0, + 0,180,181,7,10,0,0,181,182,7,3,0,0,182,183,7,0,0,0,183,184,7,2,0, + 0,184,8,1,0,0,0,185,186,7,9,0,0,186,187,7,10,0,0,187,188,7,0,0,0, + 188,189,7,1,0,0,189,190,7,2,0,0,190,10,1,0,0,0,191,192,7,9,0,0,192, + 193,7,10,0,0,193,194,7,6,0,0,194,195,7,2,0,0,195,196,7,7,0,0,196, + 197,7,0,0,0,197,198,7,1,0,0,198,199,7,8,0,0,199,12,1,0,0,0,200,201, + 7,11,0,0,201,202,7,5,0,0,202,203,7,4,0,0,203,204,7,12,0,0,204,205, + 7,2,0,0,205,14,1,0,0,0,206,207,7,13,0,0,207,208,7,4,0,0,208,209, + 7,0,0,0,209,210,7,14,0,0,210,16,1,0,0,0,211,212,7,7,0,0,212,213, + 7,15,0,0,213,214,7,2,0,0,214,215,7,10,0,0,215,216,7,7,0,0,216,217, + 7,1,0,0,217,18,1,0,0,0,218,219,5,42,0,0,219,20,1,0,0,0,220,221,5, + 47,0,0,221,22,1,0,0,0,222,223,5,37,0,0,223,24,1,0,0,0,224,225,5, + 43,0,0,225,26,1,0,0,0,226,227,5,45,0,0,227,28,1,0,0,0,228,229,7, + 1,0,0,229,230,7,4,0,0,230,231,7,2,0,0,231,30,1,0,0,0,232,233,7,12, + 0,0,233,234,7,1,0,0,234,235,7,14,0,0,235,32,1,0,0,0,236,237,7,4, + 0,0,237,238,7,7,0,0,238,34,1,0,0,0,239,240,7,3,0,0,240,241,7,16, + 0,0,241,36,1,0,0,0,242,243,7,6,0,0,243,244,7,17,0,0,244,245,7,12, + 0,0,245,246,7,18,0,0,246,38,1,0,0,0,247,248,7,18,0,0,248,249,7,12, + 0,0,249,250,7,10,0,0,250,251,7,5,0,0,251,252,7,0,0,0,252,253,7,16, + 0,0,253,40,1,0,0,0,254,255,7,18,0,0,255,256,7,12,0,0,256,257,7,10, + 0,0,257,258,7,5,0,0,258,259,7,0,0,0,259,260,7,19,0,0,260,42,1,0, + 0,0,261,262,7,8,0,0,262,263,7,7,0,0,263,264,7,4,0,0,264,265,7,13, + 0,0,265,266,7,15,0,0,266,267,7,7,0,0,267,44,1,0,0,0,268,269,7,20, + 0,0,269,270,7,21,0,0,270,271,7,19,0,0,271,46,1,0,0,0,272,273,7,20, + 0,0,273,274,7,21,0,0,274,275,7,22,0,0,275,48,1,0,0,0,276,277,7,20, + 0,0,277,278,7,21,0,0,278,279,7,16,0,0,279,50,1,0,0,0,280,281,7,20, + 0,0,281,282,7,21,0,0,282,283,7,18,0,0,283,52,1,0,0,0,284,285,7,23, + 0,0,285,286,7,12,0,0,286,287,7,14,0,0,287,288,7,12,0,0,288,289,7, + 20,0,0,289,290,7,12,0,0,290,291,7,7,0,0,291,292,7,14,0,0,292,54, + 1,0,0,0,293,294,7,20,0,0,294,295,7,15,0,0,295,296,7,12,0,0,296,297, + 7,6,0,0,297,298,7,10,0,0,298,299,7,7,0,0,299,300,7,15,0,0,300,56, + 1,0,0,0,301,302,7,18,0,0,302,303,7,7,0,0,303,304,7,0,0,0,304,305, + 7,1,0,0,305,306,7,2,0,0,306,58,1,0,0,0,307,308,7,3,0,0,308,309,7, + 12,0,0,309,310,7,7,0,0,310,311,7,7,0,0,311,312,7,0,0,0,312,313,7, + 15,0,0,313,314,7,7,0,0,314,60,1,0,0,0,315,316,5,61,0,0,316,317,5, + 61,0,0,317,62,1,0,0,0,318,319,5,33,0,0,319,320,5,61,0,0,320,64,1, + 0,0,0,321,322,5,62,0,0,322,66,1,0,0,0,323,324,5,62,0,0,324,325,5, + 61,0,0,325,68,1,0,0,0,326,327,5,60,0,0,327,70,1,0,0,0,328,329,5, + 60,0,0,329,330,5,61,0,0,330,72,1,0,0,0,331,332,5,61,0,0,332,74,1, + 0,0,0,333,334,5,43,0,0,334,335,5,43,0,0,335,76,1,0,0,0,336,337,5, + 45,0,0,337,338,5,45,0,0,338,78,1,0,0,0,339,340,5,43,0,0,340,341, + 5,61,0,0,341,80,1,0,0,0,342,343,5,45,0,0,343,344,5,61,0,0,344,82, + 1,0,0,0,345,346,5,42,0,0,346,347,5,61,0,0,347,84,1,0,0,0,348,349, + 5,47,0,0,349,350,5,61,0,0,350,86,1,0,0,0,351,352,5,37,0,0,352,353, + 5,61,0,0,353,88,1,0,0,0,354,355,5,59,0,0,355,90,1,0,0,0,356,357, + 7,13,0,0,357,358,7,12,0,0,358,359,7,7,0,0,359,92,1,0,0,0,360,361, + 7,11,0,0,361,362,7,4,0,0,362,363,7,7,0,0,363,94,1,0,0,0,364,365, + 7,6,0,0,365,366,7,15,0,0,366,367,7,12,0,0,367,368,7,7,0,0,368,369, + 7,21,0,0,369,370,7,23,0,0,370,96,1,0,0,0,371,372,7,0,0,0,372,373, + 7,1,0,0,373,98,1,0,0,0,374,375,7,17,0,0,375,376,7,23,0,0,376,377, + 7,15,0,0,377,378,7,7,0,0,378,379,7,15,0,0,379,100,1,0,0,0,380,381, + 7,0,0,0,381,382,7,11,0,0,382,102,1,0,0,0,383,384,7,15,0,0,384,385, + 7,5,0,0,385,386,7,6,0,0,386,387,7,15,0,0,387,104,1,0,0,0,388,389, + 7,17,0,0,389,390,7,23,0,0,390,391,7,0,0,0,391,392,7,5,0,0,392,393, + 7,15,0,0,393,106,1,0,0,0,394,395,7,14,0,0,395,396,7,4,0,0,396,108, + 1,0,0,0,397,398,5,123,0,0,398,110,1,0,0,0,399,400,5,125,0,0,400, + 112,1,0,0,0,401,402,5,40,0,0,402,114,1,0,0,0,403,404,5,41,0,0,404, + 116,1,0,0,0,405,406,5,91,0,0,406,118,1,0,0,0,407,408,5,93,0,0,408, + 120,1,0,0,0,409,410,5,46,0,0,410,122,1,0,0,0,411,412,5,34,0,0,412, + 124,1,0,0,0,413,414,5,44,0,0,414,126,1,0,0,0,415,416,5,47,0,0,416, + 417,5,42,0,0,417,421,1,0,0,0,418,420,9,0,0,0,419,418,1,0,0,0,420, + 423,1,0,0,0,421,422,1,0,0,0,421,419,1,0,0,0,422,424,1,0,0,0,423, + 421,1,0,0,0,424,425,5,42,0,0,425,436,5,47,0,0,426,427,5,47,0,0,427, + 428,5,47,0,0,428,432,1,0,0,0,429,431,8,24,0,0,430,429,1,0,0,0,431, + 434,1,0,0,0,432,430,1,0,0,0,432,433,1,0,0,0,433,436,1,0,0,0,434, + 432,1,0,0,0,435,415,1,0,0,0,435,426,1,0,0,0,436,128,1,0,0,0,437, + 438,7,2,0,0,438,439,7,7,0,0,439,440,7,10,0,0,440,441,7,15,0,0,441, + 130,1,0,0,0,442,443,7,11,0,0,443,444,7,12,0,0,444,445,7,5,0,0,445, + 446,7,6,0,0,446,447,7,15,0,0,447,132,1,0,0,0,448,449,7,25,0,0,449, + 134,1,0,0,0,450,451,7,26,0,0,451,136,1,0,0,0,452,453,5,124,0,0,453, + 454,5,48,0,0,454,465,5,62,0,0,455,456,5,124,0,0,456,457,5,49,0,0, + 457,465,5,62,0,0,458,459,5,124,0,0,459,460,5,43,0,0,460,465,5,62, + 0,0,461,462,5,124,0,0,462,463,5,45,0,0,463,465,5,62,0,0,464,452, + 1,0,0,0,464,455,1,0,0,0,464,458,1,0,0,0,464,461,1,0,0,0,465,138, + 1,0,0,0,466,470,3,129,64,0,467,470,3,131,65,0,468,470,2,48,49,0, + 469,466,1,0,0,0,469,467,1,0,0,0,469,468,1,0,0,0,470,140,1,0,0,0, + 471,473,3,135,67,0,472,471,1,0,0,0,472,473,1,0,0,0,473,475,1,0,0, + 0,474,476,3,133,66,0,475,474,1,0,0,0,476,477,1,0,0,0,477,475,1,0, + 0,0,477,478,1,0,0,0,478,142,1,0,0,0,479,481,3,135,67,0,480,479,1, + 0,0,0,480,481,1,0,0,0,481,483,1,0,0,0,482,484,3,133,66,0,483,482, + 1,0,0,0,484,485,1,0,0,0,485,483,1,0,0,0,485,486,1,0,0,0,486,487, + 1,0,0,0,487,491,5,46,0,0,488,490,3,133,66,0,489,488,1,0,0,0,490, + 493,1,0,0,0,491,489,1,0,0,0,491,492,1,0,0,0,492,504,1,0,0,0,493, + 491,1,0,0,0,494,496,3,135,67,0,495,494,1,0,0,0,495,496,1,0,0,0,496, + 497,1,0,0,0,497,499,5,46,0,0,498,500,3,133,66,0,499,498,1,0,0,0, + 500,501,1,0,0,0,501,499,1,0,0,0,501,502,1,0,0,0,502,504,1,0,0,0, + 503,480,1,0,0,0,503,495,1,0,0,0,504,144,1,0,0,0,505,506,5,48,0,0, + 506,509,7,22,0,0,507,510,7,27,0,0,508,510,3,133,66,0,509,507,1,0, + 0,0,509,508,1,0,0,0,510,511,1,0,0,0,511,509,1,0,0,0,511,512,1,0, + 0,0,512,146,1,0,0,0,513,514,5,48,0,0,514,516,7,3,0,0,515,517,7,28, + 0,0,516,515,1,0,0,0,517,518,1,0,0,0,518,516,1,0,0,0,518,519,1,0, + 0,0,519,148,1,0,0,0,520,523,3,117,58,0,521,524,3,139,69,0,522,524, + 2,48,49,0,523,521,1,0,0,0,523,522,1,0,0,0,524,536,1,0,0,0,525,529, + 3,125,62,0,526,528,5,32,0,0,527,526,1,0,0,0,528,531,1,0,0,0,529, + 527,1,0,0,0,529,530,1,0,0,0,530,534,1,0,0,0,531,529,1,0,0,0,532, + 535,3,139,69,0,533,535,2,48,49,0,534,532,1,0,0,0,534,533,1,0,0,0, + 535,537,1,0,0,0,536,525,1,0,0,0,536,537,1,0,0,0,537,538,1,0,0,0, + 538,539,3,119,59,0,539,540,7,9,0,0,540,556,1,0,0,0,541,542,3,143, + 71,0,542,543,3,125,62,0,543,544,3,143,71,0,544,545,7,9,0,0,545,556, + 1,0,0,0,546,556,3,137,68,0,547,549,3,135,67,0,548,547,1,0,0,0,548, + 549,1,0,0,0,549,552,1,0,0,0,550,553,3,139,69,0,551,553,2,48,49,0, + 552,550,1,0,0,0,552,551,1,0,0,0,553,554,1,0,0,0,554,556,7,9,0,0, + 555,520,1,0,0,0,555,541,1,0,0,0,555,546,1,0,0,0,555,548,1,0,0,0, + 556,150,1,0,0,0,557,606,3,149,74,0,558,559,3,117,58,0,559,571,3, + 149,74,0,560,564,3,125,62,0,561,563,5,32,0,0,562,561,1,0,0,0,563, + 566,1,0,0,0,564,562,1,0,0,0,564,565,1,0,0,0,565,567,1,0,0,0,566, + 564,1,0,0,0,567,568,3,149,74,0,568,570,1,0,0,0,569,560,1,0,0,0,570, + 573,1,0,0,0,571,569,1,0,0,0,571,572,1,0,0,0,572,574,1,0,0,0,573, + 571,1,0,0,0,574,575,3,119,59,0,575,606,1,0,0,0,576,577,3,117,58, + 0,577,589,3,141,70,0,578,582,3,125,62,0,579,581,5,32,0,0,580,579, + 1,0,0,0,581,584,1,0,0,0,582,580,1,0,0,0,582,583,1,0,0,0,583,585, + 1,0,0,0,584,582,1,0,0,0,585,586,3,141,70,0,586,588,1,0,0,0,587,578, + 1,0,0,0,588,591,1,0,0,0,589,587,1,0,0,0,589,590,1,0,0,0,590,592, + 1,0,0,0,591,589,1,0,0,0,592,593,3,119,59,0,593,594,7,9,0,0,594,606, + 1,0,0,0,595,597,3,135,67,0,596,595,1,0,0,0,596,597,1,0,0,0,597,599, + 1,0,0,0,598,600,3,133,66,0,599,598,1,0,0,0,600,601,1,0,0,0,601,599, + 1,0,0,0,601,602,1,0,0,0,602,603,1,0,0,0,603,604,7,9,0,0,604,606, + 1,0,0,0,605,557,1,0,0,0,605,558,1,0,0,0,605,576,1,0,0,0,605,596, + 1,0,0,0,606,152,1,0,0,0,607,608,3,157,78,0,608,609,7,9,0,0,609,154, + 1,0,0,0,610,614,7,29,0,0,611,613,7,30,0,0,612,611,1,0,0,0,613,616, + 1,0,0,0,614,612,1,0,0,0,614,615,1,0,0,0,615,156,1,0,0,0,616,614, + 1,0,0,0,617,625,5,34,0,0,618,619,5,92,0,0,619,624,9,0,0,0,620,621, + 5,34,0,0,621,624,5,34,0,0,622,624,8,31,0,0,623,618,1,0,0,0,623,620, + 1,0,0,0,623,622,1,0,0,0,624,627,1,0,0,0,625,623,1,0,0,0,625,626, + 1,0,0,0,626,628,1,0,0,0,627,625,1,0,0,0,628,629,5,34,0,0,629,158, + 1,0,0,0,630,632,7,32,0,0,631,630,1,0,0,0,632,633,1,0,0,0,633,631, + 1,0,0,0,633,634,1,0,0,0,634,637,1,0,0,0,635,637,3,127,63,0,636,631, + 1,0,0,0,636,635,1,0,0,0,637,638,1,0,0,0,638,639,6,79,0,0,639,160, + 1,0,0,0,640,642,5,13,0,0,641,640,1,0,0,0,641,642,1,0,0,0,642,643, + 1,0,0,0,643,644,5,10,0,0,644,162,1,0,0,0,37,0,421,432,435,464,469, + 472,477,480,485,491,495,501,503,509,511,518,523,529,534,536,548, + 552,555,564,571,582,589,596,601,605,614,623,625,633,636,641,1,6, + 0,0 ] class qutes_lexer(Lexer): @@ -248,59 +269,70 @@ class qutes_lexer(Lexer): RETURN = 9 MULTIPLY = 10 DIVIDE = 11 - ADD = 12 - SUB = 13 - NOT = 14 - BY = 15 - SWAP = 16 - PAULIY = 17 - PAULIZ = 18 - GROVER = 19 - MCZ = 20 - MCX = 21 - MCY = 22 - MCP = 23 - HADAMARD = 24 - MEASURE = 25 - PRINT = 26 - BARRIER = 27 - EQUAL = 28 - GREATER = 29 - GREATEREQUAL = 30 - LOWER = 31 - LOWEREQUAL = 32 - ASSIGN = 33 - END_OF_STATEMENT = 34 - VAR_STATEMENT = 35 - FOR_STATEMENT = 36 - SEARCH_STATEMENT = 37 - IN_STATEMENT = 38 - WHERE_STATEMENT = 39 - IF_STATEMENT = 40 - ELSE_STATEMENT = 41 - WHILE_STATEMENT = 42 - DO_STATEMENT = 43 - CURLY_PARENTHESIS_OPEN = 44 - CURLY_PARENTHESIS_CLOSE = 45 - ROUND_PARENTHESIS_OPEN = 46 - ROUND_PARENTHESIS_CLOSE = 47 - SQUARE_PARENTHESIS_OPEN = 48 - SQUARE_PARENTHESIS_CLOSE = 49 - DOT = 50 - STRING_ENCLOSURE = 51 - COMMA = 52 - BOOL_LITERAL = 53 - INT_LITERAL = 54 - FLOAT_LITERAL = 55 - HEX_LITERAL = 56 - BIN_LITERAL = 57 - QUBIT_LITERAL = 58 - QUINT_LITERAL = 59 - QUSTRING_LITERAL = 60 - SYMBOL_LITERAL = 61 - STRING_LITERAL = 62 - WS = 63 - NEWLINE = 64 + MODULE = 12 + ADD = 13 + SUB = 14 + NOT = 15 + AND = 16 + OR = 17 + BY = 18 + SWAP = 19 + PAULIY = 20 + PAULIZ = 21 + GROVER = 22 + MCZ = 23 + MCX = 24 + MCY = 25 + MCP = 26 + HADAMARD = 27 + MEASURE = 28 + PRINT = 29 + BARRIER = 30 + EQUAL = 31 + NOT_EQUAL = 32 + GREATER = 33 + GREATEREQUAL = 34 + LOWER = 35 + LOWEREQUAL = 36 + ASSIGN = 37 + AUTO_INCREMENT = 38 + AUTO_DECREMENT = 39 + AUTO_SUM = 40 + AUTO_SUB = 41 + AUTO_MULTIPLY = 42 + AUTO_DIVIDE = 43 + AUTO_MODULE = 44 + END_OF_STATEMENT = 45 + VAR_STATEMENT = 46 + FOR_STATEMENT = 47 + SEARCH_STATEMENT = 48 + IN_STATEMENT = 49 + WHERE_STATEMENT = 50 + IF_STATEMENT = 51 + ELSE_STATEMENT = 52 + WHILE_STATEMENT = 53 + DO_STATEMENT = 54 + CURLY_PARENTHESIS_OPEN = 55 + CURLY_PARENTHESIS_CLOSE = 56 + ROUND_PARENTHESIS_OPEN = 57 + ROUND_PARENTHESIS_CLOSE = 58 + SQUARE_PARENTHESIS_OPEN = 59 + SQUARE_PARENTHESIS_CLOSE = 60 + DOT = 61 + STRING_ENCLOSURE = 62 + COMMA = 63 + BOOL_LITERAL = 64 + INT_LITERAL = 65 + FLOAT_LITERAL = 66 + HEX_LITERAL = 67 + BIN_LITERAL = 68 + QUBIT_LITERAL = 69 + QUINT_LITERAL = 70 + QUSTRING_LITERAL = 71 + SYMBOL_LITERAL = 72 + STRING_LITERAL = 73 + WS = 74 + NEWLINE = 75 channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] @@ -308,37 +340,42 @@ class qutes_lexer(Lexer): literalNames = [ "", "'int'", "'bool'", "'string'", "'qubit'", "'quint'", "'qustring'", - "'float'", "'void'", "'return'", "'*'", "'/'", "'+'", "'-'", - "'not'", "'by'", "'swap'", "'pauliy'", "'pauliz'", "'grover'", - "'mcz'", "'mcx'", "'mcy'", "'mcp'", "'hadamard'", "'measure'", - "'print'", "'barrier'", "'=='", "'>'", "'>='", "'<'", "'<='", - "'='", "';'", "'var'", "'for'", "'search'", "'in'", "'where'", - "'if'", "'else'", "'while'", "'do'", "'{'", "'}'", "'('", "')'", - "'['", "']'", "'.'", "'\"'", "','" ] + "'float'", "'void'", "'return'", "'*'", "'/'", "'%'", "'+'", + "'-'", "'not'", "'and'", "'or'", "'by'", "'swap'", "'pauliy'", + "'pauliz'", "'grover'", "'mcz'", "'mcx'", "'mcy'", "'mcp'", + "'hadamard'", "'measure'", "'print'", "'barrier'", "'=='", "'!='", + "'>'", "'>='", "'<'", "'<='", "'='", "'++'", "'--'", "'+='", + "'-='", "'*='", "'/='", "'%='", "';'", "'var'", "'for'", "'search'", + "'in'", "'where'", "'if'", "'else'", "'while'", "'do'", "'{'", + "'}'", "'('", "')'", "'['", "']'", "'.'", "'\"'", "','" ] symbolicNames = [ "", "INT_TYPE", "BOOL_TYPE", "STRING_TYPE", "QUBIT_TYPE", "QUINT_TYPE", "QUSTRING_TYPE", "FLOAT_TYPE", "VOID_TYPE", "RETURN", "MULTIPLY", - "DIVIDE", "ADD", "SUB", "NOT", "BY", "SWAP", "PAULIY", "PAULIZ", - "GROVER", "MCZ", "MCX", "MCY", "MCP", "HADAMARD", "MEASURE", - "PRINT", "BARRIER", "EQUAL", "GREATER", "GREATEREQUAL", "LOWER", - "LOWEREQUAL", "ASSIGN", "END_OF_STATEMENT", "VAR_STATEMENT", - "FOR_STATEMENT", "SEARCH_STATEMENT", "IN_STATEMENT", "WHERE_STATEMENT", - "IF_STATEMENT", "ELSE_STATEMENT", "WHILE_STATEMENT", "DO_STATEMENT", - "CURLY_PARENTHESIS_OPEN", "CURLY_PARENTHESIS_CLOSE", "ROUND_PARENTHESIS_OPEN", - "ROUND_PARENTHESIS_CLOSE", "SQUARE_PARENTHESIS_OPEN", "SQUARE_PARENTHESIS_CLOSE", - "DOT", "STRING_ENCLOSURE", "COMMA", "BOOL_LITERAL", "INT_LITERAL", - "FLOAT_LITERAL", "HEX_LITERAL", "BIN_LITERAL", "QUBIT_LITERAL", - "QUINT_LITERAL", "QUSTRING_LITERAL", "SYMBOL_LITERAL", "STRING_LITERAL", - "WS", "NEWLINE" ] + "DIVIDE", "MODULE", "ADD", "SUB", "NOT", "AND", "OR", "BY", + "SWAP", "PAULIY", "PAULIZ", "GROVER", "MCZ", "MCX", "MCY", "MCP", + "HADAMARD", "MEASURE", "PRINT", "BARRIER", "EQUAL", "NOT_EQUAL", + "GREATER", "GREATEREQUAL", "LOWER", "LOWEREQUAL", "ASSIGN", + "AUTO_INCREMENT", "AUTO_DECREMENT", "AUTO_SUM", "AUTO_SUB", + "AUTO_MULTIPLY", "AUTO_DIVIDE", "AUTO_MODULE", "END_OF_STATEMENT", + "VAR_STATEMENT", "FOR_STATEMENT", "SEARCH_STATEMENT", "IN_STATEMENT", + "WHERE_STATEMENT", "IF_STATEMENT", "ELSE_STATEMENT", "WHILE_STATEMENT", + "DO_STATEMENT", "CURLY_PARENTHESIS_OPEN", "CURLY_PARENTHESIS_CLOSE", + "ROUND_PARENTHESIS_OPEN", "ROUND_PARENTHESIS_CLOSE", "SQUARE_PARENTHESIS_OPEN", + "SQUARE_PARENTHESIS_CLOSE", "DOT", "STRING_ENCLOSURE", "COMMA", + "BOOL_LITERAL", "INT_LITERAL", "FLOAT_LITERAL", "HEX_LITERAL", + "BIN_LITERAL", "QUBIT_LITERAL", "QUINT_LITERAL", "QUSTRING_LITERAL", + "SYMBOL_LITERAL", "STRING_LITERAL", "WS", "NEWLINE" ] ruleNames = [ "INT_TYPE", "BOOL_TYPE", "STRING_TYPE", "QUBIT_TYPE", "QUINT_TYPE", "QUSTRING_TYPE", "FLOAT_TYPE", "VOID_TYPE", - "RETURN", "MULTIPLY", "DIVIDE", "ADD", "SUB", "NOT", "BY", - "SWAP", "PAULIY", "PAULIZ", "GROVER", "MCZ", "MCX", "MCY", - "MCP", "HADAMARD", "MEASURE", "PRINT", "BARRIER", "EQUAL", - "GREATER", "GREATEREQUAL", "LOWER", "LOWEREQUAL", "ASSIGN", - "END_OF_STATEMENT", "VAR_STATEMENT", "FOR_STATEMENT", + "RETURN", "MULTIPLY", "DIVIDE", "MODULE", "ADD", "SUB", + "NOT", "AND", "OR", "BY", "SWAP", "PAULIY", "PAULIZ", + "GROVER", "MCZ", "MCX", "MCY", "MCP", "HADAMARD", "MEASURE", + "PRINT", "BARRIER", "EQUAL", "NOT_EQUAL", "GREATER", "GREATEREQUAL", + "LOWER", "LOWEREQUAL", "ASSIGN", "AUTO_INCREMENT", "AUTO_DECREMENT", + "AUTO_SUM", "AUTO_SUB", "AUTO_MULTIPLY", "AUTO_DIVIDE", + "AUTO_MODULE", "END_OF_STATEMENT", "VAR_STATEMENT", "FOR_STATEMENT", "SEARCH_STATEMENT", "IN_STATEMENT", "WHERE_STATEMENT", "IF_STATEMENT", "ELSE_STATEMENT", "WHILE_STATEMENT", "DO_STATEMENT", "CURLY_PARENTHESIS_OPEN", "CURLY_PARENTHESIS_CLOSE", "ROUND_PARENTHESIS_OPEN", diff --git a/src/qutes_antlr/qutes_lexer.tokens b/src/qutes_antlr/qutes_lexer.tokens index 41c14b1..2d74c03 100644 --- a/src/qutes_antlr/qutes_lexer.tokens +++ b/src/qutes_antlr/qutes_lexer.tokens @@ -9,59 +9,70 @@ VOID_TYPE=8 RETURN=9 MULTIPLY=10 DIVIDE=11 -ADD=12 -SUB=13 -NOT=14 -BY=15 -SWAP=16 -PAULIY=17 -PAULIZ=18 -GROVER=19 -MCZ=20 -MCX=21 -MCY=22 -MCP=23 -HADAMARD=24 -MEASURE=25 -PRINT=26 -BARRIER=27 -EQUAL=28 -GREATER=29 -GREATEREQUAL=30 -LOWER=31 -LOWEREQUAL=32 -ASSIGN=33 -END_OF_STATEMENT=34 -VAR_STATEMENT=35 -FOR_STATEMENT=36 -SEARCH_STATEMENT=37 -IN_STATEMENT=38 -WHERE_STATEMENT=39 -IF_STATEMENT=40 -ELSE_STATEMENT=41 -WHILE_STATEMENT=42 -DO_STATEMENT=43 -CURLY_PARENTHESIS_OPEN=44 -CURLY_PARENTHESIS_CLOSE=45 -ROUND_PARENTHESIS_OPEN=46 -ROUND_PARENTHESIS_CLOSE=47 -SQUARE_PARENTHESIS_OPEN=48 -SQUARE_PARENTHESIS_CLOSE=49 -DOT=50 -STRING_ENCLOSURE=51 -COMMA=52 -BOOL_LITERAL=53 -INT_LITERAL=54 -FLOAT_LITERAL=55 -HEX_LITERAL=56 -BIN_LITERAL=57 -QUBIT_LITERAL=58 -QUINT_LITERAL=59 -QUSTRING_LITERAL=60 -SYMBOL_LITERAL=61 -STRING_LITERAL=62 -WS=63 -NEWLINE=64 +MODULE=12 +ADD=13 +SUB=14 +NOT=15 +AND=16 +OR=17 +BY=18 +SWAP=19 +PAULIY=20 +PAULIZ=21 +GROVER=22 +MCZ=23 +MCX=24 +MCY=25 +MCP=26 +HADAMARD=27 +MEASURE=28 +PRINT=29 +BARRIER=30 +EQUAL=31 +NOT_EQUAL=32 +GREATER=33 +GREATEREQUAL=34 +LOWER=35 +LOWEREQUAL=36 +ASSIGN=37 +AUTO_INCREMENT=38 +AUTO_DECREMENT=39 +AUTO_SUM=40 +AUTO_SUB=41 +AUTO_MULTIPLY=42 +AUTO_DIVIDE=43 +AUTO_MODULE=44 +END_OF_STATEMENT=45 +VAR_STATEMENT=46 +FOR_STATEMENT=47 +SEARCH_STATEMENT=48 +IN_STATEMENT=49 +WHERE_STATEMENT=50 +IF_STATEMENT=51 +ELSE_STATEMENT=52 +WHILE_STATEMENT=53 +DO_STATEMENT=54 +CURLY_PARENTHESIS_OPEN=55 +CURLY_PARENTHESIS_CLOSE=56 +ROUND_PARENTHESIS_OPEN=57 +ROUND_PARENTHESIS_CLOSE=58 +SQUARE_PARENTHESIS_OPEN=59 +SQUARE_PARENTHESIS_CLOSE=60 +DOT=61 +STRING_ENCLOSURE=62 +COMMA=63 +BOOL_LITERAL=64 +INT_LITERAL=65 +FLOAT_LITERAL=66 +HEX_LITERAL=67 +BIN_LITERAL=68 +QUBIT_LITERAL=69 +QUINT_LITERAL=70 +QUSTRING_LITERAL=71 +SYMBOL_LITERAL=72 +STRING_LITERAL=73 +WS=74 +NEWLINE=75 'int'=1 'bool'=2 'string'=3 @@ -73,44 +84,55 @@ NEWLINE=64 'return'=9 '*'=10 '/'=11 -'+'=12 -'-'=13 -'not'=14 -'by'=15 -'swap'=16 -'pauliy'=17 -'pauliz'=18 -'grover'=19 -'mcz'=20 -'mcx'=21 -'mcy'=22 -'mcp'=23 -'hadamard'=24 -'measure'=25 -'print'=26 -'barrier'=27 -'=='=28 -'>'=29 -'>='=30 -'<'=31 -'<='=32 -'='=33 -';'=34 -'var'=35 -'for'=36 -'search'=37 -'in'=38 -'where'=39 -'if'=40 -'else'=41 -'while'=42 -'do'=43 -'{'=44 -'}'=45 -'('=46 -')'=47 -'['=48 -']'=49 -'.'=50 -'"'=51 -','=52 +'%'=12 +'+'=13 +'-'=14 +'not'=15 +'and'=16 +'or'=17 +'by'=18 +'swap'=19 +'pauliy'=20 +'pauliz'=21 +'grover'=22 +'mcz'=23 +'mcx'=24 +'mcy'=25 +'mcp'=26 +'hadamard'=27 +'measure'=28 +'print'=29 +'barrier'=30 +'=='=31 +'!='=32 +'>'=33 +'>='=34 +'<'=35 +'<='=36 +'='=37 +'++'=38 +'--'=39 +'+='=40 +'-='=41 +'*='=42 +'/='=43 +'%='=44 +';'=45 +'var'=46 +'for'=47 +'search'=48 +'in'=49 +'where'=50 +'if'=51 +'else'=52 +'while'=53 +'do'=54 +'{'=55 +'}'=56 +'('=57 +')'=58 +'['=59 +']'=60 +'.'=61 +'"'=62 +','=63 diff --git a/src/qutes_antlr/qutes_parser.py b/src/qutes_antlr/qutes_parser.py index c084c22..e1f9997 100644 --- a/src/qutes_antlr/qutes_parser.py +++ b/src/qutes_antlr/qutes_parser.py @@ -10,86 +10,90 @@ def serializedATN(): return [ - 4,1,64,228,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 4,1,75,232,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13, - 2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20, - 7,20,2,21,7,21,2,22,7,22,2,23,7,23,1,0,5,0,50,8,0,10,0,12,0,53,9, - 0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,78,8,1,10,1,12,1,81,9,1,1,1,1, - 1,1,1,1,1,1,1,3,1,88,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,109,8,1,1,2,1,2,1,2,3,2, - 114,8,2,1,3,1,3,1,3,1,3,3,3,120,8,3,1,4,1,4,1,4,3,4,125,8,4,1,5, - 1,5,1,5,1,5,1,5,3,5,132,8,5,1,6,1,6,1,6,1,6,1,7,1,7,1,7,3,7,141, - 8,7,1,7,1,7,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,3,9,154,8,9,1,10, - 1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10, - 1,10,1,10,1,10,1,10,1,10,1,10,3,10,176,8,10,3,10,178,8,10,1,10,1, - 10,1,10,1,10,1,10,1,10,5,10,186,8,10,10,10,12,10,189,9,10,1,11,1, - 11,1,11,3,11,194,8,11,1,12,1,12,1,13,1,13,3,13,200,8,13,1,14,1,14, - 1,14,5,14,205,8,14,10,14,12,14,208,9,14,1,15,1,15,1,16,1,16,1,17, - 1,17,1,18,1,18,1,19,1,19,1,20,1,20,1,21,1,21,1,22,1,22,1,23,1,23, - 1,23,0,1,20,24,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34, - 36,38,40,42,44,46,0,7,1,0,28,32,3,0,12,14,17,18,24,26,2,0,16,16, - 20,22,1,0,10,11,1,0,12,13,1,0,1,8,2,0,54,54,56,57,242,0,51,1,0,0, - 0,2,108,1,0,0,0,4,110,1,0,0,0,6,115,1,0,0,0,8,121,1,0,0,0,10,131, - 1,0,0,0,12,133,1,0,0,0,14,137,1,0,0,0,16,144,1,0,0,0,18,153,1,0, - 0,0,20,177,1,0,0,0,22,190,1,0,0,0,24,195,1,0,0,0,26,199,1,0,0,0, - 28,201,1,0,0,0,30,209,1,0,0,0,32,211,1,0,0,0,34,213,1,0,0,0,36,215, - 1,0,0,0,38,217,1,0,0,0,40,219,1,0,0,0,42,221,1,0,0,0,44,223,1,0, - 0,0,46,225,1,0,0,0,48,50,3,2,1,0,49,48,1,0,0,0,50,53,1,0,0,0,51, - 49,1,0,0,0,51,52,1,0,0,0,52,54,1,0,0,0,53,51,1,0,0,0,54,55,5,0,0, - 1,55,1,1,0,0,0,56,57,5,40,0,0,57,58,3,10,5,0,58,59,3,2,1,0,59,109, - 1,0,0,0,60,61,5,40,0,0,61,62,3,10,5,0,62,63,3,2,1,0,63,64,5,41,0, - 0,64,65,3,2,1,0,65,109,1,0,0,0,66,67,5,42,0,0,67,68,3,10,5,0,68, - 69,3,2,1,0,69,109,1,0,0,0,70,71,5,43,0,0,71,72,3,2,1,0,72,73,5,42, - 0,0,73,74,3,10,5,0,74,109,1,0,0,0,75,79,5,44,0,0,76,78,3,2,1,0,77, - 76,1,0,0,0,78,81,1,0,0,0,79,77,1,0,0,0,79,80,1,0,0,0,80,82,1,0,0, - 0,81,79,1,0,0,0,82,109,5,45,0,0,83,84,3,26,13,0,84,85,3,32,16,0, - 85,87,5,46,0,0,86,88,3,4,2,0,87,86,1,0,0,0,87,88,1,0,0,0,88,89,1, - 0,0,0,89,90,5,47,0,0,90,91,3,2,1,0,91,109,1,0,0,0,92,93,3,6,3,0, - 93,94,5,34,0,0,94,109,1,0,0,0,95,96,3,28,14,0,96,97,5,33,0,0,97, - 98,3,10,5,0,98,99,5,34,0,0,99,109,1,0,0,0,100,101,5,9,0,0,101,102, - 3,10,5,0,102,103,5,34,0,0,103,109,1,0,0,0,104,105,3,10,5,0,105,106, - 5,34,0,0,106,109,1,0,0,0,107,109,5,34,0,0,108,56,1,0,0,0,108,60, - 1,0,0,0,108,66,1,0,0,0,108,70,1,0,0,0,108,75,1,0,0,0,108,83,1,0, - 0,0,108,92,1,0,0,0,108,95,1,0,0,0,108,100,1,0,0,0,108,104,1,0,0, - 0,108,107,1,0,0,0,109,3,1,0,0,0,110,113,3,6,3,0,111,112,5,52,0,0, - 112,114,3,4,2,0,113,111,1,0,0,0,113,114,1,0,0,0,114,5,1,0,0,0,115, - 116,3,26,13,0,116,119,3,30,15,0,117,118,5,33,0,0,118,120,3,10,5, - 0,119,117,1,0,0,0,119,120,1,0,0,0,120,7,1,0,0,0,121,124,3,28,14, - 0,122,123,5,52,0,0,123,125,3,8,4,0,124,122,1,0,0,0,124,125,1,0,0, - 0,125,9,1,0,0,0,126,132,3,20,10,0,127,132,3,14,7,0,128,132,3,18, - 9,0,129,132,3,16,8,0,130,132,3,12,6,0,131,126,1,0,0,0,131,127,1, - 0,0,0,131,128,1,0,0,0,131,129,1,0,0,0,131,130,1,0,0,0,132,11,1,0, - 0,0,133,134,3,22,11,0,134,135,5,38,0,0,135,136,3,28,14,0,136,13, - 1,0,0,0,137,138,3,32,16,0,138,140,5,46,0,0,139,141,3,8,4,0,140,139, - 1,0,0,0,140,141,1,0,0,0,141,142,1,0,0,0,142,143,5,47,0,0,143,15, - 1,0,0,0,144,145,5,46,0,0,145,146,3,10,5,0,146,147,5,47,0,0,147,17, - 1,0,0,0,148,154,3,20,10,0,149,150,3,20,10,0,150,151,7,0,0,0,151, - 152,3,20,10,0,152,154,1,0,0,0,153,148,1,0,0,0,153,149,1,0,0,0,154, - 19,1,0,0,0,155,156,6,10,-1,0,156,157,7,1,0,0,157,178,3,20,10,4,158, - 159,7,2,0,0,159,178,3,22,11,0,160,161,5,23,0,0,161,162,3,22,11,0, - 162,163,5,15,0,0,163,164,3,10,5,0,164,178,1,0,0,0,165,176,3,46,23, - 0,166,176,3,44,22,0,167,176,3,42,21,0,168,176,3,36,18,0,169,176, - 3,38,19,0,170,176,3,40,20,0,171,176,3,28,14,0,172,176,5,25,0,0,173, - 176,5,27,0,0,174,176,3,34,17,0,175,165,1,0,0,0,175,166,1,0,0,0,175, - 167,1,0,0,0,175,168,1,0,0,0,175,169,1,0,0,0,175,170,1,0,0,0,175, - 171,1,0,0,0,175,172,1,0,0,0,175,173,1,0,0,0,175,174,1,0,0,0,176, - 178,1,0,0,0,177,155,1,0,0,0,177,158,1,0,0,0,177,160,1,0,0,0,177, - 175,1,0,0,0,178,187,1,0,0,0,179,180,10,6,0,0,180,181,7,3,0,0,181, - 186,3,20,10,7,182,183,10,5,0,0,183,184,7,4,0,0,184,186,3,20,10,6, - 185,179,1,0,0,0,185,182,1,0,0,0,186,189,1,0,0,0,187,185,1,0,0,0, - 187,188,1,0,0,0,188,21,1,0,0,0,189,187,1,0,0,0,190,193,3,20,10,0, - 191,192,5,52,0,0,192,194,3,22,11,0,193,191,1,0,0,0,193,194,1,0,0, - 0,194,23,1,0,0,0,195,196,7,5,0,0,196,25,1,0,0,0,197,200,3,24,12, - 0,198,200,3,28,14,0,199,197,1,0,0,0,199,198,1,0,0,0,200,27,1,0,0, - 0,201,206,5,61,0,0,202,203,5,50,0,0,203,205,5,61,0,0,204,202,1,0, - 0,0,205,208,1,0,0,0,206,204,1,0,0,0,206,207,1,0,0,0,207,29,1,0,0, - 0,208,206,1,0,0,0,209,210,5,61,0,0,210,31,1,0,0,0,211,212,5,61,0, - 0,212,33,1,0,0,0,213,214,5,62,0,0,214,35,1,0,0,0,215,216,5,58,0, - 0,216,37,1,0,0,0,217,218,5,59,0,0,218,39,1,0,0,0,219,220,5,60,0, - 0,220,41,1,0,0,0,221,222,5,55,0,0,222,43,1,0,0,0,223,224,7,6,0,0, - 224,45,1,0,0,0,225,226,5,53,0,0,226,47,1,0,0,0,17,51,79,87,108,113, - 119,124,131,140,153,175,177,185,187,193,199,206 + 2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,1,0, + 5,0,42,8,0,10,0,12,0,45,9,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,70,8, + 1,10,1,12,1,73,9,1,1,1,1,1,1,1,1,1,1,1,3,1,80,8,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,3,1,102,8,1,1,2,1,2,1,2,3,2,107,8,2,1,3,1,3,1,3,1,3,3,3,113,8, + 3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,125,8,4,1,4,1,4,1, + 4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,144, + 8,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4, + 1,4,1,4,1,4,1,4,1,4,5,4,166,8,4,10,4,12,4,169,9,4,1,5,1,5,3,5,173, + 8,5,1,5,1,5,3,5,177,8,5,1,6,1,6,3,6,181,8,6,1,6,1,6,3,6,185,8,6, + 1,7,1,7,3,7,189,8,7,1,8,1,8,1,9,1,9,1,9,5,9,196,8,9,10,9,12,9,199, + 9,9,1,9,1,9,3,9,203,8,9,1,10,1,10,1,11,1,11,1,12,1,12,1,12,1,12, + 1,12,1,12,1,12,3,12,216,8,12,1,13,1,13,1,14,1,14,1,15,1,15,1,16, + 1,16,1,17,1,17,1,18,1,18,1,19,1,19,1,19,0,1,8,20,0,2,4,6,8,10,12, + 14,16,18,20,22,24,26,28,30,32,34,36,38,0,11,2,0,28,28,30,30,2,0, + 13,15,38,39,2,0,19,19,23,25,2,0,20,21,27,29,1,0,10,12,1,0,13,14, + 1,0,33,36,1,0,31,32,1,0,38,39,1,0,1,8,2,0,65,65,67,68,257,0,43,1, + 0,0,0,2,101,1,0,0,0,4,103,1,0,0,0,6,108,1,0,0,0,8,143,1,0,0,0,10, + 172,1,0,0,0,12,180,1,0,0,0,14,188,1,0,0,0,16,190,1,0,0,0,18,202, + 1,0,0,0,20,204,1,0,0,0,22,206,1,0,0,0,24,215,1,0,0,0,26,217,1,0, + 0,0,28,219,1,0,0,0,30,221,1,0,0,0,32,223,1,0,0,0,34,225,1,0,0,0, + 36,227,1,0,0,0,38,229,1,0,0,0,40,42,3,2,1,0,41,40,1,0,0,0,42,45, + 1,0,0,0,43,41,1,0,0,0,43,44,1,0,0,0,44,46,1,0,0,0,45,43,1,0,0,0, + 46,47,5,0,0,1,47,1,1,0,0,0,48,49,5,51,0,0,49,50,3,8,4,0,50,51,3, + 2,1,0,51,102,1,0,0,0,52,53,5,51,0,0,53,54,3,8,4,0,54,55,3,2,1,0, + 55,56,5,52,0,0,56,57,3,2,1,0,57,102,1,0,0,0,58,59,5,53,0,0,59,60, + 3,8,4,0,60,61,3,2,1,0,61,102,1,0,0,0,62,63,5,54,0,0,63,64,3,2,1, + 0,64,65,5,53,0,0,65,66,3,8,4,0,66,102,1,0,0,0,67,71,5,55,0,0,68, + 70,3,2,1,0,69,68,1,0,0,0,70,73,1,0,0,0,71,69,1,0,0,0,71,72,1,0,0, + 0,72,74,1,0,0,0,73,71,1,0,0,0,74,102,5,56,0,0,75,76,3,14,7,0,76, + 77,3,22,11,0,77,79,5,57,0,0,78,80,3,4,2,0,79,78,1,0,0,0,79,80,1, + 0,0,0,80,81,1,0,0,0,81,82,5,58,0,0,82,83,3,2,1,0,83,102,1,0,0,0, + 84,85,3,6,3,0,85,86,5,45,0,0,86,102,1,0,0,0,87,88,3,18,9,0,88,89, + 5,37,0,0,89,90,3,8,4,0,90,91,5,45,0,0,91,102,1,0,0,0,92,93,5,9,0, + 0,93,94,3,8,4,0,94,95,5,45,0,0,95,102,1,0,0,0,96,97,3,8,4,0,97,98, + 5,45,0,0,98,102,1,0,0,0,99,102,7,0,0,0,100,102,5,45,0,0,101,48,1, + 0,0,0,101,52,1,0,0,0,101,58,1,0,0,0,101,62,1,0,0,0,101,67,1,0,0, + 0,101,75,1,0,0,0,101,84,1,0,0,0,101,87,1,0,0,0,101,92,1,0,0,0,101, + 96,1,0,0,0,101,99,1,0,0,0,101,100,1,0,0,0,102,3,1,0,0,0,103,106, + 3,6,3,0,104,105,5,63,0,0,105,107,3,4,2,0,106,104,1,0,0,0,106,107, + 1,0,0,0,107,5,1,0,0,0,108,109,3,14,7,0,109,112,3,20,10,0,110,111, + 5,37,0,0,111,113,3,8,4,0,112,110,1,0,0,0,112,113,1,0,0,0,113,7,1, + 0,0,0,114,115,6,4,-1,0,115,116,5,57,0,0,116,117,3,8,4,0,117,118, + 5,58,0,0,118,144,1,0,0,0,119,144,3,24,12,0,120,144,3,18,9,0,121, + 122,3,22,11,0,122,124,5,57,0,0,123,125,3,10,5,0,124,123,1,0,0,0, + 124,125,1,0,0,0,125,126,1,0,0,0,126,127,5,58,0,0,127,144,1,0,0,0, + 128,129,7,1,0,0,129,144,3,8,4,11,130,131,7,2,0,0,131,144,3,12,6, + 0,132,133,7,3,0,0,133,144,3,8,4,3,134,135,5,26,0,0,135,136,3,12, + 6,0,136,137,5,18,0,0,137,138,3,8,4,2,138,144,1,0,0,0,139,140,3,12, + 6,0,140,141,5,49,0,0,141,142,3,18,9,0,142,144,1,0,0,0,143,114,1, + 0,0,0,143,119,1,0,0,0,143,120,1,0,0,0,143,121,1,0,0,0,143,128,1, + 0,0,0,143,130,1,0,0,0,143,132,1,0,0,0,143,134,1,0,0,0,143,139,1, + 0,0,0,144,167,1,0,0,0,145,146,10,10,0,0,146,147,7,4,0,0,147,166, + 3,8,4,11,148,149,10,9,0,0,149,150,7,5,0,0,150,166,3,8,4,10,151,152, + 10,8,0,0,152,153,7,6,0,0,153,166,3,8,4,9,154,155,10,7,0,0,155,156, + 7,7,0,0,156,166,3,8,4,8,157,158,10,6,0,0,158,159,5,16,0,0,159,166, + 3,8,4,7,160,161,10,5,0,0,161,162,5,17,0,0,162,166,3,8,4,6,163,164, + 10,12,0,0,164,166,7,8,0,0,165,145,1,0,0,0,165,148,1,0,0,0,165,151, + 1,0,0,0,165,154,1,0,0,0,165,157,1,0,0,0,165,160,1,0,0,0,165,163, + 1,0,0,0,166,169,1,0,0,0,167,165,1,0,0,0,167,168,1,0,0,0,168,9,1, + 0,0,0,169,167,1,0,0,0,170,173,3,24,12,0,171,173,3,18,9,0,172,170, + 1,0,0,0,172,171,1,0,0,0,173,176,1,0,0,0,174,175,5,63,0,0,175,177, + 3,10,5,0,176,174,1,0,0,0,176,177,1,0,0,0,177,11,1,0,0,0,178,181, + 3,24,12,0,179,181,3,18,9,0,180,178,1,0,0,0,180,179,1,0,0,0,181,184, + 1,0,0,0,182,183,5,63,0,0,183,185,3,12,6,0,184,182,1,0,0,0,184,185, + 1,0,0,0,185,13,1,0,0,0,186,189,3,16,8,0,187,189,3,18,9,0,188,186, + 1,0,0,0,188,187,1,0,0,0,189,15,1,0,0,0,190,191,7,9,0,0,191,17,1, + 0,0,0,192,197,5,72,0,0,193,194,5,61,0,0,194,196,5,72,0,0,195,193, + 1,0,0,0,196,199,1,0,0,0,197,195,1,0,0,0,197,198,1,0,0,0,198,203, + 1,0,0,0,199,197,1,0,0,0,200,203,3,20,10,0,201,203,3,22,11,0,202, + 192,1,0,0,0,202,200,1,0,0,0,202,201,1,0,0,0,203,19,1,0,0,0,204,205, + 5,72,0,0,205,21,1,0,0,0,206,207,5,72,0,0,207,23,1,0,0,0,208,216, + 3,38,19,0,209,216,3,36,18,0,210,216,3,34,17,0,211,216,3,28,14,0, + 212,216,3,30,15,0,213,216,3,32,16,0,214,216,3,26,13,0,215,208,1, + 0,0,0,215,209,1,0,0,0,215,210,1,0,0,0,215,211,1,0,0,0,215,212,1, + 0,0,0,215,213,1,0,0,0,215,214,1,0,0,0,216,25,1,0,0,0,217,218,5,73, + 0,0,218,27,1,0,0,0,219,220,5,69,0,0,220,29,1,0,0,0,221,222,5,70, + 0,0,222,31,1,0,0,0,223,224,5,71,0,0,224,33,1,0,0,0,225,226,5,66, + 0,0,226,35,1,0,0,0,227,228,7,10,0,0,228,37,1,0,0,0,229,230,5,64, + 0,0,230,39,1,0,0,0,18,43,71,79,101,106,112,124,143,165,167,172,176, + 180,184,188,197,202,215 ] class qutes_parser ( Parser ): @@ -104,25 +108,29 @@ class qutes_parser ( Parser ): literalNames = [ "", "'int'", "'bool'", "'string'", "'qubit'", "'quint'", "'qustring'", "'float'", "'void'", "'return'", - "'*'", "'/'", "'+'", "'-'", "'not'", "'by'", "'swap'", - "'pauliy'", "'pauliz'", "'grover'", "'mcz'", "'mcx'", - "'mcy'", "'mcp'", "'hadamard'", "'measure'", "'print'", - "'barrier'", "'=='", "'>'", "'>='", "'<'", "'<='", - "'='", "';'", "'var'", "'for'", "'search'", "'in'", - "'where'", "'if'", "'else'", "'while'", "'do'", "'{'", - "'}'", "'('", "')'", "'['", "']'", "'.'", "'\"'", "','" ] + "'*'", "'/'", "'%'", "'+'", "'-'", "'not'", "'and'", + "'or'", "'by'", "'swap'", "'pauliy'", "'pauliz'", "'grover'", + "'mcz'", "'mcx'", "'mcy'", "'mcp'", "'hadamard'", "'measure'", + "'print'", "'barrier'", "'=='", "'!='", "'>'", "'>='", + "'<'", "'<='", "'='", "'++'", "'--'", "'+='", "'-='", + "'*='", "'/='", "'%='", "';'", "'var'", "'for'", "'search'", + "'in'", "'where'", "'if'", "'else'", "'while'", "'do'", + "'{'", "'}'", "'('", "')'", "'['", "']'", "'.'", "'\"'", + "','" ] symbolicNames = [ "", "INT_TYPE", "BOOL_TYPE", "STRING_TYPE", "QUBIT_TYPE", "QUINT_TYPE", "QUSTRING_TYPE", "FLOAT_TYPE", - "VOID_TYPE", "RETURN", "MULTIPLY", "DIVIDE", "ADD", - "SUB", "NOT", "BY", "SWAP", "PAULIY", "PAULIZ", "GROVER", - "MCZ", "MCX", "MCY", "MCP", "HADAMARD", "MEASURE", - "PRINT", "BARRIER", "EQUAL", "GREATER", "GREATEREQUAL", - "LOWER", "LOWEREQUAL", "ASSIGN", "END_OF_STATEMENT", - "VAR_STATEMENT", "FOR_STATEMENT", "SEARCH_STATEMENT", - "IN_STATEMENT", "WHERE_STATEMENT", "IF_STATEMENT", - "ELSE_STATEMENT", "WHILE_STATEMENT", "DO_STATEMENT", - "CURLY_PARENTHESIS_OPEN", "CURLY_PARENTHESIS_CLOSE", + "VOID_TYPE", "RETURN", "MULTIPLY", "DIVIDE", "MODULE", + "ADD", "SUB", "NOT", "AND", "OR", "BY", "SWAP", "PAULIY", + "PAULIZ", "GROVER", "MCZ", "MCX", "MCY", "MCP", "HADAMARD", + "MEASURE", "PRINT", "BARRIER", "EQUAL", "NOT_EQUAL", + "GREATER", "GREATEREQUAL", "LOWER", "LOWEREQUAL", + "ASSIGN", "AUTO_INCREMENT", "AUTO_DECREMENT", "AUTO_SUM", + "AUTO_SUB", "AUTO_MULTIPLY", "AUTO_DIVIDE", "AUTO_MODULE", + "END_OF_STATEMENT", "VAR_STATEMENT", "FOR_STATEMENT", + "SEARCH_STATEMENT", "IN_STATEMENT", "WHERE_STATEMENT", + "IF_STATEMENT", "ELSE_STATEMENT", "WHILE_STATEMENT", + "DO_STATEMENT", "CURLY_PARENTHESIS_OPEN", "CURLY_PARENTHESIS_CLOSE", "ROUND_PARENTHESIS_OPEN", "ROUND_PARENTHESIS_CLOSE", "SQUARE_PARENTHESIS_OPEN", "SQUARE_PARENTHESIS_CLOSE", "DOT", "STRING_ENCLOSURE", "COMMA", "BOOL_LITERAL", @@ -134,33 +142,28 @@ class qutes_parser ( Parser ): RULE_statement = 1 RULE_functionDeclarationParams = 2 RULE_variableDeclaration = 3 - RULE_functionCallParams = 4 - RULE_expr = 5 - RULE_groverExpr = 6 - RULE_functionCall = 7 - RULE_parenExpr = 8 - RULE_test = 9 - RULE_term = 10 - RULE_termList = 11 - RULE_type = 12 - RULE_variableType = 13 - RULE_qualifiedName = 14 - RULE_variableName = 15 - RULE_functionName = 16 - RULE_string = 17 - RULE_qubit = 18 - RULE_quint = 19 - RULE_qustring = 20 - RULE_float = 21 - RULE_integer = 22 - RULE_boolean = 23 + RULE_expr = 4 + RULE_functionCallParams = 5 + RULE_termList = 6 + RULE_variableType = 7 + RULE_type = 8 + RULE_qualifiedName = 9 + RULE_variableName = 10 + RULE_functionName = 11 + RULE_literal = 12 + RULE_string = 13 + RULE_qubit = 14 + RULE_quint = 15 + RULE_qustring = 16 + RULE_float = 17 + RULE_integer = 18 + RULE_boolean = 19 ruleNames = [ "program", "statement", "functionDeclarationParams", - "variableDeclaration", "functionCallParams", "expr", - "groverExpr", "functionCall", "parenExpr", "test", "term", - "termList", "type", "variableType", "qualifiedName", - "variableName", "functionName", "string", "qubit", "quint", - "qustring", "float", "integer", "boolean" ] + "variableDeclaration", "expr", "functionCallParams", + "termList", "variableType", "type", "qualifiedName", + "variableName", "functionName", "literal", "string", + "qubit", "quint", "qustring", "float", "integer", "boolean" ] EOF = Token.EOF INT_TYPE=1 @@ -174,59 +177,70 @@ class qutes_parser ( Parser ): RETURN=9 MULTIPLY=10 DIVIDE=11 - ADD=12 - SUB=13 - NOT=14 - BY=15 - SWAP=16 - PAULIY=17 - PAULIZ=18 - GROVER=19 - MCZ=20 - MCX=21 - MCY=22 - MCP=23 - HADAMARD=24 - MEASURE=25 - PRINT=26 - BARRIER=27 - EQUAL=28 - GREATER=29 - GREATEREQUAL=30 - LOWER=31 - LOWEREQUAL=32 - ASSIGN=33 - END_OF_STATEMENT=34 - VAR_STATEMENT=35 - FOR_STATEMENT=36 - SEARCH_STATEMENT=37 - IN_STATEMENT=38 - WHERE_STATEMENT=39 - IF_STATEMENT=40 - ELSE_STATEMENT=41 - WHILE_STATEMENT=42 - DO_STATEMENT=43 - CURLY_PARENTHESIS_OPEN=44 - CURLY_PARENTHESIS_CLOSE=45 - ROUND_PARENTHESIS_OPEN=46 - ROUND_PARENTHESIS_CLOSE=47 - SQUARE_PARENTHESIS_OPEN=48 - SQUARE_PARENTHESIS_CLOSE=49 - DOT=50 - STRING_ENCLOSURE=51 - COMMA=52 - BOOL_LITERAL=53 - INT_LITERAL=54 - FLOAT_LITERAL=55 - HEX_LITERAL=56 - BIN_LITERAL=57 - QUBIT_LITERAL=58 - QUINT_LITERAL=59 - QUSTRING_LITERAL=60 - SYMBOL_LITERAL=61 - STRING_LITERAL=62 - WS=63 - NEWLINE=64 + MODULE=12 + ADD=13 + SUB=14 + NOT=15 + AND=16 + OR=17 + BY=18 + SWAP=19 + PAULIY=20 + PAULIZ=21 + GROVER=22 + MCZ=23 + MCX=24 + MCY=25 + MCP=26 + HADAMARD=27 + MEASURE=28 + PRINT=29 + BARRIER=30 + EQUAL=31 + NOT_EQUAL=32 + GREATER=33 + GREATEREQUAL=34 + LOWER=35 + LOWEREQUAL=36 + ASSIGN=37 + AUTO_INCREMENT=38 + AUTO_DECREMENT=39 + AUTO_SUM=40 + AUTO_SUB=41 + AUTO_MULTIPLY=42 + AUTO_DIVIDE=43 + AUTO_MODULE=44 + END_OF_STATEMENT=45 + VAR_STATEMENT=46 + FOR_STATEMENT=47 + SEARCH_STATEMENT=48 + IN_STATEMENT=49 + WHERE_STATEMENT=50 + IF_STATEMENT=51 + ELSE_STATEMENT=52 + WHILE_STATEMENT=53 + DO_STATEMENT=54 + CURLY_PARENTHESIS_OPEN=55 + CURLY_PARENTHESIS_CLOSE=56 + ROUND_PARENTHESIS_OPEN=57 + ROUND_PARENTHESIS_CLOSE=58 + SQUARE_PARENTHESIS_OPEN=59 + SQUARE_PARENTHESIS_CLOSE=60 + DOT=61 + STRING_ENCLOSURE=62 + COMMA=63 + BOOL_LITERAL=64 + INT_LITERAL=65 + FLOAT_LITERAL=66 + HEX_LITERAL=67 + BIN_LITERAL=68 + QUBIT_LITERAL=69 + QUINT_LITERAL=70 + QUSTRING_LITERAL=71 + SYMBOL_LITERAL=72 + STRING_LITERAL=73 + WS=74 + NEWLINE=75 def __init__(self, input:TokenStream, output:TextIO = sys.stdout): super().__init__(input, output) @@ -281,17 +295,17 @@ def program(self): self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 51 + self.state = 43 self._errHandler.sync(self) _la = self._input.LA(1) - while (((_la) & ~0x3f) == 0 and ((1 << _la) & 9214467109629162494) != 0): - self.state = 48 + while (((_la) & ~0x3f) == 0 and ((1 << _la) & 209453393821361150) != 0) or ((((_la - 64)) & ~0x3f) == 0 and ((1 << (_la - 64)) & 1023) != 0): + self.state = 40 self.statement() - self.state = 53 + self.state = 45 self._errHandler.sync(self) _la = self._input.LA(1) - self.state = 54 + self.state = 46 self.match(qutes_parser.EOF) except RecognitionException as re: localctx.exception = re @@ -419,6 +433,32 @@ def accept(self, visitor:ParseTreeVisitor): return visitor.visitChildren(self) + class FactStatementContext(StatementContext): + + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.StatementContext + super().__init__(parser) + self.copyFrom(ctx) + + def MEASURE(self): + return self.getToken(qutes_parser.MEASURE, 0) + def BARRIER(self): + return self.getToken(qutes_parser.BARRIER, 0) + + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterFactStatement" ): + listener.enterFactStatement(self) + + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitFactStatement" ): + listener.exitFactStatement(self) + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitFactStatement" ): + return visitor.visitFactStatement(self) + else: + return visitor.visitChildren(self) + + class ExpressionStatementContext(StatementContext): def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.StatementContext @@ -662,147 +702,159 @@ def statement(self): self.enterRule(localctx, 2, self.RULE_statement) self._la = 0 # Token type try: - self.state = 108 + self.state = 101 self._errHandler.sync(self) la_ = self._interp.adaptivePredict(self._input,3,self._ctx) if la_ == 1: localctx = qutes_parser.IfStatementContext(self, localctx) self.enterOuterAlt(localctx, 1) - self.state = 56 + self.state = 48 self.match(qutes_parser.IF_STATEMENT) - self.state = 57 - self.expr() - self.state = 58 + self.state = 49 + self.expr(0) + self.state = 50 self.statement() pass elif la_ == 2: localctx = qutes_parser.IfElseStatementContext(self, localctx) self.enterOuterAlt(localctx, 2) - self.state = 60 + self.state = 52 self.match(qutes_parser.IF_STATEMENT) - self.state = 61 - self.expr() - self.state = 62 + self.state = 53 + self.expr(0) + self.state = 54 self.statement() - self.state = 63 + self.state = 55 self.match(qutes_parser.ELSE_STATEMENT) - self.state = 64 + self.state = 56 self.statement() pass elif la_ == 3: localctx = qutes_parser.WhileStatementContext(self, localctx) self.enterOuterAlt(localctx, 3) - self.state = 66 + self.state = 58 self.match(qutes_parser.WHILE_STATEMENT) - self.state = 67 - self.expr() - self.state = 68 + self.state = 59 + self.expr(0) + self.state = 60 self.statement() pass elif la_ == 4: localctx = qutes_parser.DoWhileStatementContext(self, localctx) self.enterOuterAlt(localctx, 4) - self.state = 70 + self.state = 62 self.match(qutes_parser.DO_STATEMENT) - self.state = 71 + self.state = 63 self.statement() - self.state = 72 + self.state = 64 self.match(qutes_parser.WHILE_STATEMENT) - self.state = 73 - self.expr() + self.state = 65 + self.expr(0) pass elif la_ == 5: localctx = qutes_parser.BlockStatementContext(self, localctx) self.enterOuterAlt(localctx, 5) - self.state = 75 + self.state = 67 self.match(qutes_parser.CURLY_PARENTHESIS_OPEN) - self.state = 79 + self.state = 71 self._errHandler.sync(self) _la = self._input.LA(1) - while (((_la) & ~0x3f) == 0 and ((1 << _la) & 9214467109629162494) != 0): - self.state = 76 + while (((_la) & ~0x3f) == 0 and ((1 << _la) & 209453393821361150) != 0) or ((((_la - 64)) & ~0x3f) == 0 and ((1 << (_la - 64)) & 1023) != 0): + self.state = 68 self.statement() - self.state = 81 + self.state = 73 self._errHandler.sync(self) _la = self._input.LA(1) - self.state = 82 + self.state = 74 self.match(qutes_parser.CURLY_PARENTHESIS_CLOSE) pass elif la_ == 6: localctx = qutes_parser.FunctionStatementContext(self, localctx) self.enterOuterAlt(localctx, 6) - self.state = 83 + self.state = 75 self.variableType() - self.state = 84 + self.state = 76 self.functionName() - self.state = 85 + self.state = 77 self.match(qutes_parser.ROUND_PARENTHESIS_OPEN) - self.state = 87 + self.state = 79 self._errHandler.sync(self) _la = self._input.LA(1) - if (((_la) & ~0x3f) == 0 and ((1 << _la) & 2305843009213694462) != 0): - self.state = 86 + if (((_la) & ~0x3f) == 0 and ((1 << _la) & 510) != 0) or _la==72: + self.state = 78 self.functionDeclarationParams() - self.state = 89 + self.state = 81 self.match(qutes_parser.ROUND_PARENTHESIS_CLOSE) - self.state = 90 + self.state = 82 self.statement() pass elif la_ == 7: localctx = qutes_parser.DeclarationStatementContext(self, localctx) self.enterOuterAlt(localctx, 7) - self.state = 92 + self.state = 84 self.variableDeclaration() - self.state = 93 + self.state = 85 self.match(qutes_parser.END_OF_STATEMENT) pass elif la_ == 8: localctx = qutes_parser.AssignmentStatementContext(self, localctx) self.enterOuterAlt(localctx, 8) - self.state = 95 + self.state = 87 self.qualifiedName() - self.state = 96 + self.state = 88 self.match(qutes_parser.ASSIGN) - self.state = 97 - self.expr() - self.state = 98 + self.state = 89 + self.expr(0) + self.state = 90 self.match(qutes_parser.END_OF_STATEMENT) pass elif la_ == 9: localctx = qutes_parser.ReturnStatementContext(self, localctx) self.enterOuterAlt(localctx, 9) - self.state = 100 + self.state = 92 self.match(qutes_parser.RETURN) - self.state = 101 - self.expr() - self.state = 102 + self.state = 93 + self.expr(0) + self.state = 94 self.match(qutes_parser.END_OF_STATEMENT) pass elif la_ == 10: localctx = qutes_parser.ExpressionStatementContext(self, localctx) self.enterOuterAlt(localctx, 10) - self.state = 104 - self.expr() - self.state = 105 + self.state = 96 + self.expr(0) + self.state = 97 self.match(qutes_parser.END_OF_STATEMENT) pass elif la_ == 11: - localctx = qutes_parser.EmptyStatementContext(self, localctx) + localctx = qutes_parser.FactStatementContext(self, localctx) self.enterOuterAlt(localctx, 11) - self.state = 107 + self.state = 99 + _la = self._input.LA(1) + if not(_la==28 or _la==30): + self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + pass + + elif la_ == 12: + localctx = qutes_parser.EmptyStatementContext(self, localctx) + self.enterOuterAlt(localctx, 12) + self.state = 100 self.match(qutes_parser.END_OF_STATEMENT) pass @@ -861,15 +913,15 @@ def functionDeclarationParams(self): self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 110 + self.state = 103 self.variableDeclaration() - self.state = 113 + self.state = 106 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==52: - self.state = 111 + if _la==63: + self.state = 104 self.match(qutes_parser.COMMA) - self.state = 112 + self.state = 105 self.functionDeclarationParams() @@ -931,18 +983,18 @@ def variableDeclaration(self): self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 115 + self.state = 108 self.variableType() - self.state = 116 + self.state = 109 self.variableName() - self.state = 119 + self.state = 112 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==33: - self.state = 117 + if _la==37: + self.state = 110 self.match(qutes_parser.ASSIGN) - self.state = 118 - self.expr() + self.state = 111 + self.expr(0) except RecognitionException as re: @@ -954,466 +1006,275 @@ def variableDeclaration(self): return localctx - class FunctionCallParamsContext(ParserRuleContext): + class ExprContext(ParserRuleContext): __slots__ = 'parser' def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser - def qualifiedName(self): - return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) + def getRuleIndex(self): + return qutes_parser.RULE_expr - def COMMA(self): - return self.getToken(qutes_parser.COMMA, 0) + + def copyFrom(self, ctx:ParserRuleContext): + super().copyFrom(ctx) - def functionCallParams(self): - return self.getTypedRuleContext(qutes_parser.FunctionCallParamsContext,0) + class QualifiedNameExpressionContext(ExprContext): + + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.copyFrom(ctx) + + def qualifiedName(self): + return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) - def getRuleIndex(self): - return qutes_parser.RULE_functionCallParams def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterFunctionCallParams" ): - listener.enterFunctionCallParams(self) + if hasattr( listener, "enterQualifiedNameExpression" ): + listener.enterQualifiedNameExpression(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitFunctionCallParams" ): - listener.exitFunctionCallParams(self) + if hasattr( listener, "exitQualifiedNameExpression" ): + listener.exitQualifiedNameExpression(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitFunctionCallParams" ): - return visitor.visitFunctionCallParams(self) + if hasattr( visitor, "visitQualifiedNameExpression" ): + return visitor.visitQualifiedNameExpression(self) else: return visitor.visitChildren(self) + class RelationalOperatorContext(ExprContext): + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) - def functionCallParams(self): + def expr(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(qutes_parser.ExprContext) + else: + return self.getTypedRuleContext(qutes_parser.ExprContext,i) - localctx = qutes_parser.FunctionCallParamsContext(self, self._ctx, self.state) - self.enterRule(localctx, 8, self.RULE_functionCallParams) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 121 - self.qualifiedName() - self.state = 124 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la==52: - self.state = 122 - self.match(qutes_parser.COMMA) - self.state = 123 - self.functionCallParams() + def GREATEREQUAL(self): + return self.getToken(qutes_parser.GREATEREQUAL, 0) + def LOWEREQUAL(self): + return self.getToken(qutes_parser.LOWEREQUAL, 0) + def GREATER(self): + return self.getToken(qutes_parser.GREATER, 0) + def LOWER(self): + return self.getToken(qutes_parser.LOWER, 0) + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterRelationalOperator" ): + listener.enterRelationalOperator(self) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitRelationalOperator" ): + listener.exitRelationalOperator(self) + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitRelationalOperator" ): + return visitor.visitRelationalOperator(self) + else: + return visitor.visitChildren(self) - class ExprContext(ParserRuleContext): - __slots__ = 'parser' - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): - super().__init__(parent, invokingState) - self.parser = parser + class LogicAndOperatorContext(ExprContext): - def term(self): - return self.getTypedRuleContext(qutes_parser.TermContext,0) + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + def expr(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(qutes_parser.ExprContext) + else: + return self.getTypedRuleContext(qutes_parser.ExprContext,i) - def functionCall(self): - return self.getTypedRuleContext(qutes_parser.FunctionCallContext,0) + def AND(self): + return self.getToken(qutes_parser.AND, 0) + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterLogicAndOperator" ): + listener.enterLogicAndOperator(self) - def test(self): - return self.getTypedRuleContext(qutes_parser.TestContext,0) + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitLogicAndOperator" ): + listener.exitLogicAndOperator(self) + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitLogicAndOperator" ): + return visitor.visitLogicAndOperator(self) + else: + return visitor.visitChildren(self) - def parenExpr(self): - return self.getTypedRuleContext(qutes_parser.ParenExprContext,0) + class PrefixOperatorContext(ExprContext): - def groverExpr(self): - return self.getTypedRuleContext(qutes_parser.GroverExprContext,0) + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + def expr(self): + return self.getTypedRuleContext(qutes_parser.ExprContext,0) - def getRuleIndex(self): - return qutes_parser.RULE_expr + def NOT(self): + return self.getToken(qutes_parser.NOT, 0) + def ADD(self): + return self.getToken(qutes_parser.ADD, 0) + def SUB(self): + return self.getToken(qutes_parser.SUB, 0) + def AUTO_INCREMENT(self): + return self.getToken(qutes_parser.AUTO_INCREMENT, 0) + def AUTO_DECREMENT(self): + return self.getToken(qutes_parser.AUTO_DECREMENT, 0) def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterExpr" ): - listener.enterExpr(self) + if hasattr( listener, "enterPrefixOperator" ): + listener.enterPrefixOperator(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitExpr" ): - listener.exitExpr(self) + if hasattr( listener, "exitPrefixOperator" ): + listener.exitPrefixOperator(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitExpr" ): - return visitor.visitExpr(self) + if hasattr( visitor, "visitPrefixOperator" ): + return visitor.visitPrefixOperator(self) else: return visitor.visitChildren(self) + class LiteralExpressionContext(ExprContext): + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.copyFrom(ctx) - def expr(self): - - localctx = qutes_parser.ExprContext(self, self._ctx, self.state) - self.enterRule(localctx, 10, self.RULE_expr) - try: - self.state = 131 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,7,self._ctx) - if la_ == 1: - self.enterOuterAlt(localctx, 1) - self.state = 126 - self.term(0) - pass - - elif la_ == 2: - self.enterOuterAlt(localctx, 2) - self.state = 127 - self.functionCall() - pass - - elif la_ == 3: - self.enterOuterAlt(localctx, 3) - self.state = 128 - self.test() - pass + def literal(self): + return self.getTypedRuleContext(qutes_parser.LiteralContext,0) - elif la_ == 4: - self.enterOuterAlt(localctx, 4) - self.state = 129 - self.parenExpr() - pass - elif la_ == 5: - self.enterOuterAlt(localctx, 5) - self.state = 130 - self.groverExpr() - pass + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterLiteralExpression" ): + listener.enterLiteralExpression(self) + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitLiteralExpression" ): + listener.exitLiteralExpression(self) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitLiteralExpression" ): + return visitor.visitLiteralExpression(self) + else: + return visitor.visitChildren(self) - class GroverExprContext(ParserRuleContext): - __slots__ = 'parser' + class GroverOperatorContext(ExprContext): - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): - super().__init__(parent, invokingState) - self.parser = parser + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) self.op = None # Token + self.copyFrom(ctx) def termList(self): return self.getTypedRuleContext(qutes_parser.TermListContext,0) - def qualifiedName(self): return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) - def IN_STATEMENT(self): return self.getToken(qutes_parser.IN_STATEMENT, 0) - def getRuleIndex(self): - return qutes_parser.RULE_groverExpr - def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterGroverExpr" ): - listener.enterGroverExpr(self) + if hasattr( listener, "enterGroverOperator" ): + listener.enterGroverOperator(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitGroverExpr" ): - listener.exitGroverExpr(self) + if hasattr( listener, "exitGroverOperator" ): + listener.exitGroverOperator(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitGroverExpr" ): - return visitor.visitGroverExpr(self) + if hasattr( visitor, "visitGroverOperator" ): + return visitor.visitGroverOperator(self) else: return visitor.visitChildren(self) + class FunctionCallExpressionContext(ExprContext): - - def groverExpr(self): - - localctx = qutes_parser.GroverExprContext(self, self._ctx, self.state) - self.enterRule(localctx, 12, self.RULE_groverExpr) - try: - self.enterOuterAlt(localctx, 1) - self.state = 133 - self.termList() - self.state = 134 - localctx.op = self.match(qutes_parser.IN_STATEMENT) - self.state = 135 - self.qualifiedName() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - - class FunctionCallContext(ParserRuleContext): - __slots__ = 'parser' - - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): - super().__init__(parent, invokingState) - self.parser = parser + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.copyFrom(ctx) def functionName(self): return self.getTypedRuleContext(qutes_parser.FunctionNameContext,0) - def ROUND_PARENTHESIS_OPEN(self): return self.getToken(qutes_parser.ROUND_PARENTHESIS_OPEN, 0) - def ROUND_PARENTHESIS_CLOSE(self): return self.getToken(qutes_parser.ROUND_PARENTHESIS_CLOSE, 0) - def functionCallParams(self): return self.getTypedRuleContext(qutes_parser.FunctionCallParamsContext,0) - def getRuleIndex(self): - return qutes_parser.RULE_functionCall - def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterFunctionCall" ): - listener.enterFunctionCall(self) + if hasattr( listener, "enterFunctionCallExpression" ): + listener.enterFunctionCallExpression(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitFunctionCall" ): - listener.exitFunctionCall(self) + if hasattr( listener, "exitFunctionCallExpression" ): + listener.exitFunctionCallExpression(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitFunctionCall" ): - return visitor.visitFunctionCall(self) + if hasattr( visitor, "visitFunctionCallExpression" ): + return visitor.visitFunctionCallExpression(self) else: return visitor.visitChildren(self) + class EqualityOperatorContext(ExprContext): + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) - def functionCall(self): - - localctx = qutes_parser.FunctionCallContext(self, self._ctx, self.state) - self.enterRule(localctx, 14, self.RULE_functionCall) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 137 - self.functionName() - self.state = 138 - self.match(qutes_parser.ROUND_PARENTHESIS_OPEN) - self.state = 140 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la==61: - self.state = 139 - self.functionCallParams() - - - self.state = 142 - self.match(qutes_parser.ROUND_PARENTHESIS_CLOSE) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - - class ParenExprContext(ParserRuleContext): - __slots__ = 'parser' - - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): - super().__init__(parent, invokingState) - self.parser = parser - - def ROUND_PARENTHESIS_OPEN(self): - return self.getToken(qutes_parser.ROUND_PARENTHESIS_OPEN, 0) - - def expr(self): - return self.getTypedRuleContext(qutes_parser.ExprContext,0) - - - def ROUND_PARENTHESIS_CLOSE(self): - return self.getToken(qutes_parser.ROUND_PARENTHESIS_CLOSE, 0) - - def getRuleIndex(self): - return qutes_parser.RULE_parenExpr - - def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterParenExpr" ): - listener.enterParenExpr(self) - - def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitParenExpr" ): - listener.exitParenExpr(self) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitParenExpr" ): - return visitor.visitParenExpr(self) - else: - return visitor.visitChildren(self) - - - - - def parenExpr(self): - - localctx = qutes_parser.ParenExprContext(self, self._ctx, self.state) - self.enterRule(localctx, 16, self.RULE_parenExpr) - try: - self.enterOuterAlt(localctx, 1) - self.state = 144 - self.match(qutes_parser.ROUND_PARENTHESIS_OPEN) - self.state = 145 - self.expr() - self.state = 146 - self.match(qutes_parser.ROUND_PARENTHESIS_CLOSE) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - - class TestContext(ParserRuleContext): - __slots__ = 'parser' - - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): - super().__init__(parent, invokingState) - self.parser = parser - self.op = None # Token - - def term(self, i:int=None): - if i is None: - return self.getTypedRuleContexts(qutes_parser.TermContext) - else: - return self.getTypedRuleContext(qutes_parser.TermContext,i) - - - def GREATER(self): - return self.getToken(qutes_parser.GREATER, 0) - - def LOWER(self): - return self.getToken(qutes_parser.LOWER, 0) + def expr(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(qutes_parser.ExprContext) + else: + return self.getTypedRuleContext(qutes_parser.ExprContext,i) def EQUAL(self): return self.getToken(qutes_parser.EQUAL, 0) - - def GREATEREQUAL(self): - return self.getToken(qutes_parser.GREATEREQUAL, 0) - - def LOWEREQUAL(self): - return self.getToken(qutes_parser.LOWEREQUAL, 0) - - def getRuleIndex(self): - return qutes_parser.RULE_test + def NOT_EQUAL(self): + return self.getToken(qutes_parser.NOT_EQUAL, 0) def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterTest" ): - listener.enterTest(self) + if hasattr( listener, "enterEqualityOperator" ): + listener.enterEqualityOperator(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitTest" ): - listener.exitTest(self) + if hasattr( listener, "exitEqualityOperator" ): + listener.exitEqualityOperator(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTest" ): - return visitor.visitTest(self) + if hasattr( visitor, "visitEqualityOperator" ): + return visitor.visitEqualityOperator(self) else: return visitor.visitChildren(self) + class MultipleUnaryOperatorContext(ExprContext): - - def test(self): - - localctx = qutes_parser.TestContext(self, self._ctx, self.state) - self.enterRule(localctx, 18, self.RULE_test) - self._la = 0 # Token type - try: - self.state = 153 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,9,self._ctx) - if la_ == 1: - self.enterOuterAlt(localctx, 1) - self.state = 148 - self.term(0) - pass - - elif la_ == 2: - self.enterOuterAlt(localctx, 2) - self.state = 149 - self.term(0) - self.state = 150 - localctx.op = self._input.LT(1) - _la = self._input.LA(1) - if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 8321499136) != 0)): - localctx.op = self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - self.state = 151 - self.term(0) - pass - - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - - class TermContext(ParserRuleContext): - __slots__ = 'parser' - - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): - super().__init__(parent, invokingState) - self.parser = parser - - - def getRuleIndex(self): - return qutes_parser.RULE_term - - - def copyFrom(self, ctx:ParserRuleContext): - super().copyFrom(ctx) - - - class MultipleUnaryOperatorContext(TermContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.TermContext + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext super().__init__(parser) self.op = None # Token self.copyFrom(ctx) @@ -1445,92 +1306,101 @@ def accept(self, visitor:ParseTreeVisitor): return visitor.visitChildren(self) - class BinaryPriorityOperatorContext(TermContext): + class SumOperatorContext(ExprContext): - def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.TermContext + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext super().__init__(parser) self.op = None # Token self.copyFrom(ctx) - def term(self, i:int=None): + def expr(self, i:int=None): if i is None: - return self.getTypedRuleContexts(qutes_parser.TermContext) + return self.getTypedRuleContexts(qutes_parser.ExprContext) else: - return self.getTypedRuleContext(qutes_parser.TermContext,i) + return self.getTypedRuleContext(qutes_parser.ExprContext,i) - def MULTIPLY(self): - return self.getToken(qutes_parser.MULTIPLY, 0) - def DIVIDE(self): - return self.getToken(qutes_parser.DIVIDE, 0) + def ADD(self): + return self.getToken(qutes_parser.ADD, 0) + def SUB(self): + return self.getToken(qutes_parser.SUB, 0) def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterBinaryPriorityOperator" ): - listener.enterBinaryPriorityOperator(self) + if hasattr( listener, "enterSumOperator" ): + listener.enterSumOperator(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitBinaryPriorityOperator" ): - listener.exitBinaryPriorityOperator(self) + if hasattr( listener, "exitSumOperator" ): + listener.exitSumOperator(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitBinaryPriorityOperator" ): - return visitor.visitBinaryPriorityOperator(self) + if hasattr( visitor, "visitSumOperator" ): + return visitor.visitSumOperator(self) else: return visitor.visitChildren(self) - class IdentityOperatorContext(TermContext): + class PostfixOperatorContext(ExprContext): - def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.TermContext + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext super().__init__(parser) + self.op = None # Token self.copyFrom(ctx) - def boolean(self): - return self.getTypedRuleContext(qutes_parser.BooleanContext,0) + def expr(self): + return self.getTypedRuleContext(qutes_parser.ExprContext,0) - def integer(self): - return self.getTypedRuleContext(qutes_parser.IntegerContext,0) + def AUTO_INCREMENT(self): + return self.getToken(qutes_parser.AUTO_INCREMENT, 0) + def AUTO_DECREMENT(self): + return self.getToken(qutes_parser.AUTO_DECREMENT, 0) - def float_(self): - return self.getTypedRuleContext(qutes_parser.FloatContext,0) + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterPostfixOperator" ): + listener.enterPostfixOperator(self) - def qubit(self): - return self.getTypedRuleContext(qutes_parser.QubitContext,0) + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitPostfixOperator" ): + listener.exitPostfixOperator(self) - def quint(self): - return self.getTypedRuleContext(qutes_parser.QuintContext,0) + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPostfixOperator" ): + return visitor.visitPostfixOperator(self) + else: + return visitor.visitChildren(self) - def qustring(self): - return self.getTypedRuleContext(qutes_parser.QustringContext,0) - def qualifiedName(self): - return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) + class ParentesizeExpressionContext(ExprContext): - def MEASURE(self): - return self.getToken(qutes_parser.MEASURE, 0) - def BARRIER(self): - return self.getToken(qutes_parser.BARRIER, 0) - def string(self): - return self.getTypedRuleContext(qutes_parser.StringContext,0) + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.copyFrom(ctx) + + def ROUND_PARENTHESIS_OPEN(self): + return self.getToken(qutes_parser.ROUND_PARENTHESIS_OPEN, 0) + def expr(self): + return self.getTypedRuleContext(qutes_parser.ExprContext,0) + def ROUND_PARENTHESIS_CLOSE(self): + return self.getToken(qutes_parser.ROUND_PARENTHESIS_CLOSE, 0) def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterIdentityOperator" ): - listener.enterIdentityOperator(self) + if hasattr( listener, "enterParentesizeExpression" ): + listener.enterParentesizeExpression(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitIdentityOperator" ): - listener.exitIdentityOperator(self) + if hasattr( listener, "exitParentesizeExpression" ): + listener.exitParentesizeExpression(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitIdentityOperator" ): - return visitor.visitIdentityOperator(self) + if hasattr( visitor, "visitParentesizeExpression" ): + return visitor.visitParentesizeExpression(self) else: return visitor.visitChildren(self) - class MultipleUnaryPhaseOperatorContext(TermContext): + class MultipleUnaryPhaseOperatorContext(ExprContext): - def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.TermContext + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext super().__init__(parser) self.op = None # Token self.copyFrom(ctx) @@ -1561,20 +1431,53 @@ def accept(self, visitor:ParseTreeVisitor): return visitor.visitChildren(self) - class UnaryOperatorContext(TermContext): + class MultiplicativeOperatorContext(ExprContext): + + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + + def expr(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(qutes_parser.ExprContext) + else: + return self.getTypedRuleContext(qutes_parser.ExprContext,i) + + def MULTIPLY(self): + return self.getToken(qutes_parser.MULTIPLY, 0) + def DIVIDE(self): + return self.getToken(qutes_parser.DIVIDE, 0) + def MODULE(self): + return self.getToken(qutes_parser.MODULE, 0) + + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterMultiplicativeOperator" ): + listener.enterMultiplicativeOperator(self) + + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitMultiplicativeOperator" ): + listener.exitMultiplicativeOperator(self) + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitMultiplicativeOperator" ): + return visitor.visitMultiplicativeOperator(self) + else: + return visitor.visitChildren(self) + + + class UnaryOperatorContext(ExprContext): - def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.TermContext + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext super().__init__(parser) self.op = None # Token self.copyFrom(ctx) - def term(self): - return self.getTypedRuleContext(qutes_parser.TermContext,0) + def expr(self): + return self.getTypedRuleContext(qutes_parser.ExprContext,0) def PRINT(self): return self.getToken(qutes_parser.PRINT, 0) - def NOT(self): - return self.getToken(qutes_parser.NOT, 0) def PAULIY(self): return self.getToken(qutes_parser.PAULIY, 0) def PAULIZ(self): @@ -1583,10 +1486,6 @@ def HADAMARD(self): return self.getToken(qutes_parser.HADAMARD, 0) def MEASURE(self): return self.getToken(qutes_parser.MEASURE, 0) - def ADD(self): - return self.getToken(qutes_parser.ADD, 0) - def SUB(self): - return self.getToken(qutes_parser.SUB, 0) def enterRule(self, listener:ParseTreeListener): if hasattr( listener, "enterUnaryOperator" ): @@ -1603,272 +1502,538 @@ def accept(self, visitor:ParseTreeVisitor): return visitor.visitChildren(self) - class BinaryOperatorContext(TermContext): + class LogicOrOperatorContext(ExprContext): - def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.TermContext + def __init__(self, parser, ctx:ParserRuleContext): # actually a qutes_parser.ExprContext super().__init__(parser) self.op = None # Token self.copyFrom(ctx) - def term(self, i:int=None): + def expr(self, i:int=None): if i is None: - return self.getTypedRuleContexts(qutes_parser.TermContext) + return self.getTypedRuleContexts(qutes_parser.ExprContext) else: - return self.getTypedRuleContext(qutes_parser.TermContext,i) + return self.getTypedRuleContext(qutes_parser.ExprContext,i) - def ADD(self): - return self.getToken(qutes_parser.ADD, 0) - def SUB(self): - return self.getToken(qutes_parser.SUB, 0) + def OR(self): + return self.getToken(qutes_parser.OR, 0) def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterBinaryOperator" ): - listener.enterBinaryOperator(self) + if hasattr( listener, "enterLogicOrOperator" ): + listener.enterLogicOrOperator(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitBinaryOperator" ): - listener.exitBinaryOperator(self) + if hasattr( listener, "exitLogicOrOperator" ): + listener.exitLogicOrOperator(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitBinaryOperator" ): - return visitor.visitBinaryOperator(self) + if hasattr( visitor, "visitLogicOrOperator" ): + return visitor.visitLogicOrOperator(self) else: return visitor.visitChildren(self) - def term(self, _p:int=0): + def expr(self, _p:int=0): _parentctx = self._ctx _parentState = self.state - localctx = qutes_parser.TermContext(self, self._ctx, _parentState) + localctx = qutes_parser.ExprContext(self, self._ctx, _parentState) _prevctx = localctx - _startState = 20 - self.enterRecursionRule(localctx, 20, self.RULE_term, _p) + _startState = 8 + self.enterRecursionRule(localctx, 8, self.RULE_expr, _p) self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 177 + self.state = 143 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,11,self._ctx) + la_ = self._interp.adaptivePredict(self._input,7,self._ctx) if la_ == 1: - localctx = qutes_parser.UnaryOperatorContext(self, localctx) + localctx = qutes_parser.ParentesizeExpressionContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + + self.state = 115 + self.match(qutes_parser.ROUND_PARENTHESIS_OPEN) + self.state = 116 + self.expr(0) + self.state = 117 + self.match(qutes_parser.ROUND_PARENTHESIS_CLOSE) + pass + + elif la_ == 2: + localctx = qutes_parser.LiteralExpressionContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 119 + self.literal() + pass + + elif la_ == 3: + localctx = qutes_parser.QualifiedNameExpressionContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 120 + self.qualifiedName() + pass + + elif la_ == 4: + localctx = qutes_parser.FunctionCallExpressionContext(self, localctx) self._ctx = localctx _prevctx = localctx + self.state = 121 + self.functionName() + self.state = 122 + self.match(qutes_parser.ROUND_PARENTHESIS_OPEN) + self.state = 124 + self._errHandler.sync(self) + _la = self._input.LA(1) + if ((((_la - 64)) & ~0x3f) == 0 and ((1 << (_la - 64)) & 1023) != 0): + self.state = 123 + self.functionCallParams() + + + self.state = 126 + self.match(qutes_parser.ROUND_PARENTHESIS_CLOSE) + pass - self.state = 156 + elif la_ == 5: + localctx = qutes_parser.PrefixOperatorContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 128 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 117862400) != 0)): + if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 824633778176) != 0)): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 157 - self.term(4) + self.state = 129 + self.expr(11) pass - elif la_ == 2: + elif la_ == 6: localctx = qutes_parser.MultipleUnaryOperatorContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 158 + self.state = 130 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 7405568) != 0)): + if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 59244544) != 0)): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 159 + self.state = 131 self.termList() pass - elif la_ == 3: + elif la_ == 7: + localctx = qutes_parser.UnaryOperatorContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 132 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 942669824) != 0)): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 133 + self.expr(3) + pass + + elif la_ == 8: localctx = qutes_parser.MultipleUnaryPhaseOperatorContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 160 + self.state = 134 localctx.op = self.match(qutes_parser.MCP) - self.state = 161 + self.state = 135 self.termList() - self.state = 162 + self.state = 136 self.match(qutes_parser.BY) - self.state = 163 - self.expr() + self.state = 137 + self.expr(2) pass - elif la_ == 4: - localctx = qutes_parser.IdentityOperatorContext(self, localctx) + elif la_ == 9: + localctx = qutes_parser.GroverOperatorContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 175 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [53]: - self.state = 165 - self.boolean() - pass - elif token in [54, 56, 57]: - self.state = 166 - self.integer() - pass - elif token in [55]: - self.state = 167 - self.float_() - pass - elif token in [58]: - self.state = 168 - self.qubit() - pass - elif token in [59]: - self.state = 169 - self.quint() - pass - elif token in [60]: - self.state = 170 - self.qustring() - pass - elif token in [61]: - self.state = 171 - self.qualifiedName() - pass - elif token in [25]: - self.state = 172 - self.match(qutes_parser.MEASURE) - pass - elif token in [27]: - self.state = 173 - self.match(qutes_parser.BARRIER) - pass - elif token in [62]: - self.state = 174 - self.string() - pass - else: - raise NoViableAltException(self) - + self.state = 139 + self.termList() + self.state = 140 + localctx.op = self.match(qutes_parser.IN_STATEMENT) + self.state = 141 + self.qualifiedName() pass self._ctx.stop = self._input.LT(-1) - self.state = 187 + self.state = 167 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,13,self._ctx) + _alt = self._interp.adaptivePredict(self._input,9,self._ctx) while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: if _alt==1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - self.state = 185 + self.state = 165 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,12,self._ctx) + la_ = self._interp.adaptivePredict(self._input,8,self._ctx) if la_ == 1: - localctx = qutes_parser.BinaryPriorityOperatorContext(self, qutes_parser.TermContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_term) - self.state = 179 - if not self.precpred(self._ctx, 6): + localctx = qutes_parser.MultiplicativeOperatorContext(self, qutes_parser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 145 + if not self.precpred(self._ctx, 10): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 6)") - self.state = 180 + raise FailedPredicateException(self, "self.precpred(self._ctx, 10)") + self.state = 146 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==10 or _la==11): + if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 7168) != 0)): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 181 - self.term(7) + self.state = 147 + self.expr(11) pass elif la_ == 2: - localctx = qutes_parser.BinaryOperatorContext(self, qutes_parser.TermContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_term) - self.state = 182 + localctx = qutes_parser.SumOperatorContext(self, qutes_parser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 148 + if not self.precpred(self._ctx, 9): + from antlr4.error.Errors import FailedPredicateException + raise FailedPredicateException(self, "self.precpred(self._ctx, 9)") + self.state = 149 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not(_la==13 or _la==14): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 150 + self.expr(10) + pass + + elif la_ == 3: + localctx = qutes_parser.RelationalOperatorContext(self, qutes_parser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 151 + if not self.precpred(self._ctx, 8): + from antlr4.error.Errors import FailedPredicateException + raise FailedPredicateException(self, "self.precpred(self._ctx, 8)") + self.state = 152 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 128849018880) != 0)): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 153 + self.expr(9) + pass + + elif la_ == 4: + localctx = qutes_parser.EqualityOperatorContext(self, qutes_parser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 154 + if not self.precpred(self._ctx, 7): + from antlr4.error.Errors import FailedPredicateException + raise FailedPredicateException(self, "self.precpred(self._ctx, 7)") + self.state = 155 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not(_la==31 or _la==32): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 156 + self.expr(8) + pass + + elif la_ == 5: + localctx = qutes_parser.LogicAndOperatorContext(self, qutes_parser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 157 + if not self.precpred(self._ctx, 6): + from antlr4.error.Errors import FailedPredicateException + raise FailedPredicateException(self, "self.precpred(self._ctx, 6)") + self.state = 158 + localctx.op = self.match(qutes_parser.AND) + self.state = 159 + self.expr(7) + pass + + elif la_ == 6: + localctx = qutes_parser.LogicOrOperatorContext(self, qutes_parser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 160 if not self.precpred(self._ctx, 5): from antlr4.error.Errors import FailedPredicateException raise FailedPredicateException(self, "self.precpred(self._ctx, 5)") - self.state = 183 + self.state = 161 + localctx.op = self.match(qutes_parser.OR) + self.state = 162 + self.expr(6) + pass + + elif la_ == 7: + localctx = qutes_parser.PostfixOperatorContext(self, qutes_parser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 163 + if not self.precpred(self._ctx, 12): + from antlr4.error.Errors import FailedPredicateException + raise FailedPredicateException(self, "self.precpred(self._ctx, 12)") + self.state = 164 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==12 or _la==13): + if not(_la==38 or _la==39): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 184 - self.term(6) pass - - self.state = 189 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,13,self._ctx) + + self.state = 169 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,9,self._ctx) + + except RecognitionException as re: + localctx.exception = re + self._errHandler.reportError(self, re) + self._errHandler.recover(self, re) + finally: + self.unrollRecursionContexts(_parentctx) + return localctx + + + class FunctionCallParamsContext(ParserRuleContext): + __slots__ = 'parser' + + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + super().__init__(parent, invokingState) + self.parser = parser + + def literal(self): + return self.getTypedRuleContext(qutes_parser.LiteralContext,0) + + + def qualifiedName(self): + return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) + + + def COMMA(self): + return self.getToken(qutes_parser.COMMA, 0) + + def functionCallParams(self): + return self.getTypedRuleContext(qutes_parser.FunctionCallParamsContext,0) + + + def getRuleIndex(self): + return qutes_parser.RULE_functionCallParams + + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterFunctionCallParams" ): + listener.enterFunctionCallParams(self) + + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitFunctionCallParams" ): + listener.exitFunctionCallParams(self) + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitFunctionCallParams" ): + return visitor.visitFunctionCallParams(self) + else: + return visitor.visitChildren(self) + + + + + def functionCallParams(self): + + localctx = qutes_parser.FunctionCallParamsContext(self, self._ctx, self.state) + self.enterRule(localctx, 10, self.RULE_functionCallParams) + self._la = 0 # Token type + try: + self.enterOuterAlt(localctx, 1) + self.state = 172 + self._errHandler.sync(self) + token = self._input.LA(1) + if token in [64, 65, 66, 67, 68, 69, 70, 71, 73]: + self.state = 170 + self.literal() + pass + elif token in [72]: + self.state = 171 + self.qualifiedName() + pass + else: + raise NoViableAltException(self) + + self.state = 176 + self._errHandler.sync(self) + _la = self._input.LA(1) + if _la==63: + self.state = 174 + self.match(qutes_parser.COMMA) + self.state = 175 + self.functionCallParams() + + + except RecognitionException as re: + localctx.exception = re + self._errHandler.reportError(self, re) + self._errHandler.recover(self, re) + finally: + self.exitRule() + return localctx + + + class TermListContext(ParserRuleContext): + __slots__ = 'parser' + + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + super().__init__(parent, invokingState) + self.parser = parser + + def literal(self): + return self.getTypedRuleContext(qutes_parser.LiteralContext,0) + + + def qualifiedName(self): + return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) + + + def COMMA(self): + return self.getToken(qutes_parser.COMMA, 0) + + def termList(self): + return self.getTypedRuleContext(qutes_parser.TermListContext,0) + + + def getRuleIndex(self): + return qutes_parser.RULE_termList + + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterTermList" ): + listener.enterTermList(self) + + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitTermList" ): + listener.exitTermList(self) + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTermList" ): + return visitor.visitTermList(self) + else: + return visitor.visitChildren(self) + + + + + def termList(self): + + localctx = qutes_parser.TermListContext(self, self._ctx, self.state) + self.enterRule(localctx, 12, self.RULE_termList) + try: + self.enterOuterAlt(localctx, 1) + self.state = 180 + self._errHandler.sync(self) + token = self._input.LA(1) + if token in [64, 65, 66, 67, 68, 69, 70, 71, 73]: + self.state = 178 + self.literal() + pass + elif token in [72]: + self.state = 179 + self.qualifiedName() + pass + else: + raise NoViableAltException(self) + + self.state = 184 + self._errHandler.sync(self) + la_ = self._interp.adaptivePredict(self._input,13,self._ctx) + if la_ == 1: + self.state = 182 + self.match(qutes_parser.COMMA) + self.state = 183 + self.termList() + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) self._errHandler.recover(self, re) finally: - self.unrollRecursionContexts(_parentctx) + self.exitRule() return localctx - class TermListContext(ParserRuleContext): + class VariableTypeContext(ParserRuleContext): __slots__ = 'parser' def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser - def term(self): - return self.getTypedRuleContext(qutes_parser.TermContext,0) - + def type_(self): + return self.getTypedRuleContext(qutes_parser.TypeContext,0) - def COMMA(self): - return self.getToken(qutes_parser.COMMA, 0) - def termList(self): - return self.getTypedRuleContext(qutes_parser.TermListContext,0) + def qualifiedName(self): + return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) def getRuleIndex(self): - return qutes_parser.RULE_termList + return qutes_parser.RULE_variableType def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterTermList" ): - listener.enterTermList(self) + if hasattr( listener, "enterVariableType" ): + listener.enterVariableType(self) def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitTermList" ): - listener.exitTermList(self) + if hasattr( listener, "exitVariableType" ): + listener.exitVariableType(self) def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTermList" ): - return visitor.visitTermList(self) + if hasattr( visitor, "visitVariableType" ): + return visitor.visitVariableType(self) else: return visitor.visitChildren(self) - def termList(self): + def variableType(self): - localctx = qutes_parser.TermListContext(self, self._ctx, self.state) - self.enterRule(localctx, 22, self.RULE_termList) + localctx = qutes_parser.VariableTypeContext(self, self._ctx, self.state) + self.enterRule(localctx, 14, self.RULE_variableType) try: - self.enterOuterAlt(localctx, 1) - self.state = 190 - self.term(0) - self.state = 193 + self.state = 188 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,14,self._ctx) - if la_ == 1: - self.state = 191 - self.match(qutes_parser.COMMA) - self.state = 192 - self.termList() - + token = self._input.LA(1) + if token in [1, 2, 3, 4, 5, 6, 7, 8]: + self.enterOuterAlt(localctx, 1) + self.state = 186 + self.type_() + pass + elif token in [72]: + self.enterOuterAlt(localctx, 2) + self.state = 187 + self.qualifiedName() + pass + else: + raise NoViableAltException(self) except RecognitionException as re: localctx.exception = re @@ -1933,11 +2098,11 @@ def accept(self, visitor:ParseTreeVisitor): def type_(self): localctx = qutes_parser.TypeContext(self, self._ctx, self.state) - self.enterRule(localctx, 24, self.RULE_type) + self.enterRule(localctx, 16, self.RULE_type) self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 195 + self.state = 190 _la = self._input.LA(1) if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 510) != 0)): self._errHandler.recoverInline(self) @@ -1953,71 +2118,6 @@ def type_(self): return localctx - class VariableTypeContext(ParserRuleContext): - __slots__ = 'parser' - - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): - super().__init__(parent, invokingState) - self.parser = parser - - def type_(self): - return self.getTypedRuleContext(qutes_parser.TypeContext,0) - - - def qualifiedName(self): - return self.getTypedRuleContext(qutes_parser.QualifiedNameContext,0) - - - def getRuleIndex(self): - return qutes_parser.RULE_variableType - - def enterRule(self, listener:ParseTreeListener): - if hasattr( listener, "enterVariableType" ): - listener.enterVariableType(self) - - def exitRule(self, listener:ParseTreeListener): - if hasattr( listener, "exitVariableType" ): - listener.exitVariableType(self) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitVariableType" ): - return visitor.visitVariableType(self) - else: - return visitor.visitChildren(self) - - - - - def variableType(self): - - localctx = qutes_parser.VariableTypeContext(self, self._ctx, self.state) - self.enterRule(localctx, 26, self.RULE_variableType) - try: - self.state = 199 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [1, 2, 3, 4, 5, 6, 7, 8]: - self.enterOuterAlt(localctx, 1) - self.state = 197 - self.type_() - pass - elif token in [61]: - self.enterOuterAlt(localctx, 2) - self.state = 198 - self.qualifiedName() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class QualifiedNameContext(ParserRuleContext): __slots__ = 'parser' @@ -2037,6 +2137,14 @@ def DOT(self, i:int=None): else: return self.getToken(qutes_parser.DOT, i) + def variableName(self): + return self.getTypedRuleContext(qutes_parser.VariableNameContext,0) + + + def functionName(self): + return self.getTypedRuleContext(qutes_parser.FunctionNameContext,0) + + def getRuleIndex(self): return qutes_parser.RULE_qualifiedName @@ -2060,23 +2168,42 @@ def accept(self, visitor:ParseTreeVisitor): def qualifiedName(self): localctx = qutes_parser.QualifiedNameContext(self, self._ctx, self.state) - self.enterRule(localctx, 28, self.RULE_qualifiedName) + self.enterRule(localctx, 18, self.RULE_qualifiedName) try: - self.enterOuterAlt(localctx, 1) - self.state = 201 - self.match(qutes_parser.SYMBOL_LITERAL) - self.state = 206 + self.state = 202 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,16,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: - self.state = 202 - self.match(qutes_parser.DOT) - self.state = 203 - self.match(qutes_parser.SYMBOL_LITERAL) - self.state = 208 + la_ = self._interp.adaptivePredict(self._input,16,self._ctx) + if la_ == 1: + self.enterOuterAlt(localctx, 1) + self.state = 192 + self.match(qutes_parser.SYMBOL_LITERAL) + self.state = 197 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,16,self._ctx) + _alt = self._interp.adaptivePredict(self._input,15,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: + self.state = 193 + self.match(qutes_parser.DOT) + self.state = 194 + self.match(qutes_parser.SYMBOL_LITERAL) + self.state = 199 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,15,self._ctx) + + pass + + elif la_ == 2: + self.enterOuterAlt(localctx, 2) + self.state = 200 + self.variableName() + pass + + elif la_ == 3: + self.enterOuterAlt(localctx, 3) + self.state = 201 + self.functionName() + pass + except RecognitionException as re: localctx.exception = re @@ -2120,10 +2247,10 @@ def accept(self, visitor:ParseTreeVisitor): def variableName(self): localctx = qutes_parser.VariableNameContext(self, self._ctx, self.state) - self.enterRule(localctx, 30, self.RULE_variableName) + self.enterRule(localctx, 20, self.RULE_variableName) try: self.enterOuterAlt(localctx, 1) - self.state = 209 + self.state = 204 self.match(qutes_parser.SYMBOL_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2167,10 +2294,10 @@ def accept(self, visitor:ParseTreeVisitor): def functionName(self): localctx = qutes_parser.FunctionNameContext(self, self._ctx, self.state) - self.enterRule(localctx, 32, self.RULE_functionName) + self.enterRule(localctx, 22, self.RULE_functionName) try: self.enterOuterAlt(localctx, 1) - self.state = 211 + self.state = 206 self.match(qutes_parser.SYMBOL_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2181,6 +2308,116 @@ def functionName(self): return localctx + class LiteralContext(ParserRuleContext): + __slots__ = 'parser' + + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + super().__init__(parent, invokingState) + self.parser = parser + + def boolean(self): + return self.getTypedRuleContext(qutes_parser.BooleanContext,0) + + + def integer(self): + return self.getTypedRuleContext(qutes_parser.IntegerContext,0) + + + def float_(self): + return self.getTypedRuleContext(qutes_parser.FloatContext,0) + + + def qubit(self): + return self.getTypedRuleContext(qutes_parser.QubitContext,0) + + + def quint(self): + return self.getTypedRuleContext(qutes_parser.QuintContext,0) + + + def qustring(self): + return self.getTypedRuleContext(qutes_parser.QustringContext,0) + + + def string(self): + return self.getTypedRuleContext(qutes_parser.StringContext,0) + + + def getRuleIndex(self): + return qutes_parser.RULE_literal + + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterLiteral" ): + listener.enterLiteral(self) + + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitLiteral" ): + listener.exitLiteral(self) + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitLiteral" ): + return visitor.visitLiteral(self) + else: + return visitor.visitChildren(self) + + + + + def literal(self): + + localctx = qutes_parser.LiteralContext(self, self._ctx, self.state) + self.enterRule(localctx, 24, self.RULE_literal) + try: + self.state = 215 + self._errHandler.sync(self) + token = self._input.LA(1) + if token in [64]: + self.enterOuterAlt(localctx, 1) + self.state = 208 + self.boolean() + pass + elif token in [65, 67, 68]: + self.enterOuterAlt(localctx, 2) + self.state = 209 + self.integer() + pass + elif token in [66]: + self.enterOuterAlt(localctx, 3) + self.state = 210 + self.float_() + pass + elif token in [69]: + self.enterOuterAlt(localctx, 4) + self.state = 211 + self.qubit() + pass + elif token in [70]: + self.enterOuterAlt(localctx, 5) + self.state = 212 + self.quint() + pass + elif token in [71]: + self.enterOuterAlt(localctx, 6) + self.state = 213 + self.qustring() + pass + elif token in [73]: + self.enterOuterAlt(localctx, 7) + self.state = 214 + self.string() + pass + else: + raise NoViableAltException(self) + + except RecognitionException as re: + localctx.exception = re + self._errHandler.reportError(self, re) + self._errHandler.recover(self, re) + finally: + self.exitRule() + return localctx + + class StringContext(ParserRuleContext): __slots__ = 'parser' @@ -2214,10 +2451,10 @@ def accept(self, visitor:ParseTreeVisitor): def string(self): localctx = qutes_parser.StringContext(self, self._ctx, self.state) - self.enterRule(localctx, 34, self.RULE_string) + self.enterRule(localctx, 26, self.RULE_string) try: self.enterOuterAlt(localctx, 1) - self.state = 213 + self.state = 217 self.match(qutes_parser.STRING_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2261,10 +2498,10 @@ def accept(self, visitor:ParseTreeVisitor): def qubit(self): localctx = qutes_parser.QubitContext(self, self._ctx, self.state) - self.enterRule(localctx, 36, self.RULE_qubit) + self.enterRule(localctx, 28, self.RULE_qubit) try: self.enterOuterAlt(localctx, 1) - self.state = 215 + self.state = 219 self.match(qutes_parser.QUBIT_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2308,10 +2545,10 @@ def accept(self, visitor:ParseTreeVisitor): def quint(self): localctx = qutes_parser.QuintContext(self, self._ctx, self.state) - self.enterRule(localctx, 38, self.RULE_quint) + self.enterRule(localctx, 30, self.RULE_quint) try: self.enterOuterAlt(localctx, 1) - self.state = 217 + self.state = 221 self.match(qutes_parser.QUINT_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2355,10 +2592,10 @@ def accept(self, visitor:ParseTreeVisitor): def qustring(self): localctx = qutes_parser.QustringContext(self, self._ctx, self.state) - self.enterRule(localctx, 40, self.RULE_qustring) + self.enterRule(localctx, 32, self.RULE_qustring) try: self.enterOuterAlt(localctx, 1) - self.state = 219 + self.state = 223 self.match(qutes_parser.QUSTRING_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2402,10 +2639,10 @@ def accept(self, visitor:ParseTreeVisitor): def float_(self): localctx = qutes_parser.FloatContext(self, self._ctx, self.state) - self.enterRule(localctx, 42, self.RULE_float) + self.enterRule(localctx, 34, self.RULE_float) try: self.enterOuterAlt(localctx, 1) - self.state = 221 + self.state = 225 self.match(qutes_parser.FLOAT_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2455,13 +2692,13 @@ def accept(self, visitor:ParseTreeVisitor): def integer(self): localctx = qutes_parser.IntegerContext(self, self._ctx, self.state) - self.enterRule(localctx, 44, self.RULE_integer) + self.enterRule(localctx, 36, self.RULE_integer) self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 223 + self.state = 227 _la = self._input.LA(1) - if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 234187180623265792) != 0)): + if not(((((_la - 65)) & ~0x3f) == 0 and ((1 << (_la - 65)) & 13) != 0)): self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -2508,10 +2745,10 @@ def accept(self, visitor:ParseTreeVisitor): def boolean(self): localctx = qutes_parser.BooleanContext(self, self._ctx, self.state) - self.enterRule(localctx, 46, self.RULE_boolean) + self.enterRule(localctx, 38, self.RULE_boolean) try: self.enterOuterAlt(localctx, 1) - self.state = 225 + self.state = 229 self.match(qutes_parser.BOOL_LITERAL) except RecognitionException as re: localctx.exception = re @@ -2526,22 +2763,42 @@ def boolean(self): def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): if self._predicates == None: self._predicates = dict() - self._predicates[10] = self.term_sempred + self._predicates[4] = self.expr_sempred pred = self._predicates.get(ruleIndex, None) if pred is None: raise Exception("No predicate with index:" + str(ruleIndex)) else: return pred(localctx, predIndex) - def term_sempred(self, localctx:TermContext, predIndex:int): + def expr_sempred(self, localctx:ExprContext, predIndex:int): if predIndex == 0: - return self.precpred(self._ctx, 6) + return self.precpred(self._ctx, 10) if predIndex == 1: + return self.precpred(self._ctx, 9) + + + if predIndex == 2: + return self.precpred(self._ctx, 8) + + + if predIndex == 3: + return self.precpred(self._ctx, 7) + + + if predIndex == 4: + return self.precpred(self._ctx, 6) + + + if predIndex == 5: return self.precpred(self._ctx, 5) + if predIndex == 6: + return self.precpred(self._ctx, 12) + + diff --git a/src/qutes_antlr/qutes_parser.tokens b/src/qutes_antlr/qutes_parser.tokens index 41c14b1..2d74c03 100644 --- a/src/qutes_antlr/qutes_parser.tokens +++ b/src/qutes_antlr/qutes_parser.tokens @@ -9,59 +9,70 @@ VOID_TYPE=8 RETURN=9 MULTIPLY=10 DIVIDE=11 -ADD=12 -SUB=13 -NOT=14 -BY=15 -SWAP=16 -PAULIY=17 -PAULIZ=18 -GROVER=19 -MCZ=20 -MCX=21 -MCY=22 -MCP=23 -HADAMARD=24 -MEASURE=25 -PRINT=26 -BARRIER=27 -EQUAL=28 -GREATER=29 -GREATEREQUAL=30 -LOWER=31 -LOWEREQUAL=32 -ASSIGN=33 -END_OF_STATEMENT=34 -VAR_STATEMENT=35 -FOR_STATEMENT=36 -SEARCH_STATEMENT=37 -IN_STATEMENT=38 -WHERE_STATEMENT=39 -IF_STATEMENT=40 -ELSE_STATEMENT=41 -WHILE_STATEMENT=42 -DO_STATEMENT=43 -CURLY_PARENTHESIS_OPEN=44 -CURLY_PARENTHESIS_CLOSE=45 -ROUND_PARENTHESIS_OPEN=46 -ROUND_PARENTHESIS_CLOSE=47 -SQUARE_PARENTHESIS_OPEN=48 -SQUARE_PARENTHESIS_CLOSE=49 -DOT=50 -STRING_ENCLOSURE=51 -COMMA=52 -BOOL_LITERAL=53 -INT_LITERAL=54 -FLOAT_LITERAL=55 -HEX_LITERAL=56 -BIN_LITERAL=57 -QUBIT_LITERAL=58 -QUINT_LITERAL=59 -QUSTRING_LITERAL=60 -SYMBOL_LITERAL=61 -STRING_LITERAL=62 -WS=63 -NEWLINE=64 +MODULE=12 +ADD=13 +SUB=14 +NOT=15 +AND=16 +OR=17 +BY=18 +SWAP=19 +PAULIY=20 +PAULIZ=21 +GROVER=22 +MCZ=23 +MCX=24 +MCY=25 +MCP=26 +HADAMARD=27 +MEASURE=28 +PRINT=29 +BARRIER=30 +EQUAL=31 +NOT_EQUAL=32 +GREATER=33 +GREATEREQUAL=34 +LOWER=35 +LOWEREQUAL=36 +ASSIGN=37 +AUTO_INCREMENT=38 +AUTO_DECREMENT=39 +AUTO_SUM=40 +AUTO_SUB=41 +AUTO_MULTIPLY=42 +AUTO_DIVIDE=43 +AUTO_MODULE=44 +END_OF_STATEMENT=45 +VAR_STATEMENT=46 +FOR_STATEMENT=47 +SEARCH_STATEMENT=48 +IN_STATEMENT=49 +WHERE_STATEMENT=50 +IF_STATEMENT=51 +ELSE_STATEMENT=52 +WHILE_STATEMENT=53 +DO_STATEMENT=54 +CURLY_PARENTHESIS_OPEN=55 +CURLY_PARENTHESIS_CLOSE=56 +ROUND_PARENTHESIS_OPEN=57 +ROUND_PARENTHESIS_CLOSE=58 +SQUARE_PARENTHESIS_OPEN=59 +SQUARE_PARENTHESIS_CLOSE=60 +DOT=61 +STRING_ENCLOSURE=62 +COMMA=63 +BOOL_LITERAL=64 +INT_LITERAL=65 +FLOAT_LITERAL=66 +HEX_LITERAL=67 +BIN_LITERAL=68 +QUBIT_LITERAL=69 +QUINT_LITERAL=70 +QUSTRING_LITERAL=71 +SYMBOL_LITERAL=72 +STRING_LITERAL=73 +WS=74 +NEWLINE=75 'int'=1 'bool'=2 'string'=3 @@ -73,44 +84,55 @@ NEWLINE=64 'return'=9 '*'=10 '/'=11 -'+'=12 -'-'=13 -'not'=14 -'by'=15 -'swap'=16 -'pauliy'=17 -'pauliz'=18 -'grover'=19 -'mcz'=20 -'mcx'=21 -'mcy'=22 -'mcp'=23 -'hadamard'=24 -'measure'=25 -'print'=26 -'barrier'=27 -'=='=28 -'>'=29 -'>='=30 -'<'=31 -'<='=32 -'='=33 -';'=34 -'var'=35 -'for'=36 -'search'=37 -'in'=38 -'where'=39 -'if'=40 -'else'=41 -'while'=42 -'do'=43 -'{'=44 -'}'=45 -'('=46 -')'=47 -'['=48 -']'=49 -'.'=50 -'"'=51 -','=52 +'%'=12 +'+'=13 +'-'=14 +'not'=15 +'and'=16 +'or'=17 +'by'=18 +'swap'=19 +'pauliy'=20 +'pauliz'=21 +'grover'=22 +'mcz'=23 +'mcx'=24 +'mcy'=25 +'mcp'=26 +'hadamard'=27 +'measure'=28 +'print'=29 +'barrier'=30 +'=='=31 +'!='=32 +'>'=33 +'>='=34 +'<'=35 +'<='=36 +'='=37 +'++'=38 +'--'=39 +'+='=40 +'-='=41 +'*='=42 +'/='=43 +'%='=44 +';'=45 +'var'=46 +'for'=47 +'search'=48 +'in'=49 +'where'=50 +'if'=51 +'else'=52 +'while'=53 +'do'=54 +'{'=55 +'}'=56 +'('=57 +')'=58 +'['=59 +']'=60 +'.'=61 +'"'=62 +','=63 diff --git a/src/qutes_antlr/qutes_parserListener.py b/src/qutes_antlr/qutes_parserListener.py index 45b7353..903f88a 100644 --- a/src/qutes_antlr/qutes_parserListener.py +++ b/src/qutes_antlr/qutes_parserListener.py @@ -107,6 +107,15 @@ def exitExpressionStatement(self, ctx:qutes_parser.ExpressionStatementContext): pass + # Enter a parse tree produced by qutes_parser#FactStatement. + def enterFactStatement(self, ctx:qutes_parser.FactStatementContext): + pass + + # Exit a parse tree produced by qutes_parser#FactStatement. + def exitFactStatement(self, ctx:qutes_parser.FactStatementContext): + pass + + # Enter a parse tree produced by qutes_parser#EmptyStatement. def enterEmptyStatement(self, ctx:qutes_parser.EmptyStatementContext): pass @@ -134,57 +143,75 @@ def exitVariableDeclaration(self, ctx:qutes_parser.VariableDeclarationContext): pass - # Enter a parse tree produced by qutes_parser#functionCallParams. - def enterFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): + # Enter a parse tree produced by qutes_parser#QualifiedNameExpression. + def enterQualifiedNameExpression(self, ctx:qutes_parser.QualifiedNameExpressionContext): pass - # Exit a parse tree produced by qutes_parser#functionCallParams. - def exitFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): + # Exit a parse tree produced by qutes_parser#QualifiedNameExpression. + def exitQualifiedNameExpression(self, ctx:qutes_parser.QualifiedNameExpressionContext): + pass + + + # Enter a parse tree produced by qutes_parser#RelationalOperator. + def enterRelationalOperator(self, ctx:qutes_parser.RelationalOperatorContext): + pass + + # Exit a parse tree produced by qutes_parser#RelationalOperator. + def exitRelationalOperator(self, ctx:qutes_parser.RelationalOperatorContext): + pass + + + # Enter a parse tree produced by qutes_parser#LogicAndOperator. + def enterLogicAndOperator(self, ctx:qutes_parser.LogicAndOperatorContext): + pass + + # Exit a parse tree produced by qutes_parser#LogicAndOperator. + def exitLogicAndOperator(self, ctx:qutes_parser.LogicAndOperatorContext): pass - # Enter a parse tree produced by qutes_parser#expr. - def enterExpr(self, ctx:qutes_parser.ExprContext): + # Enter a parse tree produced by qutes_parser#PrefixOperator. + def enterPrefixOperator(self, ctx:qutes_parser.PrefixOperatorContext): pass - # Exit a parse tree produced by qutes_parser#expr. - def exitExpr(self, ctx:qutes_parser.ExprContext): + # Exit a parse tree produced by qutes_parser#PrefixOperator. + def exitPrefixOperator(self, ctx:qutes_parser.PrefixOperatorContext): pass - # Enter a parse tree produced by qutes_parser#groverExpr. - def enterGroverExpr(self, ctx:qutes_parser.GroverExprContext): + # Enter a parse tree produced by qutes_parser#LiteralExpression. + def enterLiteralExpression(self, ctx:qutes_parser.LiteralExpressionContext): pass - # Exit a parse tree produced by qutes_parser#groverExpr. - def exitGroverExpr(self, ctx:qutes_parser.GroverExprContext): + # Exit a parse tree produced by qutes_parser#LiteralExpression. + def exitLiteralExpression(self, ctx:qutes_parser.LiteralExpressionContext): pass - # Enter a parse tree produced by qutes_parser#functionCall. - def enterFunctionCall(self, ctx:qutes_parser.FunctionCallContext): + # Enter a parse tree produced by qutes_parser#GroverOperator. + def enterGroverOperator(self, ctx:qutes_parser.GroverOperatorContext): pass - # Exit a parse tree produced by qutes_parser#functionCall. - def exitFunctionCall(self, ctx:qutes_parser.FunctionCallContext): + # Exit a parse tree produced by qutes_parser#GroverOperator. + def exitGroverOperator(self, ctx:qutes_parser.GroverOperatorContext): pass - # Enter a parse tree produced by qutes_parser#parenExpr. - def enterParenExpr(self, ctx:qutes_parser.ParenExprContext): + # Enter a parse tree produced by qutes_parser#FunctionCallExpression. + def enterFunctionCallExpression(self, ctx:qutes_parser.FunctionCallExpressionContext): pass - # Exit a parse tree produced by qutes_parser#parenExpr. - def exitParenExpr(self, ctx:qutes_parser.ParenExprContext): + # Exit a parse tree produced by qutes_parser#FunctionCallExpression. + def exitFunctionCallExpression(self, ctx:qutes_parser.FunctionCallExpressionContext): pass - # Enter a parse tree produced by qutes_parser#test. - def enterTest(self, ctx:qutes_parser.TestContext): + # Enter a parse tree produced by qutes_parser#EqualityOperator. + def enterEqualityOperator(self, ctx:qutes_parser.EqualityOperatorContext): pass - # Exit a parse tree produced by qutes_parser#test. - def exitTest(self, ctx:qutes_parser.TestContext): + # Exit a parse tree produced by qutes_parser#EqualityOperator. + def exitEqualityOperator(self, ctx:qutes_parser.EqualityOperatorContext): pass @@ -197,21 +224,30 @@ def exitMultipleUnaryOperator(self, ctx:qutes_parser.MultipleUnaryOperatorContex pass - # Enter a parse tree produced by qutes_parser#BinaryPriorityOperator. - def enterBinaryPriorityOperator(self, ctx:qutes_parser.BinaryPriorityOperatorContext): + # Enter a parse tree produced by qutes_parser#SumOperator. + def enterSumOperator(self, ctx:qutes_parser.SumOperatorContext): pass - # Exit a parse tree produced by qutes_parser#BinaryPriorityOperator. - def exitBinaryPriorityOperator(self, ctx:qutes_parser.BinaryPriorityOperatorContext): + # Exit a parse tree produced by qutes_parser#SumOperator. + def exitSumOperator(self, ctx:qutes_parser.SumOperatorContext): pass - # Enter a parse tree produced by qutes_parser#IdentityOperator. - def enterIdentityOperator(self, ctx:qutes_parser.IdentityOperatorContext): + # Enter a parse tree produced by qutes_parser#PostfixOperator. + def enterPostfixOperator(self, ctx:qutes_parser.PostfixOperatorContext): pass - # Exit a parse tree produced by qutes_parser#IdentityOperator. - def exitIdentityOperator(self, ctx:qutes_parser.IdentityOperatorContext): + # Exit a parse tree produced by qutes_parser#PostfixOperator. + def exitPostfixOperator(self, ctx:qutes_parser.PostfixOperatorContext): + pass + + + # Enter a parse tree produced by qutes_parser#ParentesizeExpression. + def enterParentesizeExpression(self, ctx:qutes_parser.ParentesizeExpressionContext): + pass + + # Exit a parse tree produced by qutes_parser#ParentesizeExpression. + def exitParentesizeExpression(self, ctx:qutes_parser.ParentesizeExpressionContext): pass @@ -224,6 +260,15 @@ def exitMultipleUnaryPhaseOperator(self, ctx:qutes_parser.MultipleUnaryPhaseOper pass + # Enter a parse tree produced by qutes_parser#MultiplicativeOperator. + def enterMultiplicativeOperator(self, ctx:qutes_parser.MultiplicativeOperatorContext): + pass + + # Exit a parse tree produced by qutes_parser#MultiplicativeOperator. + def exitMultiplicativeOperator(self, ctx:qutes_parser.MultiplicativeOperatorContext): + pass + + # Enter a parse tree produced by qutes_parser#UnaryOperator. def enterUnaryOperator(self, ctx:qutes_parser.UnaryOperatorContext): pass @@ -233,30 +278,30 @@ def exitUnaryOperator(self, ctx:qutes_parser.UnaryOperatorContext): pass - # Enter a parse tree produced by qutes_parser#BinaryOperator. - def enterBinaryOperator(self, ctx:qutes_parser.BinaryOperatorContext): + # Enter a parse tree produced by qutes_parser#LogicOrOperator. + def enterLogicOrOperator(self, ctx:qutes_parser.LogicOrOperatorContext): pass - # Exit a parse tree produced by qutes_parser#BinaryOperator. - def exitBinaryOperator(self, ctx:qutes_parser.BinaryOperatorContext): + # Exit a parse tree produced by qutes_parser#LogicOrOperator. + def exitLogicOrOperator(self, ctx:qutes_parser.LogicOrOperatorContext): pass - # Enter a parse tree produced by qutes_parser#termList. - def enterTermList(self, ctx:qutes_parser.TermListContext): + # Enter a parse tree produced by qutes_parser#functionCallParams. + def enterFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): pass - # Exit a parse tree produced by qutes_parser#termList. - def exitTermList(self, ctx:qutes_parser.TermListContext): + # Exit a parse tree produced by qutes_parser#functionCallParams. + def exitFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): pass - # Enter a parse tree produced by qutes_parser#type. - def enterType(self, ctx:qutes_parser.TypeContext): + # Enter a parse tree produced by qutes_parser#termList. + def enterTermList(self, ctx:qutes_parser.TermListContext): pass - # Exit a parse tree produced by qutes_parser#type. - def exitType(self, ctx:qutes_parser.TypeContext): + # Exit a parse tree produced by qutes_parser#termList. + def exitTermList(self, ctx:qutes_parser.TermListContext): pass @@ -269,6 +314,15 @@ def exitVariableType(self, ctx:qutes_parser.VariableTypeContext): pass + # Enter a parse tree produced by qutes_parser#type. + def enterType(self, ctx:qutes_parser.TypeContext): + pass + + # Exit a parse tree produced by qutes_parser#type. + def exitType(self, ctx:qutes_parser.TypeContext): + pass + + # Enter a parse tree produced by qutes_parser#qualifiedName. def enterQualifiedName(self, ctx:qutes_parser.QualifiedNameContext): pass @@ -296,6 +350,15 @@ def exitFunctionName(self, ctx:qutes_parser.FunctionNameContext): pass + # Enter a parse tree produced by qutes_parser#literal. + def enterLiteral(self, ctx:qutes_parser.LiteralContext): + pass + + # Exit a parse tree produced by qutes_parser#literal. + def exitLiteral(self, ctx:qutes_parser.LiteralContext): + pass + + # Enter a parse tree produced by qutes_parser#string. def enterString(self, ctx:qutes_parser.StringContext): pass diff --git a/src/qutes_antlr/qutes_parserVisitor.py b/src/qutes_antlr/qutes_parserVisitor.py index 2554a02..afe65a0 100644 --- a/src/qutes_antlr/qutes_parserVisitor.py +++ b/src/qutes_antlr/qutes_parserVisitor.py @@ -64,6 +64,11 @@ def visitExpressionStatement(self, ctx:qutes_parser.ExpressionStatementContext): return self.visitChildren(ctx) + # Visit a parse tree produced by qutes_parser#FactStatement. + def visitFactStatement(self, ctx:qutes_parser.FactStatementContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by qutes_parser#EmptyStatement. def visitEmptyStatement(self, ctx:qutes_parser.EmptyStatementContext): return self.visitChildren(ctx) @@ -79,33 +84,43 @@ def visitVariableDeclaration(self, ctx:qutes_parser.VariableDeclarationContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#functionCallParams. - def visitFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): + # Visit a parse tree produced by qutes_parser#QualifiedNameExpression. + def visitQualifiedNameExpression(self, ctx:qutes_parser.QualifiedNameExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#expr. - def visitExpr(self, ctx:qutes_parser.ExprContext): + # Visit a parse tree produced by qutes_parser#RelationalOperator. + def visitRelationalOperator(self, ctx:qutes_parser.RelationalOperatorContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#groverExpr. - def visitGroverExpr(self, ctx:qutes_parser.GroverExprContext): + # Visit a parse tree produced by qutes_parser#LogicAndOperator. + def visitLogicAndOperator(self, ctx:qutes_parser.LogicAndOperatorContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#functionCall. - def visitFunctionCall(self, ctx:qutes_parser.FunctionCallContext): + # Visit a parse tree produced by qutes_parser#PrefixOperator. + def visitPrefixOperator(self, ctx:qutes_parser.PrefixOperatorContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#parenExpr. - def visitParenExpr(self, ctx:qutes_parser.ParenExprContext): + # Visit a parse tree produced by qutes_parser#LiteralExpression. + def visitLiteralExpression(self, ctx:qutes_parser.LiteralExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#test. - def visitTest(self, ctx:qutes_parser.TestContext): + # Visit a parse tree produced by qutes_parser#GroverOperator. + def visitGroverOperator(self, ctx:qutes_parser.GroverOperatorContext): + return self.visitChildren(ctx) + + + # Visit a parse tree produced by qutes_parser#FunctionCallExpression. + def visitFunctionCallExpression(self, ctx:qutes_parser.FunctionCallExpressionContext): + return self.visitChildren(ctx) + + + # Visit a parse tree produced by qutes_parser#EqualityOperator. + def visitEqualityOperator(self, ctx:qutes_parser.EqualityOperatorContext): return self.visitChildren(ctx) @@ -114,13 +129,18 @@ def visitMultipleUnaryOperator(self, ctx:qutes_parser.MultipleUnaryOperatorConte return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#BinaryPriorityOperator. - def visitBinaryPriorityOperator(self, ctx:qutes_parser.BinaryPriorityOperatorContext): + # Visit a parse tree produced by qutes_parser#SumOperator. + def visitSumOperator(self, ctx:qutes_parser.SumOperatorContext): + return self.visitChildren(ctx) + + + # Visit a parse tree produced by qutes_parser#PostfixOperator. + def visitPostfixOperator(self, ctx:qutes_parser.PostfixOperatorContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#IdentityOperator. - def visitIdentityOperator(self, ctx:qutes_parser.IdentityOperatorContext): + # Visit a parse tree produced by qutes_parser#ParentesizeExpression. + def visitParentesizeExpression(self, ctx:qutes_parser.ParentesizeExpressionContext): return self.visitChildren(ctx) @@ -129,23 +149,28 @@ def visitMultipleUnaryPhaseOperator(self, ctx:qutes_parser.MultipleUnaryPhaseOpe return self.visitChildren(ctx) + # Visit a parse tree produced by qutes_parser#MultiplicativeOperator. + def visitMultiplicativeOperator(self, ctx:qutes_parser.MultiplicativeOperatorContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by qutes_parser#UnaryOperator. def visitUnaryOperator(self, ctx:qutes_parser.UnaryOperatorContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#BinaryOperator. - def visitBinaryOperator(self, ctx:qutes_parser.BinaryOperatorContext): + # Visit a parse tree produced by qutes_parser#LogicOrOperator. + def visitLogicOrOperator(self, ctx:qutes_parser.LogicOrOperatorContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#termList. - def visitTermList(self, ctx:qutes_parser.TermListContext): + # Visit a parse tree produced by qutes_parser#functionCallParams. + def visitFunctionCallParams(self, ctx:qutes_parser.FunctionCallParamsContext): return self.visitChildren(ctx) - # Visit a parse tree produced by qutes_parser#type. - def visitType(self, ctx:qutes_parser.TypeContext): + # Visit a parse tree produced by qutes_parser#termList. + def visitTermList(self, ctx:qutes_parser.TermListContext): return self.visitChildren(ctx) @@ -154,6 +179,11 @@ def visitVariableType(self, ctx:qutes_parser.VariableTypeContext): return self.visitChildren(ctx) + # Visit a parse tree produced by qutes_parser#type. + def visitType(self, ctx:qutes_parser.TypeContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by qutes_parser#qualifiedName. def visitQualifiedName(self, ctx:qutes_parser.QualifiedNameContext): return self.visitChildren(ctx) @@ -169,6 +199,11 @@ def visitFunctionName(self, ctx:qutes_parser.FunctionNameContext): return self.visitChildren(ctx) + # Visit a parse tree produced by qutes_parser#literal. + def visitLiteral(self, ctx:qutes_parser.LiteralContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by qutes_parser#string. def visitString(self, ctx:qutes_parser.StringContext): return self.visitChildren(ctx) diff --git a/src/tests/test_grammar.py b/src/tests/test_grammar.py index 9169b47..fb6f183 100644 --- a/src/tests/test_grammar.py +++ b/src/tests/test_grammar.py @@ -55,9 +55,7 @@ def test_var_declaration_with_unexpected_char_throws(self): ("1221asasa___"), ("1221as___asa___"), ("1221asassa_Asas"), - ("ass=asas"), ("ass-asas"), - ("ass=-asas"), ("ass(asas"), ("ass*asas"), ("ass&asas"),