# Generated from Quil.g4 by ANTLR 4.7.1
# encoding: utf-8
from antlr4 import *
from io import StringIO
from typing.io import TextIO
import sys

def serializedATN():
    with StringIO() as buf:
        buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3H")
        buf.write("\u01cd\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7")
        buf.write("\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16")
        buf.write("\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22\4\23\t\23")
        buf.write("\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31")
        buf.write("\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36")
        buf.write("\4\37\t\37\4 \t \4!\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t")
        buf.write("&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t+\4,\t,\4-\t-\4.\t.\4")
        buf.write("/\t/\4\60\t\60\4\61\t\61\4\62\t\62\3\2\5\2f\n\2\3\2\6")
        buf.write("\2i\n\2\r\2\16\2j\3\2\7\2n\n\2\f\2\16\2q\13\2\3\2\7\2")
        buf.write("t\n\2\f\2\16\2w\13\2\3\2\3\2\3\3\3\3\3\3\5\3~\n\3\3\4")
        buf.write("\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3")
        buf.write("\4\3\4\3\4\3\4\5\4\u0092\n\4\3\5\3\5\3\5\3\5\3\5\7\5\u0099")
        buf.write("\n\5\f\5\16\5\u009c\13\5\3\5\3\5\5\5\u00a0\n\5\3\5\6\5")
        buf.write("\u00a3\n\5\r\5\16\5\u00a4\3\6\3\6\3\7\3\7\3\b\3\b\3\t")
        buf.write("\3\t\3\t\3\t\3\t\3\t\7\t\u00b3\n\t\f\t\16\t\u00b6\13\t")
        buf.write("\3\t\3\t\5\t\u00ba\n\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\13")
        buf.write("\3\13\3\13\7\13\u00c6\n\13\f\13\16\13\u00c9\13\13\3\13")
        buf.write("\3\13\3\f\3\f\3\f\3\f\7\f\u00d1\n\f\f\f\16\f\u00d4\13")
        buf.write("\f\3\r\3\r\3\r\3\r\3\r\3\r\7\r\u00dc\n\r\f\r\16\r\u00df")
        buf.write("\13\r\3\r\3\r\5\r\u00e3\n\r\3\r\7\r\u00e6\n\r\f\r\16\r")
        buf.write("\u00e9\13\r\3\r\3\r\3\r\3\r\3\16\3\16\3\17\3\17\5\17\u00f3")
        buf.write("\n\17\3\20\3\20\3\20\3\20\3\20\7\20\u00fa\n\20\f\20\16")
        buf.write("\20\u00fd\13\20\3\20\3\20\5\20\u0101\n\20\3\20\6\20\u0104")
        buf.write("\n\20\r\20\16\20\u0105\3\21\3\21\5\21\u010a\n\21\3\22")
        buf.write("\3\22\3\22\3\22\7\22\u0110\n\22\f\22\16\22\u0113\13\22")
        buf.write("\3\22\3\22\3\22\3\23\3\23\3\23\5\23\u011b\n\23\3\24\3")
        buf.write("\24\5\24\u011f\n\24\3\24\3\24\3\24\5\24\u0124\n\24\3\25")
        buf.write("\3\25\3\25\3\26\3\26\3\26\3\27\3\27\3\30\3\30\3\30\3\31")
        buf.write("\3\31\3\31\3\31\3\32\3\32\3\32\3\32\3\33\3\33\5\33\u013b")
        buf.write("\n\33\3\34\3\34\3\35\3\35\3\35\3\35\3\35\3\35\5\35\u0145")
        buf.write("\n\35\3\35\3\35\3\35\7\35\u014a\n\35\f\35\16\35\u014d")
        buf.write("\13\35\5\35\u014f\n\35\3\36\3\36\3\36\3\36\3\37\3\37\3")
        buf.write("\37\3 \3 \3 \3 \3 \5 \u015d\n \3!\3!\3!\3!\5!\u0163\n")
        buf.write("!\3\"\3\"\3\"\3\"\5\"\u0169\n\"\3#\3#\3#\3#\5#\u016f\n")
        buf.write("#\3$\3$\3$\3$\3%\3%\3%\3%\3&\3&\3&\3&\3&\3\'\3\'\3\'\3")
        buf.write("\'\3\'\5\'\u0183\n\'\3(\3(\3(\3(\3(\5(\u018a\n(\3)\3)")
        buf.write("\3*\3*\3*\3+\3+\3+\7+\u0194\n+\f+\16+\u0197\13+\3+\5+")
        buf.write("\u019a\n+\3,\3,\3-\3-\3-\3-\3-\3-\3-\3-\3-\3-\3-\3-\3")
        buf.write("-\3-\3-\3-\5-\u01ae\n-\3-\3-\3-\3-\3-\3-\3-\3-\3-\7-\u01b9")
        buf.write("\n-\f-\16-\u01bc\13-\3.\3.\3/\3/\3\60\3\60\3\60\3\60\5")
        buf.write("\60\u01c6\n\60\3\61\3\61\3\61\3\62\3\62\3\62\2\3X\63\2")
        buf.write("\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62\64")
        buf.write("\668:<>@BDFHJLNPRTVXZ\\^`b\2\13\3\2\23\26\3\2\27\32\3")
        buf.write("\2\33\36\3\2\"&\3\2\65\66\3\2\62\63\3\2\60\61\3\2+/\3")
        buf.write("\2\66\67\2\u01df\2e\3\2\2\2\4}\3\2\2\2\6\u0091\3\2\2\2")
        buf.write("\b\u0093\3\2\2\2\n\u00a6\3\2\2\2\f\u00a8\3\2\2\2\16\u00aa")
        buf.write("\3\2\2\2\20\u00ac\3\2\2\2\22\u00bf\3\2\2\2\24\u00c7\3")
        buf.write("\2\2\2\26\u00cc\3\2\2\2\30\u00d5\3\2\2\2\32\u00ee\3\2")
        buf.write("\2\2\34\u00f2\3\2\2\2\36\u00f4\3\2\2\2 \u0109\3\2\2\2")
        buf.write("\"\u0111\3\2\2\2$\u0117\3\2\2\2&\u0123\3\2\2\2(\u0125")
        buf.write("\3\2\2\2*\u0128\3\2\2\2,\u012b\3\2\2\2.\u012d\3\2\2\2")
        buf.write("\60\u0130\3\2\2\2\62\u0134\3\2\2\2\64\u0138\3\2\2\2\66")
        buf.write("\u013c\3\2\2\28\u013e\3\2\2\2:\u0150\3\2\2\2<\u0154\3")
        buf.write("\2\2\2>\u015c\3\2\2\2@\u015e\3\2\2\2B\u0164\3\2\2\2D\u016a")
        buf.write("\3\2\2\2F\u0170\3\2\2\2H\u0174\3\2\2\2J\u0178\3\2\2\2")
        buf.write("L\u017d\3\2\2\2N\u0184\3\2\2\2P\u018b\3\2\2\2R\u018d\3")
        buf.write("\2\2\2T\u0190\3\2\2\2V\u019b\3\2\2\2X\u01ad\3\2\2\2Z\u01bd")
        buf.write("\3\2\2\2\\\u01bf\3\2\2\2^\u01c5\3\2\2\2`\u01c7\3\2\2\2")
        buf.write("b\u01ca\3\2\2\2df\5\4\3\2ed\3\2\2\2ef\3\2\2\2fo\3\2\2")
        buf.write("\2gi\7E\2\2hg\3\2\2\2ij\3\2\2\2jh\3\2\2\2jk\3\2\2\2kl")
        buf.write("\3\2\2\2ln\5\4\3\2mh\3\2\2\2nq\3\2\2\2om\3\2\2\2op\3\2")
        buf.write("\2\2pu\3\2\2\2qo\3\2\2\2rt\7E\2\2sr\3\2\2\2tw\3\2\2\2")
        buf.write("us\3\2\2\2uv\3\2\2\2vx\3\2\2\2wu\3\2\2\2xy\7\2\2\3y\3")
        buf.write("\3\2\2\2z~\5\20\t\2{~\5\30\r\2|~\5\6\4\2}z\3\2\2\2}{\3")
        buf.write("\2\2\2}|\3\2\2\2~\5\3\2\2\2\177\u0092\5\b\5\2\u0080\u0092")
        buf.write("\5$\23\2\u0081\u0092\5(\25\2\u0082\u0092\5,\27\2\u0083")
        buf.write("\u0092\5.\30\2\u0084\u0092\5\60\31\2\u0085\u0092\5\62")
        buf.write("\32\2\u0086\u0092\5\64\33\2\u0087\u0092\5\66\34\2\u0088")
        buf.write("\u0092\5<\37\2\u0089\u0092\5> \2\u008a\u0092\5N(\2\u008b")
        buf.write("\u0092\5J&\2\u008c\u0092\5L\'\2\u008d\u0092\5P)\2\u008e")
        buf.write("\u0092\5R*\2\u008f\u0092\5T+\2\u0090\u0092\58\35\2\u0091")
        buf.write("\177\3\2\2\2\u0091\u0080\3\2\2\2\u0091\u0081\3\2\2\2\u0091")
        buf.write("\u0082\3\2\2\2\u0091\u0083\3\2\2\2\u0091\u0084\3\2\2\2")
        buf.write("\u0091\u0085\3\2\2\2\u0091\u0086\3\2\2\2\u0091\u0087\3")
        buf.write("\2\2\2\u0091\u0088\3\2\2\2\u0091\u0089\3\2\2\2\u0091\u008a")
        buf.write("\3\2\2\2\u0091\u008b\3\2\2\2\u0091\u008c\3\2\2\2\u0091")
        buf.write("\u008d\3\2\2\2\u0091\u008e\3\2\2\2\u0091\u008f\3\2\2\2")
        buf.write("\u0091\u0090\3\2\2\2\u0092\7\3\2\2\2\u0093\u009f\5\n\6")
        buf.write("\2\u0094\u0095\7;\2\2\u0095\u009a\5\16\b\2\u0096\u0097")
        buf.write("\7:\2\2\u0097\u0099\5\16\b\2\u0098\u0096\3\2\2\2\u0099")
        buf.write("\u009c\3\2\2\2\u009a\u0098\3\2\2\2\u009a\u009b\3\2\2\2")
        buf.write("\u009b\u009d\3\2\2\2\u009c\u009a\3\2\2\2\u009d\u009e\7")
        buf.write("<\2\2\u009e\u00a0\3\2\2\2\u009f\u0094\3\2\2\2\u009f\u00a0")
        buf.write("\3\2\2\2\u00a0\u00a2\3\2\2\2\u00a1\u00a3\5\f\7\2\u00a2")
        buf.write("\u00a1\3\2\2\2\u00a3\u00a4\3\2\2\2\u00a4\u00a2\3\2\2\2")
        buf.write("\u00a4\u00a5\3\2\2\2\u00a5\t\3\2\2\2\u00a6\u00a7\7\65")
        buf.write("\2\2\u00a7\13\3\2\2\2\u00a8\u00a9\7\66\2\2\u00a9\r\3\2")
        buf.write("\2\2\u00aa\u00ab\5X-\2\u00ab\17\3\2\2\2\u00ac\u00ad\7")
        buf.write("\3\2\2\u00ad\u00b9\5\n\6\2\u00ae\u00af\7;\2\2\u00af\u00b4")
        buf.write("\5\22\n\2\u00b0\u00b1\7:\2\2\u00b1\u00b3\5\22\n\2\u00b2")
        buf.write("\u00b0\3\2\2\2\u00b3\u00b6\3\2\2\2\u00b4\u00b2\3\2\2\2")
        buf.write("\u00b4\u00b5\3\2\2\2\u00b5\u00b7\3\2\2\2\u00b6\u00b4\3")
        buf.write("\2\2\2\u00b7\u00b8\7<\2\2\u00b8\u00ba\3\2\2\2\u00b9\u00ae")
        buf.write("\3\2\2\2\u00b9\u00ba\3\2\2\2\u00ba\u00bb\3\2\2\2\u00bb")
        buf.write("\u00bc\7?\2\2\u00bc\u00bd\7E\2\2\u00bd\u00be\5\24\13\2")
        buf.write("\u00be\21\3\2\2\2\u00bf\u00c0\7@\2\2\u00c0\u00c1\7\65")
        buf.write("\2\2\u00c1\23\3\2\2\2\u00c2\u00c3\5\26\f\2\u00c3\u00c4")
        buf.write("\7E\2\2\u00c4\u00c6\3\2\2\2\u00c5\u00c2\3\2\2\2\u00c6")
        buf.write("\u00c9\3\2\2\2\u00c7\u00c5\3\2\2\2\u00c7\u00c8\3\2\2\2")
        buf.write("\u00c8\u00ca\3\2\2\2\u00c9\u00c7\3\2\2\2\u00ca\u00cb\5")
        buf.write("\26\f\2\u00cb\25\3\2\2\2\u00cc\u00cd\7D\2\2\u00cd\u00d2")
        buf.write("\5X-\2\u00ce\u00cf\7:\2\2\u00cf\u00d1\5X-\2\u00d0\u00ce")
        buf.write("\3\2\2\2\u00d1\u00d4\3\2\2\2\u00d2\u00d0\3\2\2\2\u00d2")
        buf.write("\u00d3\3\2\2\2\u00d3\27\3\2\2\2\u00d4\u00d2\3\2\2\2\u00d5")
        buf.write("\u00d6\7\4\2\2\u00d6\u00e2\5\n\6\2\u00d7\u00d8\7;\2\2")
        buf.write("\u00d8\u00dd\5\22\n\2\u00d9\u00da\7:\2\2\u00da\u00dc\5")
        buf.write("\22\n\2\u00db\u00d9\3\2\2\2\u00dc\u00df\3\2\2\2\u00dd")
        buf.write("\u00db\3\2\2\2\u00dd\u00de\3\2\2\2\u00de\u00e0\3\2\2\2")
        buf.write("\u00df\u00dd\3\2\2\2\u00e0\u00e1\7<\2\2\u00e1\u00e3\3")
        buf.write("\2\2\2\u00e2\u00d7\3\2\2\2\u00e2\u00e3\3\2\2\2\u00e3\u00e7")
        buf.write("\3\2\2\2\u00e4\u00e6\5\32\16\2\u00e5\u00e4\3\2\2\2\u00e6")
        buf.write("\u00e9\3\2\2\2\u00e7\u00e5\3\2\2\2\u00e7\u00e8\3\2\2\2")
        buf.write("\u00e8\u00ea\3\2\2\2\u00e9\u00e7\3\2\2\2\u00ea\u00eb\7")
        buf.write("?\2\2\u00eb\u00ec\7E\2\2\u00ec\u00ed\5\"\22\2\u00ed\31")
        buf.write("\3\2\2\2\u00ee\u00ef\7\65\2\2\u00ef\33\3\2\2\2\u00f0\u00f3")
        buf.write("\5\f\7\2\u00f1\u00f3\5\32\16\2\u00f2\u00f0\3\2\2\2\u00f2")
        buf.write("\u00f1\3\2\2\2\u00f3\35\3\2\2\2\u00f4\u0100\5\n\6\2\u00f5")
        buf.write("\u00f6\7;\2\2\u00f6\u00fb\5\16\b\2\u00f7\u00f8\7:\2\2")
        buf.write("\u00f8\u00fa\5\16\b\2\u00f9\u00f7\3\2\2\2\u00fa\u00fd")
        buf.write("\3\2\2\2\u00fb\u00f9\3\2\2\2\u00fb\u00fc\3\2\2\2\u00fc")
        buf.write("\u00fe\3\2\2\2\u00fd\u00fb\3\2\2\2\u00fe\u00ff\7<\2\2")
        buf.write("\u00ff\u0101\3\2\2\2\u0100\u00f5\3\2\2\2\u0100\u0101\3")
        buf.write("\2\2\2\u0101\u0103\3\2\2\2\u0102\u0104\5\34\17\2\u0103")
        buf.write("\u0102\3\2\2\2\u0104\u0105\3\2\2\2\u0105\u0103\3\2\2\2")
        buf.write("\u0105\u0106\3\2\2\2\u0106\37\3\2\2\2\u0107\u010a\5\36")
        buf.write("\20\2\u0108\u010a\5\6\4\2\u0109\u0107\3\2\2\2\u0109\u0108")
        buf.write("\3\2\2\2\u010a!\3\2\2\2\u010b\u010c\7D\2\2\u010c\u010d")
        buf.write("\5 \21\2\u010d\u010e\7E\2\2\u010e\u0110\3\2\2\2\u010f")
        buf.write("\u010b\3\2\2\2\u0110\u0113\3\2\2\2\u0111\u010f\3\2\2\2")
        buf.write("\u0111\u0112\3\2\2\2\u0112\u0114\3\2\2\2\u0113\u0111\3")
        buf.write("\2\2\2\u0114\u0115\7D\2\2\u0115\u0116\5 \21\2\u0116#\3")
        buf.write("\2\2\2\u0117\u0118\7\5\2\2\u0118\u011a\5\f\7\2\u0119\u011b")
        buf.write("\5&\24\2\u011a\u0119\3\2\2\2\u011a\u011b\3\2\2\2\u011b")
        buf.write("%\3\2\2\2\u011c\u0124\7\65\2\2\u011d\u011f\7\65\2\2\u011e")
        buf.write("\u011d\3\2\2\2\u011e\u011f\3\2\2\2\u011f\u0120\3\2\2\2")
        buf.write("\u0120\u0121\7=\2\2\u0121\u0122\7\66\2\2\u0122\u0124\7")
        buf.write(">\2\2\u0123\u011c\3\2\2\2\u0123\u011e\3\2\2\2\u0124\'")
        buf.write("\3\2\2\2\u0125\u0126\7\6\2\2\u0126\u0127\5*\26\2\u0127")
        buf.write(")\3\2\2\2\u0128\u0129\7A\2\2\u0129\u012a\7\65\2\2\u012a")
        buf.write("+\3\2\2\2\u012b\u012c\7\7\2\2\u012c-\3\2\2\2\u012d\u012e")
        buf.write("\7\b\2\2\u012e\u012f\5*\26\2\u012f/\3\2\2\2\u0130\u0131")
        buf.write("\7\t\2\2\u0131\u0132\5*\26\2\u0132\u0133\5&\24\2\u0133")
        buf.write("\61\3\2\2\2\u0134\u0135\7\n\2\2\u0135\u0136\5*\26\2\u0136")
        buf.write("\u0137\5&\24\2\u0137\63\3\2\2\2\u0138\u013a\7\13\2\2\u0139")
        buf.write("\u013b\5\f\7\2\u013a\u0139\3\2\2\2\u013a\u013b\3\2\2\2")
        buf.write("\u013b\65\3\2\2\2\u013c\u013d\7\f\2\2\u013d\67\3\2\2\2")
        buf.write("\u013e\u013f\7\20\2\2\u013f\u0140\7\65\2\2\u0140\u0144")
        buf.write("\7\65\2\2\u0141\u0142\7=\2\2\u0142\u0143\7\66\2\2\u0143")
        buf.write("\u0145\7>\2\2\u0144\u0141\3\2\2\2\u0144\u0145\3\2\2\2")
        buf.write("\u0145\u014e\3\2\2\2\u0146\u0147\7\21\2\2\u0147\u014b")
        buf.write("\7\65\2\2\u0148\u014a\5:\36\2\u0149\u0148\3\2\2\2\u014a")
        buf.write("\u014d\3\2\2\2\u014b\u0149\3\2\2\2\u014b\u014c\3\2\2\2")
        buf.write("\u014c\u014f\3\2\2\2\u014d\u014b\3\2\2\2\u014e\u0146\3")
        buf.write("\2\2\2\u014e\u014f\3\2\2\2\u014f9\3\2\2\2\u0150\u0151")
        buf.write("\7\22\2\2\u0151\u0152\7\66\2\2\u0152\u0153\7\65\2\2\u0153")
        buf.write(";\3\2\2\2\u0154\u0155\t\2\2\2\u0155\u0156\5&\24\2\u0156")
        buf.write("=\3\2\2\2\u0157\u015d\5@!\2\u0158\u015d\5B\"\2\u0159\u015d")
        buf.write("\5D#\2\u015a\u015d\5F$\2\u015b\u015d\5H%\2\u015c\u0157")
        buf.write("\3\2\2\2\u015c\u0158\3\2\2\2\u015c\u0159\3\2\2\2\u015c")
        buf.write("\u015a\3\2\2\2\u015c\u015b\3\2\2\2\u015d?\3\2\2\2\u015e")
        buf.write("\u015f\t\3\2\2\u015f\u0162\5&\24\2\u0160\u0163\5&\24\2")
        buf.write("\u0161\u0163\7\66\2\2\u0162\u0160\3\2\2\2\u0162\u0161")
        buf.write("\3\2\2\2\u0163A\3\2\2\2\u0164\u0165\t\4\2\2\u0165\u0168")
        buf.write("\5&\24\2\u0166\u0169\5&\24\2\u0167\u0169\5^\60\2\u0168")
        buf.write("\u0166\3\2\2\2\u0168\u0167\3\2\2\2\u0169C\3\2\2\2\u016a")
        buf.write("\u016b\7\37\2\2\u016b\u016e\5&\24\2\u016c\u016f\5&\24")
        buf.write("\2\u016d\u016f\5^\60\2\u016e\u016c\3\2\2\2\u016e\u016d")
        buf.write("\3\2\2\2\u016fE\3\2\2\2\u0170\u0171\7 \2\2\u0171\u0172")
        buf.write("\5&\24\2\u0172\u0173\5&\24\2\u0173G\3\2\2\2\u0174\u0175")
        buf.write("\7!\2\2\u0175\u0176\5&\24\2\u0176\u0177\5&\24\2\u0177")
        buf.write("I\3\2\2\2\u0178\u0179\7\'\2\2\u0179\u017a\5&\24\2\u017a")
        buf.write("\u017b\7\65\2\2\u017b\u017c\5&\24\2\u017cK\3\2\2\2\u017d")
        buf.write("\u017e\7(\2\2\u017e\u017f\7\65\2\2\u017f\u0182\5&\24\2")
        buf.write("\u0180\u0183\5&\24\2\u0181\u0183\5^\60\2\u0182\u0180\3")
        buf.write("\2\2\2\u0182\u0181\3\2\2\2\u0183M\3\2\2\2\u0184\u0185")
        buf.write("\t\5\2\2\u0185\u0186\5&\24\2\u0186\u0189\5&\24\2\u0187")
        buf.write("\u018a\5&\24\2\u0188\u018a\5^\60\2\u0189\u0187\3\2\2\2")
        buf.write("\u0189\u0188\3\2\2\2\u018aO\3\2\2\2\u018b\u018c\7\r\2")
        buf.write("\2\u018cQ\3\2\2\2\u018d\u018e\7\16\2\2\u018e\u018f\78")
        buf.write("\2\2\u018fS\3\2\2\2\u0190\u0191\7\17\2\2\u0191\u0195\7")
        buf.write("\65\2\2\u0192\u0194\5V,\2\u0193\u0192\3\2\2\2\u0194\u0197")
        buf.write("\3\2\2\2\u0195\u0193\3\2\2\2\u0195\u0196\3\2\2\2\u0196")
        buf.write("\u0199\3\2\2\2\u0197\u0195\3\2\2\2\u0198\u019a\78\2\2")
        buf.write("\u0199\u0198\3\2\2\2\u0199\u019a\3\2\2\2\u019aU\3\2\2")
        buf.write("\2\u019b\u019c\t\6\2\2\u019cW\3\2\2\2\u019d\u019e\b-\1")
        buf.write("\2\u019e\u019f\7;\2\2\u019f\u01a0\5X-\2\u01a0\u01a1\7")
        buf.write("<\2\2\u01a1\u01ae\3\2\2\2\u01a2\u01a3\5\\/\2\u01a3\u01a4")
        buf.write("\5X-\n\u01a4\u01ae\3\2\2\2\u01a5\u01a6\5Z.\2\u01a6\u01a7")
        buf.write("\7;\2\2\u01a7\u01a8\5X-\2\u01a8\u01a9\7<\2\2\u01a9\u01ae")
        buf.write("\3\2\2\2\u01aa\u01ae\5^\60\2\u01ab\u01ae\5\22\n\2\u01ac")
        buf.write("\u01ae\5&\24\2\u01ad\u019d\3\2\2\2\u01ad\u01a2\3\2\2\2")
        buf.write("\u01ad\u01a5\3\2\2\2\u01ad\u01aa\3\2\2\2\u01ad\u01ab\3")
        buf.write("\2\2\2\u01ad\u01ac\3\2\2\2\u01ae\u01ba\3\2\2\2\u01af\u01b0")
        buf.write("\f\t\2\2\u01b0\u01b1\7\64\2\2\u01b1\u01b9\5X-\t\u01b2")
        buf.write("\u01b3\f\b\2\2\u01b3\u01b4\t\7\2\2\u01b4\u01b9\5X-\t\u01b5")
        buf.write("\u01b6\f\7\2\2\u01b6\u01b7\t\b\2\2\u01b7\u01b9\5X-\b\u01b8")
        buf.write("\u01af\3\2\2\2\u01b8\u01b2\3\2\2\2\u01b8\u01b5\3\2\2\2")
        buf.write("\u01b9\u01bc\3\2\2\2\u01ba\u01b8\3\2\2\2\u01ba\u01bb\3")
        buf.write("\2\2\2\u01bbY\3\2\2\2\u01bc\u01ba\3\2\2\2\u01bd\u01be")
        buf.write("\t\t\2\2\u01be[\3\2\2\2\u01bf\u01c0\t\b\2\2\u01c0]\3\2")
        buf.write("\2\2\u01c1\u01c6\5b\62\2\u01c2\u01c6\5`\61\2\u01c3\u01c6")
        buf.write("\7*\2\2\u01c4\u01c6\7)\2\2\u01c5\u01c1\3\2\2\2\u01c5\u01c2")
        buf.write("\3\2\2\2\u01c5\u01c3\3\2\2\2\u01c5\u01c4\3\2\2\2\u01c6")
        buf.write("_\3\2\2\2\u01c7\u01c8\5b\62\2\u01c8\u01c9\7*\2\2\u01c9")
        buf.write("a\3\2\2\2\u01ca\u01cb\t\n\2\2\u01cbc\3\2\2\2+ejou}\u0091")
        buf.write("\u009a\u009f\u00a4\u00b4\u00b9\u00c7\u00d2\u00dd\u00e2")
        buf.write("\u00e7\u00f2\u00fb\u0100\u0105\u0109\u0111\u011a\u011e")
        buf.write("\u0123\u013a\u0144\u014b\u014e\u015c\u0162\u0168\u016e")
        buf.write("\u0182\u0189\u0195\u0199\u01ad\u01b8\u01ba\u01c5")
        return buf.getvalue()


class QuilParser ( Parser ):

    grammarFileName = "Quil.g4"

    atn = ATNDeserializer().deserialize(serializedATN())

    decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]

    sharedContextCache = PredictionContextCache()

    literalNames = [ "<INVALID>", "'DEFGATE'", "'DEFCIRCUIT'", "'MEASURE'", 
                     "'LABEL'", "'HALT'", "'JUMP'", "'JUMP-WHEN'", "'JUMP-UNLESS'", 
                     "'RESET'", "'WAIT'", "'NOP'", "'INCLUDE'", "'PRAGMA'", 
                     "'DECLARE'", "'SHARING'", "'OFFSET'", "'NEG'", "'NOT'", 
                     "'TRUE'", "'FALSE'", "'AND'", "'IOR'", "'XOR'", "'OR'", 
                     "'ADD'", "'SUB'", "'MUL'", "'DIV'", "'MOVE'", "'EXCHANGE'", 
                     "'CONVERT'", "'EQ'", "'GT'", "'GE'", "'LT'", "'LE'", 
                     "'LOAD'", "'STORE'", "'pi'", "'i'", "'sin'", "'cos'", 
                     "'sqrt'", "'exp'", "'cis'", "'+'", "'-'", "'*'", "'/'", 
                     "'^'", "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 
                     "'.'", "','", "'('", "')'", "'['", "']'", "':'", "'%'", 
                     "'@'", "'\"'", "'_'", "'    '", "<INVALID>", "<INVALID>", 
                     "' '" ]

    symbolicNames = [ "<INVALID>", "DEFGATE", "DEFCIRCUIT", "MEASURE", "LABEL", 
                      "HALT", "JUMP", "JUMPWHEN", "JUMPUNLESS", "RESET", 
                      "WAIT", "NOP", "INCLUDE", "PRAGMA", "DECLARE", "SHARING", 
                      "OFFSET", "NEG", "NOT", "TRUE", "FALSE", "AND", "IOR", 
                      "XOR", "OR", "ADD", "SUB", "MUL", "DIV", "MOVE", "EXCHANGE", 
                      "CONVERT", "EQ", "GT", "GE", "LT", "LE", "LOAD", "STORE", 
                      "PI", "I", "SIN", "COS", "SQRT", "EXP", "CIS", "PLUS", 
                      "MINUS", "TIMES", "DIVIDE", "POWER", "IDENTIFIER", 
                      "INT", "FLOAT", "STRING", "PERIOD", "COMMA", "LPAREN", 
                      "RPAREN", "LBRACKET", "RBRACKET", "COLON", "PERCENTAGE", 
                      "AT", "QUOTE", "UNDERSCORE", "TAB", "NEWLINE", "COMMENT", 
                      "SPACE", "INVALID" ]

    RULE_quil = 0
    RULE_allInstr = 1
    RULE_instr = 2
    RULE_gate = 3
    RULE_name = 4
    RULE_qubit = 5
    RULE_param = 6
    RULE_defGate = 7
    RULE_variable = 8
    RULE_matrix = 9
    RULE_matrixRow = 10
    RULE_defCircuit = 11
    RULE_qubitVariable = 12
    RULE_circuitQubit = 13
    RULE_circuitGate = 14
    RULE_circuitInstr = 15
    RULE_circuit = 16
    RULE_measure = 17
    RULE_addr = 18
    RULE_defLabel = 19
    RULE_label = 20
    RULE_halt = 21
    RULE_jump = 22
    RULE_jumpWhen = 23
    RULE_jumpUnless = 24
    RULE_resetState = 25
    RULE_wait = 26
    RULE_memoryDescriptor = 27
    RULE_offsetDescriptor = 28
    RULE_classicalUnary = 29
    RULE_classicalBinary = 30
    RULE_logicalBinaryOp = 31
    RULE_arithmeticBinaryOp = 32
    RULE_move = 33
    RULE_exchange = 34
    RULE_convert = 35
    RULE_load = 36
    RULE_store = 37
    RULE_classicalComparison = 38
    RULE_nop = 39
    RULE_include = 40
    RULE_pragma = 41
    RULE_pragma_name = 42
    RULE_expression = 43
    RULE_function = 44
    RULE_sign = 45
    RULE_number = 46
    RULE_imaginaryN = 47
    RULE_realN = 48

    ruleNames =  [ "quil", "allInstr", "instr", "gate", "name", "qubit", 
                   "param", "defGate", "variable", "matrix", "matrixRow", 
                   "defCircuit", "qubitVariable", "circuitQubit", "circuitGate", 
                   "circuitInstr", "circuit", "measure", "addr", "defLabel", 
                   "label", "halt", "jump", "jumpWhen", "jumpUnless", "resetState", 
                   "wait", "memoryDescriptor", "offsetDescriptor", "classicalUnary", 
                   "classicalBinary", "logicalBinaryOp", "arithmeticBinaryOp", 
                   "move", "exchange", "convert", "load", "store", "classicalComparison", 
                   "nop", "include", "pragma", "pragma_name", "expression", 
                   "function", "sign", "number", "imaginaryN", "realN" ]

    EOF = Token.EOF
    DEFGATE=1
    DEFCIRCUIT=2
    MEASURE=3
    LABEL=4
    HALT=5
    JUMP=6
    JUMPWHEN=7
    JUMPUNLESS=8
    RESET=9
    WAIT=10
    NOP=11
    INCLUDE=12
    PRAGMA=13
    DECLARE=14
    SHARING=15
    OFFSET=16
    NEG=17
    NOT=18
    TRUE=19
    FALSE=20
    AND=21
    IOR=22
    XOR=23
    OR=24
    ADD=25
    SUB=26
    MUL=27
    DIV=28
    MOVE=29
    EXCHANGE=30
    CONVERT=31
    EQ=32
    GT=33
    GE=34
    LT=35
    LE=36
    LOAD=37
    STORE=38
    PI=39
    I=40
    SIN=41
    COS=42
    SQRT=43
    EXP=44
    CIS=45
    PLUS=46
    MINUS=47
    TIMES=48
    DIVIDE=49
    POWER=50
    IDENTIFIER=51
    INT=52
    FLOAT=53
    STRING=54
    PERIOD=55
    COMMA=56
    LPAREN=57
    RPAREN=58
    LBRACKET=59
    RBRACKET=60
    COLON=61
    PERCENTAGE=62
    AT=63
    QUOTE=64
    UNDERSCORE=65
    TAB=66
    NEWLINE=67
    COMMENT=68
    SPACE=69
    INVALID=70

    def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
        super().__init__(input, output)
        self.checkVersion("4.7.1")
        self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
        self._predicates = None



    class QuilContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def EOF(self):
            return self.getToken(QuilParser.EOF, 0)

        def allInstr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AllInstrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AllInstrContext,i)


        def NEWLINE(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.NEWLINE)
            else:
                return self.getToken(QuilParser.NEWLINE, i)

        def getRuleIndex(self):
            return QuilParser.RULE_quil

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterQuil" ):
                listener.enterQuil(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitQuil" ):
                listener.exitQuil(self)




    def quil(self):

        localctx = QuilParser.QuilContext(self, self._ctx, self.state)
        self.enterRule(localctx, 0, self.RULE_quil)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 99
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.DEFGATE) | (1 << QuilParser.DEFCIRCUIT) | (1 << QuilParser.MEASURE) | (1 << QuilParser.LABEL) | (1 << QuilParser.HALT) | (1 << QuilParser.JUMP) | (1 << QuilParser.JUMPWHEN) | (1 << QuilParser.JUMPUNLESS) | (1 << QuilParser.RESET) | (1 << QuilParser.WAIT) | (1 << QuilParser.NOP) | (1 << QuilParser.INCLUDE) | (1 << QuilParser.PRAGMA) | (1 << QuilParser.DECLARE) | (1 << QuilParser.NEG) | (1 << QuilParser.NOT) | (1 << QuilParser.TRUE) | (1 << QuilParser.FALSE) | (1 << QuilParser.AND) | (1 << QuilParser.IOR) | (1 << QuilParser.XOR) | (1 << QuilParser.OR) | (1 << QuilParser.ADD) | (1 << QuilParser.SUB) | (1 << QuilParser.MUL) | (1 << QuilParser.DIV) | (1 << QuilParser.MOVE) | (1 << QuilParser.EXCHANGE) | (1 << QuilParser.CONVERT) | (1 << QuilParser.EQ) | (1 << QuilParser.GT) | (1 << QuilParser.GE) | (1 << QuilParser.LT) | (1 << QuilParser.LE) | (1 << QuilParser.LOAD) | (1 << QuilParser.STORE) | (1 << QuilParser.IDENTIFIER))) != 0):
                self.state = 98
                self.allInstr()


            self.state = 109
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,2,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 102 
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)
                    while True:
                        self.state = 101
                        self.match(QuilParser.NEWLINE)
                        self.state = 104 
                        self._errHandler.sync(self)
                        _la = self._input.LA(1)
                        if not (_la==QuilParser.NEWLINE):
                            break

                    self.state = 106
                    self.allInstr() 
                self.state = 111
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,2,self._ctx)

            self.state = 115
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.NEWLINE:
                self.state = 112
                self.match(QuilParser.NEWLINE)
                self.state = 117
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 118
            self.match(QuilParser.EOF)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class AllInstrContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def defGate(self):
            return self.getTypedRuleContext(QuilParser.DefGateContext,0)


        def defCircuit(self):
            return self.getTypedRuleContext(QuilParser.DefCircuitContext,0)


        def instr(self):
            return self.getTypedRuleContext(QuilParser.InstrContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_allInstr

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterAllInstr" ):
                listener.enterAllInstr(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitAllInstr" ):
                listener.exitAllInstr(self)




    def allInstr(self):

        localctx = QuilParser.AllInstrContext(self, self._ctx, self.state)
        self.enterRule(localctx, 2, self.RULE_allInstr)
        try:
            self.state = 123
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.DEFGATE]:
                self.enterOuterAlt(localctx, 1)
                self.state = 120
                self.defGate()
                pass
            elif token in [QuilParser.DEFCIRCUIT]:
                self.enterOuterAlt(localctx, 2)
                self.state = 121
                self.defCircuit()
                pass
            elif token in [QuilParser.MEASURE, QuilParser.LABEL, QuilParser.HALT, QuilParser.JUMP, QuilParser.JUMPWHEN, QuilParser.JUMPUNLESS, QuilParser.RESET, QuilParser.WAIT, QuilParser.NOP, QuilParser.INCLUDE, QuilParser.PRAGMA, QuilParser.DECLARE, QuilParser.NEG, QuilParser.NOT, QuilParser.TRUE, QuilParser.FALSE, QuilParser.AND, QuilParser.IOR, QuilParser.XOR, QuilParser.OR, QuilParser.ADD, QuilParser.SUB, QuilParser.MUL, QuilParser.DIV, QuilParser.MOVE, QuilParser.EXCHANGE, QuilParser.CONVERT, QuilParser.EQ, QuilParser.GT, QuilParser.GE, QuilParser.LT, QuilParser.LE, QuilParser.LOAD, QuilParser.STORE, QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 3)
                self.state = 122
                self.instr()
                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 InstrContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def gate(self):
            return self.getTypedRuleContext(QuilParser.GateContext,0)


        def measure(self):
            return self.getTypedRuleContext(QuilParser.MeasureContext,0)


        def defLabel(self):
            return self.getTypedRuleContext(QuilParser.DefLabelContext,0)


        def halt(self):
            return self.getTypedRuleContext(QuilParser.HaltContext,0)


        def jump(self):
            return self.getTypedRuleContext(QuilParser.JumpContext,0)


        def jumpWhen(self):
            return self.getTypedRuleContext(QuilParser.JumpWhenContext,0)


        def jumpUnless(self):
            return self.getTypedRuleContext(QuilParser.JumpUnlessContext,0)


        def resetState(self):
            return self.getTypedRuleContext(QuilParser.ResetStateContext,0)


        def wait(self):
            return self.getTypedRuleContext(QuilParser.WaitContext,0)


        def classicalUnary(self):
            return self.getTypedRuleContext(QuilParser.ClassicalUnaryContext,0)


        def classicalBinary(self):
            return self.getTypedRuleContext(QuilParser.ClassicalBinaryContext,0)


        def classicalComparison(self):
            return self.getTypedRuleContext(QuilParser.ClassicalComparisonContext,0)


        def load(self):
            return self.getTypedRuleContext(QuilParser.LoadContext,0)


        def store(self):
            return self.getTypedRuleContext(QuilParser.StoreContext,0)


        def nop(self):
            return self.getTypedRuleContext(QuilParser.NopContext,0)


        def include(self):
            return self.getTypedRuleContext(QuilParser.IncludeContext,0)


        def pragma(self):
            return self.getTypedRuleContext(QuilParser.PragmaContext,0)


        def memoryDescriptor(self):
            return self.getTypedRuleContext(QuilParser.MemoryDescriptorContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_instr

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterInstr" ):
                listener.enterInstr(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitInstr" ):
                listener.exitInstr(self)




    def instr(self):

        localctx = QuilParser.InstrContext(self, self._ctx, self.state)
        self.enterRule(localctx, 4, self.RULE_instr)
        try:
            self.state = 143
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 1)
                self.state = 125
                self.gate()
                pass
            elif token in [QuilParser.MEASURE]:
                self.enterOuterAlt(localctx, 2)
                self.state = 126
                self.measure()
                pass
            elif token in [QuilParser.LABEL]:
                self.enterOuterAlt(localctx, 3)
                self.state = 127
                self.defLabel()
                pass
            elif token in [QuilParser.HALT]:
                self.enterOuterAlt(localctx, 4)
                self.state = 128
                self.halt()
                pass
            elif token in [QuilParser.JUMP]:
                self.enterOuterAlt(localctx, 5)
                self.state = 129
                self.jump()
                pass
            elif token in [QuilParser.JUMPWHEN]:
                self.enterOuterAlt(localctx, 6)
                self.state = 130
                self.jumpWhen()
                pass
            elif token in [QuilParser.JUMPUNLESS]:
                self.enterOuterAlt(localctx, 7)
                self.state = 131
                self.jumpUnless()
                pass
            elif token in [QuilParser.RESET]:
                self.enterOuterAlt(localctx, 8)
                self.state = 132
                self.resetState()
                pass
            elif token in [QuilParser.WAIT]:
                self.enterOuterAlt(localctx, 9)
                self.state = 133
                self.wait()
                pass
            elif token in [QuilParser.NEG, QuilParser.NOT, QuilParser.TRUE, QuilParser.FALSE]:
                self.enterOuterAlt(localctx, 10)
                self.state = 134
                self.classicalUnary()
                pass
            elif token in [QuilParser.AND, QuilParser.IOR, QuilParser.XOR, QuilParser.OR, QuilParser.ADD, QuilParser.SUB, QuilParser.MUL, QuilParser.DIV, QuilParser.MOVE, QuilParser.EXCHANGE, QuilParser.CONVERT]:
                self.enterOuterAlt(localctx, 11)
                self.state = 135
                self.classicalBinary()
                pass
            elif token in [QuilParser.EQ, QuilParser.GT, QuilParser.GE, QuilParser.LT, QuilParser.LE]:
                self.enterOuterAlt(localctx, 12)
                self.state = 136
                self.classicalComparison()
                pass
            elif token in [QuilParser.LOAD]:
                self.enterOuterAlt(localctx, 13)
                self.state = 137
                self.load()
                pass
            elif token in [QuilParser.STORE]:
                self.enterOuterAlt(localctx, 14)
                self.state = 138
                self.store()
                pass
            elif token in [QuilParser.NOP]:
                self.enterOuterAlt(localctx, 15)
                self.state = 139
                self.nop()
                pass
            elif token in [QuilParser.INCLUDE]:
                self.enterOuterAlt(localctx, 16)
                self.state = 140
                self.include()
                pass
            elif token in [QuilParser.PRAGMA]:
                self.enterOuterAlt(localctx, 17)
                self.state = 141
                self.pragma()
                pass
            elif token in [QuilParser.DECLARE]:
                self.enterOuterAlt(localctx, 18)
                self.state = 142
                self.memoryDescriptor()
                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 GateContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def name(self):
            return self.getTypedRuleContext(QuilParser.NameContext,0)


        def LPAREN(self):
            return self.getToken(QuilParser.LPAREN, 0)

        def param(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.ParamContext)
            else:
                return self.getTypedRuleContext(QuilParser.ParamContext,i)


        def RPAREN(self):
            return self.getToken(QuilParser.RPAREN, 0)

        def qubit(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.QubitContext)
            else:
                return self.getTypedRuleContext(QuilParser.QubitContext,i)


        def COMMA(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.COMMA)
            else:
                return self.getToken(QuilParser.COMMA, i)

        def getRuleIndex(self):
            return QuilParser.RULE_gate

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterGate" ):
                listener.enterGate(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitGate" ):
                listener.exitGate(self)




    def gate(self):

        localctx = QuilParser.GateContext(self, self._ctx, self.state)
        self.enterRule(localctx, 6, self.RULE_gate)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 145
            self.name()
            self.state = 157
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 146
                self.match(QuilParser.LPAREN)
                self.state = 147
                self.param()
                self.state = 152
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 148
                    self.match(QuilParser.COMMA)
                    self.state = 149
                    self.param()
                    self.state = 154
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

                self.state = 155
                self.match(QuilParser.RPAREN)


            self.state = 160 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 159
                self.qubit()
                self.state = 162 
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                if not (_la==QuilParser.INT):
                    break

        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class NameContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_name

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterName" ):
                listener.enterName(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitName" ):
                listener.exitName(self)




    def name(self):

        localctx = QuilParser.NameContext(self, self._ctx, self.state)
        self.enterRule(localctx, 8, self.RULE_name)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 164
            self.match(QuilParser.IDENTIFIER)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class QubitContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def INT(self):
            return self.getToken(QuilParser.INT, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_qubit

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterQubit" ):
                listener.enterQubit(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitQubit" ):
                listener.exitQubit(self)




    def qubit(self):

        localctx = QuilParser.QubitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 10, self.RULE_qubit)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 166
            self.match(QuilParser.INT)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ParamContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def expression(self):
            return self.getTypedRuleContext(QuilParser.ExpressionContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_param

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterParam" ):
                listener.enterParam(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitParam" ):
                listener.exitParam(self)




    def param(self):

        localctx = QuilParser.ParamContext(self, self._ctx, self.state)
        self.enterRule(localctx, 12, self.RULE_param)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 168
            self.expression(0)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class DefGateContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def DEFGATE(self):
            return self.getToken(QuilParser.DEFGATE, 0)

        def name(self):
            return self.getTypedRuleContext(QuilParser.NameContext,0)


        def COLON(self):
            return self.getToken(QuilParser.COLON, 0)

        def NEWLINE(self):
            return self.getToken(QuilParser.NEWLINE, 0)

        def matrix(self):
            return self.getTypedRuleContext(QuilParser.MatrixContext,0)


        def LPAREN(self):
            return self.getToken(QuilParser.LPAREN, 0)

        def variable(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.VariableContext)
            else:
                return self.getTypedRuleContext(QuilParser.VariableContext,i)


        def RPAREN(self):
            return self.getToken(QuilParser.RPAREN, 0)

        def COMMA(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.COMMA)
            else:
                return self.getToken(QuilParser.COMMA, i)

        def getRuleIndex(self):
            return QuilParser.RULE_defGate

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterDefGate" ):
                listener.enterDefGate(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitDefGate" ):
                listener.exitDefGate(self)




    def defGate(self):

        localctx = QuilParser.DefGateContext(self, self._ctx, self.state)
        self.enterRule(localctx, 14, self.RULE_defGate)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 170
            self.match(QuilParser.DEFGATE)
            self.state = 171
            self.name()
            self.state = 183
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 172
                self.match(QuilParser.LPAREN)
                self.state = 173
                self.variable()
                self.state = 178
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 174
                    self.match(QuilParser.COMMA)
                    self.state = 175
                    self.variable()
                    self.state = 180
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

                self.state = 181
                self.match(QuilParser.RPAREN)


            self.state = 185
            self.match(QuilParser.COLON)
            self.state = 186
            self.match(QuilParser.NEWLINE)
            self.state = 187
            self.matrix()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class VariableContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def PERCENTAGE(self):
            return self.getToken(QuilParser.PERCENTAGE, 0)

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_variable

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterVariable" ):
                listener.enterVariable(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitVariable" ):
                listener.exitVariable(self)




    def variable(self):

        localctx = QuilParser.VariableContext(self, self._ctx, self.state)
        self.enterRule(localctx, 16, self.RULE_variable)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 189
            self.match(QuilParser.PERCENTAGE)
            self.state = 190
            self.match(QuilParser.IDENTIFIER)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class MatrixContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def matrixRow(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.MatrixRowContext)
            else:
                return self.getTypedRuleContext(QuilParser.MatrixRowContext,i)


        def NEWLINE(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.NEWLINE)
            else:
                return self.getToken(QuilParser.NEWLINE, i)

        def getRuleIndex(self):
            return QuilParser.RULE_matrix

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterMatrix" ):
                listener.enterMatrix(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitMatrix" ):
                listener.exitMatrix(self)




    def matrix(self):

        localctx = QuilParser.MatrixContext(self, self._ctx, self.state)
        self.enterRule(localctx, 18, self.RULE_matrix)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 197
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,11,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 192
                    self.matrixRow()
                    self.state = 193
                    self.match(QuilParser.NEWLINE) 
                self.state = 199
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,11,self._ctx)

            self.state = 200
            self.matrixRow()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class MatrixRowContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def TAB(self):
            return self.getToken(QuilParser.TAB, 0)

        def expression(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.ExpressionContext)
            else:
                return self.getTypedRuleContext(QuilParser.ExpressionContext,i)


        def COMMA(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.COMMA)
            else:
                return self.getToken(QuilParser.COMMA, i)

        def getRuleIndex(self):
            return QuilParser.RULE_matrixRow

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterMatrixRow" ):
                listener.enterMatrixRow(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitMatrixRow" ):
                listener.exitMatrixRow(self)




    def matrixRow(self):

        localctx = QuilParser.MatrixRowContext(self, self._ctx, self.state)
        self.enterRule(localctx, 20, self.RULE_matrixRow)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 202
            self.match(QuilParser.TAB)
            self.state = 203
            self.expression(0)
            self.state = 208
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.COMMA:
                self.state = 204
                self.match(QuilParser.COMMA)
                self.state = 205
                self.expression(0)
                self.state = 210
                self._errHandler.sync(self)
                _la = self._input.LA(1)

        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class DefCircuitContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def DEFCIRCUIT(self):
            return self.getToken(QuilParser.DEFCIRCUIT, 0)

        def name(self):
            return self.getTypedRuleContext(QuilParser.NameContext,0)


        def COLON(self):
            return self.getToken(QuilParser.COLON, 0)

        def NEWLINE(self):
            return self.getToken(QuilParser.NEWLINE, 0)

        def circuit(self):
            return self.getTypedRuleContext(QuilParser.CircuitContext,0)


        def LPAREN(self):
            return self.getToken(QuilParser.LPAREN, 0)

        def variable(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.VariableContext)
            else:
                return self.getTypedRuleContext(QuilParser.VariableContext,i)


        def RPAREN(self):
            return self.getToken(QuilParser.RPAREN, 0)

        def qubitVariable(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.QubitVariableContext)
            else:
                return self.getTypedRuleContext(QuilParser.QubitVariableContext,i)


        def COMMA(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.COMMA)
            else:
                return self.getToken(QuilParser.COMMA, i)

        def getRuleIndex(self):
            return QuilParser.RULE_defCircuit

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterDefCircuit" ):
                listener.enterDefCircuit(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitDefCircuit" ):
                listener.exitDefCircuit(self)




    def defCircuit(self):

        localctx = QuilParser.DefCircuitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 22, self.RULE_defCircuit)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 211
            self.match(QuilParser.DEFCIRCUIT)
            self.state = 212
            self.name()
            self.state = 224
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 213
                self.match(QuilParser.LPAREN)
                self.state = 214
                self.variable()
                self.state = 219
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 215
                    self.match(QuilParser.COMMA)
                    self.state = 216
                    self.variable()
                    self.state = 221
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

                self.state = 222
                self.match(QuilParser.RPAREN)


            self.state = 229
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.IDENTIFIER:
                self.state = 226
                self.qubitVariable()
                self.state = 231
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 232
            self.match(QuilParser.COLON)
            self.state = 233
            self.match(QuilParser.NEWLINE)
            self.state = 234
            self.circuit()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class QubitVariableContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_qubitVariable

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterQubitVariable" ):
                listener.enterQubitVariable(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitQubitVariable" ):
                listener.exitQubitVariable(self)




    def qubitVariable(self):

        localctx = QuilParser.QubitVariableContext(self, self._ctx, self.state)
        self.enterRule(localctx, 24, self.RULE_qubitVariable)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 236
            self.match(QuilParser.IDENTIFIER)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class CircuitQubitContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def qubit(self):
            return self.getTypedRuleContext(QuilParser.QubitContext,0)


        def qubitVariable(self):
            return self.getTypedRuleContext(QuilParser.QubitVariableContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_circuitQubit

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterCircuitQubit" ):
                listener.enterCircuitQubit(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitCircuitQubit" ):
                listener.exitCircuitQubit(self)




    def circuitQubit(self):

        localctx = QuilParser.CircuitQubitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 26, self.RULE_circuitQubit)
        try:
            self.state = 240
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.INT]:
                self.enterOuterAlt(localctx, 1)
                self.state = 238
                self.qubit()
                pass
            elif token in [QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 2)
                self.state = 239
                self.qubitVariable()
                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 CircuitGateContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def name(self):
            return self.getTypedRuleContext(QuilParser.NameContext,0)


        def LPAREN(self):
            return self.getToken(QuilParser.LPAREN, 0)

        def param(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.ParamContext)
            else:
                return self.getTypedRuleContext(QuilParser.ParamContext,i)


        def RPAREN(self):
            return self.getToken(QuilParser.RPAREN, 0)

        def circuitQubit(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.CircuitQubitContext)
            else:
                return self.getTypedRuleContext(QuilParser.CircuitQubitContext,i)


        def COMMA(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.COMMA)
            else:
                return self.getToken(QuilParser.COMMA, i)

        def getRuleIndex(self):
            return QuilParser.RULE_circuitGate

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterCircuitGate" ):
                listener.enterCircuitGate(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitCircuitGate" ):
                listener.exitCircuitGate(self)




    def circuitGate(self):

        localctx = QuilParser.CircuitGateContext(self, self._ctx, self.state)
        self.enterRule(localctx, 28, self.RULE_circuitGate)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 242
            self.name()
            self.state = 254
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 243
                self.match(QuilParser.LPAREN)
                self.state = 244
                self.param()
                self.state = 249
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 245
                    self.match(QuilParser.COMMA)
                    self.state = 246
                    self.param()
                    self.state = 251
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

                self.state = 252
                self.match(QuilParser.RPAREN)


            self.state = 257 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 256
                self.circuitQubit()
                self.state = 259 
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                if not (_la==QuilParser.IDENTIFIER or _la==QuilParser.INT):
                    break

        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class CircuitInstrContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def circuitGate(self):
            return self.getTypedRuleContext(QuilParser.CircuitGateContext,0)


        def instr(self):
            return self.getTypedRuleContext(QuilParser.InstrContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_circuitInstr

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterCircuitInstr" ):
                listener.enterCircuitInstr(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitCircuitInstr" ):
                listener.exitCircuitInstr(self)




    def circuitInstr(self):

        localctx = QuilParser.CircuitInstrContext(self, self._ctx, self.state)
        self.enterRule(localctx, 30, self.RULE_circuitInstr)
        try:
            self.state = 263
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,20,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 261
                self.circuitGate()
                pass

            elif la_ == 2:
                self.enterOuterAlt(localctx, 2)
                self.state = 262
                self.instr()
                pass


        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class CircuitContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def TAB(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.TAB)
            else:
                return self.getToken(QuilParser.TAB, i)

        def circuitInstr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.CircuitInstrContext)
            else:
                return self.getTypedRuleContext(QuilParser.CircuitInstrContext,i)


        def NEWLINE(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.NEWLINE)
            else:
                return self.getToken(QuilParser.NEWLINE, i)

        def getRuleIndex(self):
            return QuilParser.RULE_circuit

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterCircuit" ):
                listener.enterCircuit(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitCircuit" ):
                listener.exitCircuit(self)




    def circuit(self):

        localctx = QuilParser.CircuitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 32, self.RULE_circuit)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 271
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,21,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 265
                    self.match(QuilParser.TAB)
                    self.state = 266
                    self.circuitInstr()
                    self.state = 267
                    self.match(QuilParser.NEWLINE) 
                self.state = 273
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,21,self._ctx)

            self.state = 274
            self.match(QuilParser.TAB)
            self.state = 275
            self.circuitInstr()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class MeasureContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def MEASURE(self):
            return self.getToken(QuilParser.MEASURE, 0)

        def qubit(self):
            return self.getTypedRuleContext(QuilParser.QubitContext,0)


        def addr(self):
            return self.getTypedRuleContext(QuilParser.AddrContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_measure

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterMeasure" ):
                listener.enterMeasure(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitMeasure" ):
                listener.exitMeasure(self)




    def measure(self):

        localctx = QuilParser.MeasureContext(self, self._ctx, self.state)
        self.enterRule(localctx, 34, self.RULE_measure)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 277
            self.match(QuilParser.MEASURE)
            self.state = 278
            self.qubit()
            self.state = 280
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.IDENTIFIER or _la==QuilParser.LBRACKET:
                self.state = 279
                self.addr()


        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class AddrContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def LBRACKET(self):
            return self.getToken(QuilParser.LBRACKET, 0)

        def INT(self):
            return self.getToken(QuilParser.INT, 0)

        def RBRACKET(self):
            return self.getToken(QuilParser.RBRACKET, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_addr

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterAddr" ):
                listener.enterAddr(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitAddr" ):
                listener.exitAddr(self)




    def addr(self):

        localctx = QuilParser.AddrContext(self, self._ctx, self.state)
        self.enterRule(localctx, 36, self.RULE_addr)
        self._la = 0 # Token type
        try:
            self.state = 289
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,24,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 282
                self.match(QuilParser.IDENTIFIER)
                pass

            elif la_ == 2:
                self.enterOuterAlt(localctx, 2)
                self.state = 284
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                if _la==QuilParser.IDENTIFIER:
                    self.state = 283
                    self.match(QuilParser.IDENTIFIER)


                self.state = 286
                self.match(QuilParser.LBRACKET)
                self.state = 287
                self.match(QuilParser.INT)
                self.state = 288
                self.match(QuilParser.RBRACKET)
                pass


        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class DefLabelContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def LABEL(self):
            return self.getToken(QuilParser.LABEL, 0)

        def label(self):
            return self.getTypedRuleContext(QuilParser.LabelContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_defLabel

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterDefLabel" ):
                listener.enterDefLabel(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitDefLabel" ):
                listener.exitDefLabel(self)




    def defLabel(self):

        localctx = QuilParser.DefLabelContext(self, self._ctx, self.state)
        self.enterRule(localctx, 38, self.RULE_defLabel)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 291
            self.match(QuilParser.LABEL)
            self.state = 292
            self.label()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class LabelContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def AT(self):
            return self.getToken(QuilParser.AT, 0)

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_label

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterLabel" ):
                listener.enterLabel(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitLabel" ):
                listener.exitLabel(self)




    def label(self):

        localctx = QuilParser.LabelContext(self, self._ctx, self.state)
        self.enterRule(localctx, 40, self.RULE_label)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 294
            self.match(QuilParser.AT)
            self.state = 295
            self.match(QuilParser.IDENTIFIER)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class HaltContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def HALT(self):
            return self.getToken(QuilParser.HALT, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_halt

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterHalt" ):
                listener.enterHalt(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitHalt" ):
                listener.exitHalt(self)




    def halt(self):

        localctx = QuilParser.HaltContext(self, self._ctx, self.state)
        self.enterRule(localctx, 42, self.RULE_halt)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 297
            self.match(QuilParser.HALT)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class JumpContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def JUMP(self):
            return self.getToken(QuilParser.JUMP, 0)

        def label(self):
            return self.getTypedRuleContext(QuilParser.LabelContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_jump

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterJump" ):
                listener.enterJump(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitJump" ):
                listener.exitJump(self)




    def jump(self):

        localctx = QuilParser.JumpContext(self, self._ctx, self.state)
        self.enterRule(localctx, 44, self.RULE_jump)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 299
            self.match(QuilParser.JUMP)
            self.state = 300
            self.label()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class JumpWhenContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def JUMPWHEN(self):
            return self.getToken(QuilParser.JUMPWHEN, 0)

        def label(self):
            return self.getTypedRuleContext(QuilParser.LabelContext,0)


        def addr(self):
            return self.getTypedRuleContext(QuilParser.AddrContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_jumpWhen

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterJumpWhen" ):
                listener.enterJumpWhen(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitJumpWhen" ):
                listener.exitJumpWhen(self)




    def jumpWhen(self):

        localctx = QuilParser.JumpWhenContext(self, self._ctx, self.state)
        self.enterRule(localctx, 46, self.RULE_jumpWhen)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 302
            self.match(QuilParser.JUMPWHEN)
            self.state = 303
            self.label()
            self.state = 304
            self.addr()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class JumpUnlessContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def JUMPUNLESS(self):
            return self.getToken(QuilParser.JUMPUNLESS, 0)

        def label(self):
            return self.getTypedRuleContext(QuilParser.LabelContext,0)


        def addr(self):
            return self.getTypedRuleContext(QuilParser.AddrContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_jumpUnless

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterJumpUnless" ):
                listener.enterJumpUnless(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitJumpUnless" ):
                listener.exitJumpUnless(self)




    def jumpUnless(self):

        localctx = QuilParser.JumpUnlessContext(self, self._ctx, self.state)
        self.enterRule(localctx, 48, self.RULE_jumpUnless)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 306
            self.match(QuilParser.JUMPUNLESS)
            self.state = 307
            self.label()
            self.state = 308
            self.addr()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ResetStateContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def RESET(self):
            return self.getToken(QuilParser.RESET, 0)

        def qubit(self):
            return self.getTypedRuleContext(QuilParser.QubitContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_resetState

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterResetState" ):
                listener.enterResetState(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitResetState" ):
                listener.exitResetState(self)




    def resetState(self):

        localctx = QuilParser.ResetStateContext(self, self._ctx, self.state)
        self.enterRule(localctx, 50, self.RULE_resetState)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 310
            self.match(QuilParser.RESET)
            self.state = 312
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.INT:
                self.state = 311
                self.qubit()


        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class WaitContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def WAIT(self):
            return self.getToken(QuilParser.WAIT, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_wait

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterWait" ):
                listener.enterWait(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitWait" ):
                listener.exitWait(self)




    def wait(self):

        localctx = QuilParser.WaitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 52, self.RULE_wait)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 314
            self.match(QuilParser.WAIT)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class MemoryDescriptorContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def DECLARE(self):
            return self.getToken(QuilParser.DECLARE, 0)

        def IDENTIFIER(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.IDENTIFIER)
            else:
                return self.getToken(QuilParser.IDENTIFIER, i)

        def LBRACKET(self):
            return self.getToken(QuilParser.LBRACKET, 0)

        def INT(self):
            return self.getToken(QuilParser.INT, 0)

        def RBRACKET(self):
            return self.getToken(QuilParser.RBRACKET, 0)

        def SHARING(self):
            return self.getToken(QuilParser.SHARING, 0)

        def offsetDescriptor(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.OffsetDescriptorContext)
            else:
                return self.getTypedRuleContext(QuilParser.OffsetDescriptorContext,i)


        def getRuleIndex(self):
            return QuilParser.RULE_memoryDescriptor

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterMemoryDescriptor" ):
                listener.enterMemoryDescriptor(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitMemoryDescriptor" ):
                listener.exitMemoryDescriptor(self)




    def memoryDescriptor(self):

        localctx = QuilParser.MemoryDescriptorContext(self, self._ctx, self.state)
        self.enterRule(localctx, 54, self.RULE_memoryDescriptor)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 316
            self.match(QuilParser.DECLARE)
            self.state = 317
            self.match(QuilParser.IDENTIFIER)
            self.state = 318
            self.match(QuilParser.IDENTIFIER)
            self.state = 322
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LBRACKET:
                self.state = 319
                self.match(QuilParser.LBRACKET)
                self.state = 320
                self.match(QuilParser.INT)
                self.state = 321
                self.match(QuilParser.RBRACKET)


            self.state = 332
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.SHARING:
                self.state = 324
                self.match(QuilParser.SHARING)
                self.state = 325
                self.match(QuilParser.IDENTIFIER)
                self.state = 329
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.OFFSET:
                    self.state = 326
                    self.offsetDescriptor()
                    self.state = 331
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)



        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class OffsetDescriptorContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def OFFSET(self):
            return self.getToken(QuilParser.OFFSET, 0)

        def INT(self):
            return self.getToken(QuilParser.INT, 0)

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_offsetDescriptor

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterOffsetDescriptor" ):
                listener.enterOffsetDescriptor(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitOffsetDescriptor" ):
                listener.exitOffsetDescriptor(self)




    def offsetDescriptor(self):

        localctx = QuilParser.OffsetDescriptorContext(self, self._ctx, self.state)
        self.enterRule(localctx, 56, self.RULE_offsetDescriptor)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 334
            self.match(QuilParser.OFFSET)
            self.state = 335
            self.match(QuilParser.INT)
            self.state = 336
            self.match(QuilParser.IDENTIFIER)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ClassicalUnaryContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def addr(self):
            return self.getTypedRuleContext(QuilParser.AddrContext,0)


        def NEG(self):
            return self.getToken(QuilParser.NEG, 0)

        def NOT(self):
            return self.getToken(QuilParser.NOT, 0)

        def TRUE(self):
            return self.getToken(QuilParser.TRUE, 0)

        def FALSE(self):
            return self.getToken(QuilParser.FALSE, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_classicalUnary

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterClassicalUnary" ):
                listener.enterClassicalUnary(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitClassicalUnary" ):
                listener.exitClassicalUnary(self)




    def classicalUnary(self):

        localctx = QuilParser.ClassicalUnaryContext(self, self._ctx, self.state)
        self.enterRule(localctx, 58, self.RULE_classicalUnary)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 338
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.NEG) | (1 << QuilParser.NOT) | (1 << QuilParser.TRUE) | (1 << QuilParser.FALSE))) != 0)):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
            self.state = 339
            self.addr()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ClassicalBinaryContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def logicalBinaryOp(self):
            return self.getTypedRuleContext(QuilParser.LogicalBinaryOpContext,0)


        def arithmeticBinaryOp(self):
            return self.getTypedRuleContext(QuilParser.ArithmeticBinaryOpContext,0)


        def move(self):
            return self.getTypedRuleContext(QuilParser.MoveContext,0)


        def exchange(self):
            return self.getTypedRuleContext(QuilParser.ExchangeContext,0)


        def convert(self):
            return self.getTypedRuleContext(QuilParser.ConvertContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_classicalBinary

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterClassicalBinary" ):
                listener.enterClassicalBinary(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitClassicalBinary" ):
                listener.exitClassicalBinary(self)




    def classicalBinary(self):

        localctx = QuilParser.ClassicalBinaryContext(self, self._ctx, self.state)
        self.enterRule(localctx, 60, self.RULE_classicalBinary)
        try:
            self.state = 346
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.AND, QuilParser.IOR, QuilParser.XOR, QuilParser.OR]:
                self.enterOuterAlt(localctx, 1)
                self.state = 341
                self.logicalBinaryOp()
                pass
            elif token in [QuilParser.ADD, QuilParser.SUB, QuilParser.MUL, QuilParser.DIV]:
                self.enterOuterAlt(localctx, 2)
                self.state = 342
                self.arithmeticBinaryOp()
                pass
            elif token in [QuilParser.MOVE]:
                self.enterOuterAlt(localctx, 3)
                self.state = 343
                self.move()
                pass
            elif token in [QuilParser.EXCHANGE]:
                self.enterOuterAlt(localctx, 4)
                self.state = 344
                self.exchange()
                pass
            elif token in [QuilParser.CONVERT]:
                self.enterOuterAlt(localctx, 5)
                self.state = 345
                self.convert()
                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 LogicalBinaryOpContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def AND(self):
            return self.getToken(QuilParser.AND, 0)

        def OR(self):
            return self.getToken(QuilParser.OR, 0)

        def IOR(self):
            return self.getToken(QuilParser.IOR, 0)

        def XOR(self):
            return self.getToken(QuilParser.XOR, 0)

        def INT(self):
            return self.getToken(QuilParser.INT, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_logicalBinaryOp

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterLogicalBinaryOp" ):
                listener.enterLogicalBinaryOp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitLogicalBinaryOp" ):
                listener.exitLogicalBinaryOp(self)




    def logicalBinaryOp(self):

        localctx = QuilParser.LogicalBinaryOpContext(self, self._ctx, self.state)
        self.enterRule(localctx, 62, self.RULE_logicalBinaryOp)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 348
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.AND) | (1 << QuilParser.IOR) | (1 << QuilParser.XOR) | (1 << QuilParser.OR))) != 0)):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
            self.state = 349
            self.addr()
            self.state = 352
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER, QuilParser.LBRACKET]:
                self.state = 350
                self.addr()
                pass
            elif token in [QuilParser.INT]:
                self.state = 351
                self.match(QuilParser.INT)
                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 ArithmeticBinaryOpContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def ADD(self):
            return self.getToken(QuilParser.ADD, 0)

        def SUB(self):
            return self.getToken(QuilParser.SUB, 0)

        def MUL(self):
            return self.getToken(QuilParser.MUL, 0)

        def DIV(self):
            return self.getToken(QuilParser.DIV, 0)

        def number(self):
            return self.getTypedRuleContext(QuilParser.NumberContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_arithmeticBinaryOp

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterArithmeticBinaryOp" ):
                listener.enterArithmeticBinaryOp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitArithmeticBinaryOp" ):
                listener.exitArithmeticBinaryOp(self)




    def arithmeticBinaryOp(self):

        localctx = QuilParser.ArithmeticBinaryOpContext(self, self._ctx, self.state)
        self.enterRule(localctx, 64, self.RULE_arithmeticBinaryOp)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 354
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.ADD) | (1 << QuilParser.SUB) | (1 << QuilParser.MUL) | (1 << QuilParser.DIV))) != 0)):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
            self.state = 355
            self.addr()
            self.state = 358
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER, QuilParser.LBRACKET]:
                self.state = 356
                self.addr()
                pass
            elif token in [QuilParser.PI, QuilParser.I, QuilParser.INT, QuilParser.FLOAT]:
                self.state = 357
                self.number()
                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 MoveContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def MOVE(self):
            return self.getToken(QuilParser.MOVE, 0)

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def number(self):
            return self.getTypedRuleContext(QuilParser.NumberContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_move

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterMove" ):
                listener.enterMove(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitMove" ):
                listener.exitMove(self)




    def move(self):

        localctx = QuilParser.MoveContext(self, self._ctx, self.state)
        self.enterRule(localctx, 66, self.RULE_move)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 360
            self.match(QuilParser.MOVE)
            self.state = 361
            self.addr()
            self.state = 364
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER, QuilParser.LBRACKET]:
                self.state = 362
                self.addr()
                pass
            elif token in [QuilParser.PI, QuilParser.I, QuilParser.INT, QuilParser.FLOAT]:
                self.state = 363
                self.number()
                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 ExchangeContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def EXCHANGE(self):
            return self.getToken(QuilParser.EXCHANGE, 0)

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def getRuleIndex(self):
            return QuilParser.RULE_exchange

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterExchange" ):
                listener.enterExchange(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitExchange" ):
                listener.exitExchange(self)




    def exchange(self):

        localctx = QuilParser.ExchangeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 68, self.RULE_exchange)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 366
            self.match(QuilParser.EXCHANGE)
            self.state = 367
            self.addr()
            self.state = 368
            self.addr()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ConvertContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def CONVERT(self):
            return self.getToken(QuilParser.CONVERT, 0)

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def getRuleIndex(self):
            return QuilParser.RULE_convert

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterConvert" ):
                listener.enterConvert(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitConvert" ):
                listener.exitConvert(self)




    def convert(self):

        localctx = QuilParser.ConvertContext(self, self._ctx, self.state)
        self.enterRule(localctx, 70, self.RULE_convert)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 370
            self.match(QuilParser.CONVERT)
            self.state = 371
            self.addr()
            self.state = 372
            self.addr()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class LoadContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def LOAD(self):
            return self.getToken(QuilParser.LOAD, 0)

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_load

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterLoad" ):
                listener.enterLoad(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitLoad" ):
                listener.exitLoad(self)




    def load(self):

        localctx = QuilParser.LoadContext(self, self._ctx, self.state)
        self.enterRule(localctx, 72, self.RULE_load)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 374
            self.match(QuilParser.LOAD)
            self.state = 375
            self.addr()
            self.state = 376
            self.match(QuilParser.IDENTIFIER)
            self.state = 377
            self.addr()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class StoreContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def STORE(self):
            return self.getToken(QuilParser.STORE, 0)

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def number(self):
            return self.getTypedRuleContext(QuilParser.NumberContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_store

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterStore" ):
                listener.enterStore(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitStore" ):
                listener.exitStore(self)




    def store(self):

        localctx = QuilParser.StoreContext(self, self._ctx, self.state)
        self.enterRule(localctx, 74, self.RULE_store)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 379
            self.match(QuilParser.STORE)
            self.state = 380
            self.match(QuilParser.IDENTIFIER)
            self.state = 381
            self.addr()
            self.state = 384
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER, QuilParser.LBRACKET]:
                self.state = 382
                self.addr()
                pass
            elif token in [QuilParser.PI, QuilParser.I, QuilParser.INT, QuilParser.FLOAT]:
                self.state = 383
                self.number()
                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 ClassicalComparisonContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def addr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AddrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AddrContext,i)


        def EQ(self):
            return self.getToken(QuilParser.EQ, 0)

        def GT(self):
            return self.getToken(QuilParser.GT, 0)

        def GE(self):
            return self.getToken(QuilParser.GE, 0)

        def LT(self):
            return self.getToken(QuilParser.LT, 0)

        def LE(self):
            return self.getToken(QuilParser.LE, 0)

        def number(self):
            return self.getTypedRuleContext(QuilParser.NumberContext,0)


        def getRuleIndex(self):
            return QuilParser.RULE_classicalComparison

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterClassicalComparison" ):
                listener.enterClassicalComparison(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitClassicalComparison" ):
                listener.exitClassicalComparison(self)




    def classicalComparison(self):

        localctx = QuilParser.ClassicalComparisonContext(self, self._ctx, self.state)
        self.enterRule(localctx, 76, self.RULE_classicalComparison)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 386
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.EQ) | (1 << QuilParser.GT) | (1 << QuilParser.GE) | (1 << QuilParser.LT) | (1 << QuilParser.LE))) != 0)):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
            self.state = 387
            self.addr()
            self.state = 388
            self.addr()
            self.state = 391
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER, QuilParser.LBRACKET]:
                self.state = 389
                self.addr()
                pass
            elif token in [QuilParser.PI, QuilParser.I, QuilParser.INT, QuilParser.FLOAT]:
                self.state = 390
                self.number()
                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 NopContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def NOP(self):
            return self.getToken(QuilParser.NOP, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_nop

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterNop" ):
                listener.enterNop(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitNop" ):
                listener.exitNop(self)




    def nop(self):

        localctx = QuilParser.NopContext(self, self._ctx, self.state)
        self.enterRule(localctx, 78, self.RULE_nop)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 393
            self.match(QuilParser.NOP)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class IncludeContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def INCLUDE(self):
            return self.getToken(QuilParser.INCLUDE, 0)

        def STRING(self):
            return self.getToken(QuilParser.STRING, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_include

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterInclude" ):
                listener.enterInclude(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitInclude" ):
                listener.exitInclude(self)




    def include(self):

        localctx = QuilParser.IncludeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 80, self.RULE_include)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 395
            self.match(QuilParser.INCLUDE)
            self.state = 396
            self.match(QuilParser.STRING)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class PragmaContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def PRAGMA(self):
            return self.getToken(QuilParser.PRAGMA, 0)

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def pragma_name(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.Pragma_nameContext)
            else:
                return self.getTypedRuleContext(QuilParser.Pragma_nameContext,i)


        def STRING(self):
            return self.getToken(QuilParser.STRING, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_pragma

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterPragma" ):
                listener.enterPragma(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitPragma" ):
                listener.exitPragma(self)




    def pragma(self):

        localctx = QuilParser.PragmaContext(self, self._ctx, self.state)
        self.enterRule(localctx, 82, self.RULE_pragma)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 398
            self.match(QuilParser.PRAGMA)
            self.state = 399
            self.match(QuilParser.IDENTIFIER)
            self.state = 403
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.IDENTIFIER or _la==QuilParser.INT:
                self.state = 400
                self.pragma_name()
                self.state = 405
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 407
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.STRING:
                self.state = 406
                self.match(QuilParser.STRING)


        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class Pragma_nameContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def IDENTIFIER(self):
            return self.getToken(QuilParser.IDENTIFIER, 0)

        def INT(self):
            return self.getToken(QuilParser.INT, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_pragma_name

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterPragma_name" ):
                listener.enterPragma_name(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitPragma_name" ):
                listener.exitPragma_name(self)




    def pragma_name(self):

        localctx = QuilParser.Pragma_nameContext(self, self._ctx, self.state)
        self.enterRule(localctx, 84, self.RULE_pragma_name)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 409
            _la = self._input.LA(1)
            if not(_la==QuilParser.IDENTIFIER or _la==QuilParser.INT):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ExpressionContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser


        def getRuleIndex(self):
            return QuilParser.RULE_expression

     
        def copyFrom(self, ctx:ParserRuleContext):
            super().copyFrom(ctx)


    class NumberExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def number(self):
            return self.getTypedRuleContext(QuilParser.NumberContext,0)


        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterNumberExp" ):
                listener.enterNumberExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitNumberExp" ):
                listener.exitNumberExp(self)


    class PowerExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def expression(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.ExpressionContext)
            else:
                return self.getTypedRuleContext(QuilParser.ExpressionContext,i)

        def POWER(self):
            return self.getToken(QuilParser.POWER, 0)

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterPowerExp" ):
                listener.enterPowerExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitPowerExp" ):
                listener.exitPowerExp(self)


    class MulDivExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def expression(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.ExpressionContext)
            else:
                return self.getTypedRuleContext(QuilParser.ExpressionContext,i)

        def TIMES(self):
            return self.getToken(QuilParser.TIMES, 0)
        def DIVIDE(self):
            return self.getToken(QuilParser.DIVIDE, 0)

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterMulDivExp" ):
                listener.enterMulDivExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitMulDivExp" ):
                listener.exitMulDivExp(self)


    class ParenthesisExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def LPAREN(self):
            return self.getToken(QuilParser.LPAREN, 0)
        def expression(self):
            return self.getTypedRuleContext(QuilParser.ExpressionContext,0)

        def RPAREN(self):
            return self.getToken(QuilParser.RPAREN, 0)

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterParenthesisExp" ):
                listener.enterParenthesisExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitParenthesisExp" ):
                listener.exitParenthesisExp(self)


    class VariableExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def variable(self):
            return self.getTypedRuleContext(QuilParser.VariableContext,0)


        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterVariableExp" ):
                listener.enterVariableExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitVariableExp" ):
                listener.exitVariableExp(self)


    class AddrExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def addr(self):
            return self.getTypedRuleContext(QuilParser.AddrContext,0)


        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterAddrExp" ):
                listener.enterAddrExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitAddrExp" ):
                listener.exitAddrExp(self)


    class SignedExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def sign(self):
            return self.getTypedRuleContext(QuilParser.SignContext,0)

        def expression(self):
            return self.getTypedRuleContext(QuilParser.ExpressionContext,0)


        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterSignedExp" ):
                listener.enterSignedExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitSignedExp" ):
                listener.exitSignedExp(self)


    class AddSubExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def expression(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.ExpressionContext)
            else:
                return self.getTypedRuleContext(QuilParser.ExpressionContext,i)

        def PLUS(self):
            return self.getToken(QuilParser.PLUS, 0)
        def MINUS(self):
            return self.getToken(QuilParser.MINUS, 0)

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterAddSubExp" ):
                listener.enterAddSubExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitAddSubExp" ):
                listener.exitAddSubExp(self)


    class FunctionExpContext(ExpressionContext):

        def __init__(self, parser, ctx:ParserRuleContext): # actually a QuilParser.ExpressionContext
            super().__init__(parser)
            self.copyFrom(ctx)

        def function(self):
            return self.getTypedRuleContext(QuilParser.FunctionContext,0)

        def LPAREN(self):
            return self.getToken(QuilParser.LPAREN, 0)
        def expression(self):
            return self.getTypedRuleContext(QuilParser.ExpressionContext,0)

        def RPAREN(self):
            return self.getToken(QuilParser.RPAREN, 0)

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterFunctionExp" ):
                listener.enterFunctionExp(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitFunctionExp" ):
                listener.exitFunctionExp(self)



    def expression(self, _p:int=0):
        _parentctx = self._ctx
        _parentState = self.state
        localctx = QuilParser.ExpressionContext(self, self._ctx, _parentState)
        _prevctx = localctx
        _startState = 86
        self.enterRecursionRule(localctx, 86, self.RULE_expression, _p)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 427
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.LPAREN]:
                localctx = QuilParser.ParenthesisExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx

                self.state = 412
                self.match(QuilParser.LPAREN)
                self.state = 413
                self.expression(0)
                self.state = 414
                self.match(QuilParser.RPAREN)
                pass
            elif token in [QuilParser.PLUS, QuilParser.MINUS]:
                localctx = QuilParser.SignedExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 416
                self.sign()
                self.state = 417
                self.expression(8)
                pass
            elif token in [QuilParser.SIN, QuilParser.COS, QuilParser.SQRT, QuilParser.EXP, QuilParser.CIS]:
                localctx = QuilParser.FunctionExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 419
                self.function()
                self.state = 420
                self.match(QuilParser.LPAREN)
                self.state = 421
                self.expression(0)
                self.state = 422
                self.match(QuilParser.RPAREN)
                pass
            elif token in [QuilParser.PI, QuilParser.I, QuilParser.INT, QuilParser.FLOAT]:
                localctx = QuilParser.NumberExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 424
                self.number()
                pass
            elif token in [QuilParser.PERCENTAGE]:
                localctx = QuilParser.VariableExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 425
                self.variable()
                pass
            elif token in [QuilParser.IDENTIFIER, QuilParser.LBRACKET]:
                localctx = QuilParser.AddrExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 426
                self.addr()
                pass
            else:
                raise NoViableAltException(self)

            self._ctx.stop = self._input.LT(-1)
            self.state = 440
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,39,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 = 438
                    self._errHandler.sync(self)
                    la_ = self._interp.adaptivePredict(self._input,38,self._ctx)
                    if la_ == 1:
                        localctx = QuilParser.PowerExpContext(self, QuilParser.ExpressionContext(self, _parentctx, _parentState))
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expression)
                        self.state = 429
                        if not self.precpred(self._ctx, 7):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 7)")
                        self.state = 430
                        self.match(QuilParser.POWER)
                        self.state = 431
                        self.expression(7)
                        pass

                    elif la_ == 2:
                        localctx = QuilParser.MulDivExpContext(self, QuilParser.ExpressionContext(self, _parentctx, _parentState))
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expression)
                        self.state = 432
                        if not self.precpred(self._ctx, 6):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 6)")
                        self.state = 433
                        _la = self._input.LA(1)
                        if not(_la==QuilParser.TIMES or _la==QuilParser.DIVIDE):
                            self._errHandler.recoverInline(self)
                        else:
                            self._errHandler.reportMatch(self)
                            self.consume()
                        self.state = 434
                        self.expression(7)
                        pass

                    elif la_ == 3:
                        localctx = QuilParser.AddSubExpContext(self, QuilParser.ExpressionContext(self, _parentctx, _parentState))
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expression)
                        self.state = 435
                        if not self.precpred(self._ctx, 5):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 5)")
                        self.state = 436
                        _la = self._input.LA(1)
                        if not(_la==QuilParser.PLUS or _la==QuilParser.MINUS):
                            self._errHandler.recoverInline(self)
                        else:
                            self._errHandler.reportMatch(self)
                            self.consume()
                        self.state = 437
                        self.expression(6)
                        pass

             
                self.state = 442
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,39,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 FunctionContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def SIN(self):
            return self.getToken(QuilParser.SIN, 0)

        def COS(self):
            return self.getToken(QuilParser.COS, 0)

        def SQRT(self):
            return self.getToken(QuilParser.SQRT, 0)

        def EXP(self):
            return self.getToken(QuilParser.EXP, 0)

        def CIS(self):
            return self.getToken(QuilParser.CIS, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_function

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterFunction" ):
                listener.enterFunction(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitFunction" ):
                listener.exitFunction(self)




    def function(self):

        localctx = QuilParser.FunctionContext(self, self._ctx, self.state)
        self.enterRule(localctx, 88, self.RULE_function)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 443
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.SIN) | (1 << QuilParser.COS) | (1 << QuilParser.SQRT) | (1 << QuilParser.EXP) | (1 << QuilParser.CIS))) != 0)):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class SignContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def PLUS(self):
            return self.getToken(QuilParser.PLUS, 0)

        def MINUS(self):
            return self.getToken(QuilParser.MINUS, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_sign

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterSign" ):
                listener.enterSign(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitSign" ):
                listener.exitSign(self)




    def sign(self):

        localctx = QuilParser.SignContext(self, self._ctx, self.state)
        self.enterRule(localctx, 90, self.RULE_sign)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 445
            _la = self._input.LA(1)
            if not(_la==QuilParser.PLUS or _la==QuilParser.MINUS):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class NumberContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def realN(self):
            return self.getTypedRuleContext(QuilParser.RealNContext,0)


        def imaginaryN(self):
            return self.getTypedRuleContext(QuilParser.ImaginaryNContext,0)


        def I(self):
            return self.getToken(QuilParser.I, 0)

        def PI(self):
            return self.getToken(QuilParser.PI, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_number

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterNumber" ):
                listener.enterNumber(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitNumber" ):
                listener.exitNumber(self)




    def number(self):

        localctx = QuilParser.NumberContext(self, self._ctx, self.state)
        self.enterRule(localctx, 92, self.RULE_number)
        try:
            self.state = 451
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,40,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 447
                self.realN()
                pass

            elif la_ == 2:
                self.enterOuterAlt(localctx, 2)
                self.state = 448
                self.imaginaryN()
                pass

            elif la_ == 3:
                self.enterOuterAlt(localctx, 3)
                self.state = 449
                self.match(QuilParser.I)
                pass

            elif la_ == 4:
                self.enterOuterAlt(localctx, 4)
                self.state = 450
                self.match(QuilParser.PI)
                pass


        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ImaginaryNContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def realN(self):
            return self.getTypedRuleContext(QuilParser.RealNContext,0)


        def I(self):
            return self.getToken(QuilParser.I, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_imaginaryN

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterImaginaryN" ):
                listener.enterImaginaryN(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitImaginaryN" ):
                listener.exitImaginaryN(self)




    def imaginaryN(self):

        localctx = QuilParser.ImaginaryNContext(self, self._ctx, self.state)
        self.enterRule(localctx, 94, self.RULE_imaginaryN)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 453
            self.realN()
            self.state = 454
            self.match(QuilParser.I)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class RealNContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def FLOAT(self):
            return self.getToken(QuilParser.FLOAT, 0)

        def INT(self):
            return self.getToken(QuilParser.INT, 0)

        def getRuleIndex(self):
            return QuilParser.RULE_realN

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterRealN" ):
                listener.enterRealN(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitRealN" ):
                listener.exitRealN(self)




    def realN(self):

        localctx = QuilParser.RealNContext(self, self._ctx, self.state)
        self.enterRule(localctx, 96, self.RULE_realN)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 456
            _la = self._input.LA(1)
            if not(_la==QuilParser.INT or _la==QuilParser.FLOAT):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx



    def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int):
        if self._predicates == None:
            self._predicates = dict()
        self._predicates[43] = self.expression_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 expression_sempred(self, localctx:ExpressionContext, predIndex:int):
            if predIndex == 0:
                return self.precpred(self._ctx, 7)
         

            if predIndex == 1:
                return self.precpred(self._ctx, 6)
         

            if predIndex == 2:
                return self.precpred(self._ctx, 5)
         




