# Generated from Quil.g4 by ANTLR 4.7
# encoding: utf-8
from __future__ import print_function
from antlr4 import *
from io import StringIO
import sys

def serializedATN():
    with StringIO() as buf:
        buf.write(u"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3")
        buf.write(u"\66\u017a\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7")
        buf.write(u"\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t")
        buf.write(u"\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22")
        buf.write(u"\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4")
        buf.write(u"\30\t\30\4\31\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35")
        buf.write(u"\t\35\4\36\t\36\4\37\t\37\4 \t \4!\t!\4\"\t\"\4#\t#\4")
        buf.write(u"$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\3\2\5\2V\n")
        buf.write(u"\2\3\2\6\2Y\n\2\r\2\16\2Z\3\2\7\2^\n\2\f\2\16\2a\13\2")
        buf.write(u"\3\2\7\2d\n\2\f\2\16\2g\13\2\3\2\3\2\3\3\3\3\3\3\5\3")
        buf.write(u"n\n\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4")
        buf.write(u"\3\4\3\4\5\4~\n\4\3\5\3\5\3\5\3\5\3\5\7\5\u0085\n\5\f")
        buf.write(u"\5\16\5\u0088\13\5\3\5\3\5\5\5\u008c\n\5\3\5\6\5\u008f")
        buf.write(u"\n\5\r\5\16\5\u0090\3\6\3\6\3\7\3\7\3\b\3\b\5\b\u0099")
        buf.write(u"\n\b\3\t\3\t\3\t\3\t\5\t\u009f\n\t\3\t\3\t\3\n\3\n\3")
        buf.write(u"\n\3\n\3\n\3\n\7\n\u00a9\n\n\f\n\16\n\u00ac\13\n\3\n")
        buf.write(u"\3\n\5\n\u00b0\n\n\3\n\3\n\3\n\3\n\3\13\3\13\3\13\3\f")
        buf.write(u"\3\f\3\f\7\f\u00bc\n\f\f\f\16\f\u00bf\13\f\3\f\3\f\3")
        buf.write(u"\r\3\r\3\r\3\r\7\r\u00c7\n\r\f\r\16\r\u00ca\13\r\3\16")
        buf.write(u"\3\16\3\16\3\16\3\16\3\16\7\16\u00d2\n\16\f\16\16\16")
        buf.write(u"\u00d5\13\16\3\16\3\16\5\16\u00d9\n\16\3\16\7\16\u00dc")
        buf.write(u"\n\16\f\16\16\16\u00df\13\16\3\16\3\16\3\16\3\16\3\17")
        buf.write(u"\3\17\3\20\3\20\5\20\u00e9\n\20\3\21\3\21\3\21\3\21\3")
        buf.write(u"\21\7\21\u00f0\n\21\f\21\16\21\u00f3\13\21\3\21\3\21")
        buf.write(u"\5\21\u00f7\n\21\3\21\6\21\u00fa\n\21\r\21\16\21\u00fb")
        buf.write(u"\3\22\3\22\5\22\u0100\n\22\3\23\3\23\3\23\3\23\7\23\u0106")
        buf.write(u"\n\23\f\23\16\23\u0109\13\23\3\23\3\23\3\23\3\24\3\24")
        buf.write(u"\3\24\5\24\u0111\n\24\3\25\3\25\3\25\3\25\3\26\6\26\u0118")
        buf.write(u"\n\26\r\26\16\26\u0119\3\27\3\27\3\27\3\30\3\30\3\30")
        buf.write(u"\3\31\3\31\3\32\3\32\3\32\3\33\3\33\3\33\3\33\3\34\3")
        buf.write(u"\34\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3\37\3\37\3 \3")
        buf.write(u" \3 \3 \3!\3!\3\"\3\"\3\"\3#\3#\3#\7#\u0142\n#\f#\16")
        buf.write(u"#\u0145\13#\3#\5#\u0148\n#\3$\3$\3%\3%\3%\3%\3%\3%\3")
        buf.write(u"%\3%\3%\3%\3%\3%\3%\3%\3%\5%\u015b\n%\3%\3%\3%\3%\3%")
        buf.write(u"\3%\3%\3%\3%\7%\u0166\n%\f%\16%\u0169\13%\3&\3&\3\'\3")
        buf.write(u"\'\3(\3(\3(\3(\5(\u0173\n(\3)\3)\3)\3*\3*\3*\2\3H+\2")
        buf.write(u"\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62")
        buf.write(u"\64\668:<>@BDFHJLNPR\2\t\3\2\20\22\3\2\23\26\3\2#$\3")
        buf.write(u"\2 !\3\2\36\37\3\2\31\35\3\2$%\2\u0183\2U\3\2\2\2\4m")
        buf.write(u"\3\2\2\2\6}\3\2\2\2\b\177\3\2\2\2\n\u0092\3\2\2\2\f\u0094")
        buf.write(u"\3\2\2\2\16\u0098\3\2\2\2\20\u009a\3\2\2\2\22\u00a2\3")
        buf.write(u"\2\2\2\24\u00b5\3\2\2\2\26\u00bd\3\2\2\2\30\u00c2\3\2")
        buf.write(u"\2\2\32\u00cb\3\2\2\2\34\u00e4\3\2\2\2\36\u00e8\3\2\2")
        buf.write(u"\2 \u00ea\3\2\2\2\"\u00ff\3\2\2\2$\u0107\3\2\2\2&\u010d")
        buf.write(u"\3\2\2\2(\u0112\3\2\2\2*\u0117\3\2\2\2,\u011b\3\2\2\2")
        buf.write(u".\u011e\3\2\2\2\60\u0121\3\2\2\2\62\u0123\3\2\2\2\64")
        buf.write(u"\u0126\3\2\2\2\66\u012a\3\2\2\28\u012e\3\2\2\2:\u0130")
        buf.write(u"\3\2\2\2<\u0132\3\2\2\2>\u0135\3\2\2\2@\u0139\3\2\2\2")
        buf.write(u"B\u013b\3\2\2\2D\u013e\3\2\2\2F\u0149\3\2\2\2H\u015a")
        buf.write(u"\3\2\2\2J\u016a\3\2\2\2L\u016c\3\2\2\2N\u0172\3\2\2\2")
        buf.write(u"P\u0174\3\2\2\2R\u0177\3\2\2\2TV\5\4\3\2UT\3\2\2\2UV")
        buf.write(u"\3\2\2\2V_\3\2\2\2WY\7\63\2\2XW\3\2\2\2YZ\3\2\2\2ZX\3")
        buf.write(u"\2\2\2Z[\3\2\2\2[\\\3\2\2\2\\^\5\4\3\2]X\3\2\2\2^a\3")
        buf.write(u"\2\2\2_]\3\2\2\2_`\3\2\2\2`e\3\2\2\2a_\3\2\2\2bd\7\63")
        buf.write(u"\2\2cb\3\2\2\2dg\3\2\2\2ec\3\2\2\2ef\3\2\2\2fh\3\2\2")
        buf.write(u"\2ge\3\2\2\2hi\7\2\2\3i\3\3\2\2\2jn\5\22\n\2kn\5\32\16")
        buf.write(u"\2ln\5\6\4\2mj\3\2\2\2mk\3\2\2\2ml\3\2\2\2n\5\3\2\2\2")
        buf.write(u"o~\5\b\5\2p~\5&\24\2q~\5,\27\2r~\5\60\31\2s~\5\62\32")
        buf.write(u"\2t~\5\64\33\2u~\5\66\34\2v~\58\35\2w~\5:\36\2x~\5<\37")
        buf.write(u"\2y~\5> \2z~\5@!\2{~\5B\"\2|~\5D#\2}o\3\2\2\2}p\3\2\2")
        buf.write(u"\2}q\3\2\2\2}r\3\2\2\2}s\3\2\2\2}t\3\2\2\2}u\3\2\2\2")
        buf.write(u"}v\3\2\2\2}w\3\2\2\2}x\3\2\2\2}y\3\2\2\2}z\3\2\2\2}{")
        buf.write(u"\3\2\2\2}|\3\2\2\2~\7\3\2\2\2\177\u008b\5\n\6\2\u0080")
        buf.write(u"\u0081\7)\2\2\u0081\u0086\5\16\b\2\u0082\u0083\7(\2\2")
        buf.write(u"\u0083\u0085\5\16\b\2\u0084\u0082\3\2\2\2\u0085\u0088")
        buf.write(u"\3\2\2\2\u0086\u0084\3\2\2\2\u0086\u0087\3\2\2\2\u0087")
        buf.write(u"\u0089\3\2\2\2\u0088\u0086\3\2\2\2\u0089\u008a\7*\2\2")
        buf.write(u"\u008a\u008c\3\2\2\2\u008b\u0080\3\2\2\2\u008b\u008c")
        buf.write(u"\3\2\2\2\u008c\u008e\3\2\2\2\u008d\u008f\5\f\7\2\u008e")
        buf.write(u"\u008d\3\2\2\2\u008f\u0090\3\2\2\2\u0090\u008e\3\2\2")
        buf.write(u"\2\u0090\u0091\3\2\2\2\u0091\t\3\2\2\2\u0092\u0093\7")
        buf.write(u"#\2\2\u0093\13\3\2\2\2\u0094\u0095\7$\2\2\u0095\r\3\2")
        buf.write(u"\2\2\u0096\u0099\5\20\t\2\u0097\u0099\5H%\2\u0098\u0096")
        buf.write(u"\3\2\2\2\u0098\u0097\3\2\2\2\u0099\17\3\2\2\2\u009a\u009b")
        buf.write(u"\7+\2\2\u009b\u009e\7$\2\2\u009c\u009d\7\37\2\2\u009d")
        buf.write(u"\u009f\7$\2\2\u009e\u009c\3\2\2\2\u009e\u009f\3\2\2\2")
        buf.write(u"\u009f\u00a0\3\2\2\2\u00a0\u00a1\7,\2\2\u00a1\21\3\2")
        buf.write(u"\2\2\u00a2\u00a3\7\3\2\2\u00a3\u00af\5\n\6\2\u00a4\u00a5")
        buf.write(u"\7)\2\2\u00a5\u00aa\5\24\13\2\u00a6\u00a7\7(\2\2\u00a7")
        buf.write(u"\u00a9\5\24\13\2\u00a8\u00a6\3\2\2\2\u00a9\u00ac\3\2")
        buf.write(u"\2\2\u00aa\u00a8\3\2\2\2\u00aa\u00ab\3\2\2\2\u00ab\u00ad")
        buf.write(u"\3\2\2\2\u00ac\u00aa\3\2\2\2\u00ad\u00ae\7*\2\2\u00ae")
        buf.write(u"\u00b0\3\2\2\2\u00af\u00a4\3\2\2\2\u00af\u00b0\3\2\2")
        buf.write(u"\2\u00b0\u00b1\3\2\2\2\u00b1\u00b2\7-\2\2\u00b2\u00b3")
        buf.write(u"\7\63\2\2\u00b3\u00b4\5\26\f\2\u00b4\23\3\2\2\2\u00b5")
        buf.write(u"\u00b6\7.\2\2\u00b6\u00b7\7#\2\2\u00b7\25\3\2\2\2\u00b8")
        buf.write(u"\u00b9\5\30\r\2\u00b9\u00ba\7\63\2\2\u00ba\u00bc\3\2")
        buf.write(u"\2\2\u00bb\u00b8\3\2\2\2\u00bc\u00bf\3\2\2\2\u00bd\u00bb")
        buf.write(u"\3\2\2\2\u00bd\u00be\3\2\2\2\u00be\u00c0\3\2\2\2\u00bf")
        buf.write(u"\u00bd\3\2\2\2\u00c0\u00c1\5\30\r\2\u00c1\27\3\2\2\2")
        buf.write(u"\u00c2\u00c3\7\62\2\2\u00c3\u00c8\5H%\2\u00c4\u00c5\7")
        buf.write(u"(\2\2\u00c5\u00c7\5H%\2\u00c6\u00c4\3\2\2\2\u00c7\u00ca")
        buf.write(u"\3\2\2\2\u00c8\u00c6\3\2\2\2\u00c8\u00c9\3\2\2\2\u00c9")
        buf.write(u"\31\3\2\2\2\u00ca\u00c8\3\2\2\2\u00cb\u00cc\7\4\2\2\u00cc")
        buf.write(u"\u00d8\5\n\6\2\u00cd\u00ce\7)\2\2\u00ce\u00d3\5\24\13")
        buf.write(u"\2\u00cf\u00d0\7(\2\2\u00d0\u00d2\5\24\13\2\u00d1\u00cf")
        buf.write(u"\3\2\2\2\u00d2\u00d5\3\2\2\2\u00d3\u00d1\3\2\2\2\u00d3")
        buf.write(u"\u00d4\3\2\2\2\u00d4\u00d6\3\2\2\2\u00d5\u00d3\3\2\2")
        buf.write(u"\2\u00d6\u00d7\7*\2\2\u00d7\u00d9\3\2\2\2\u00d8\u00cd")
        buf.write(u"\3\2\2\2\u00d8\u00d9\3\2\2\2\u00d9\u00dd\3\2\2\2\u00da")
        buf.write(u"\u00dc\5\34\17\2\u00db\u00da\3\2\2\2\u00dc\u00df\3\2")
        buf.write(u"\2\2\u00dd\u00db\3\2\2\2\u00dd\u00de\3\2\2\2\u00de\u00e0")
        buf.write(u"\3\2\2\2\u00df\u00dd\3\2\2\2\u00e0\u00e1\7-\2\2\u00e1")
        buf.write(u"\u00e2\7\63\2\2\u00e2\u00e3\5$\23\2\u00e3\33\3\2\2\2")
        buf.write(u"\u00e4\u00e5\7#\2\2\u00e5\35\3\2\2\2\u00e6\u00e9\5\f")
        buf.write(u"\7\2\u00e7\u00e9\5\34\17\2\u00e8\u00e6\3\2\2\2\u00e8")
        buf.write(u"\u00e7\3\2\2\2\u00e9\37\3\2\2\2\u00ea\u00f6\5\n\6\2\u00eb")
        buf.write(u"\u00ec\7)\2\2\u00ec\u00f1\5\16\b\2\u00ed\u00ee\7(\2\2")
        buf.write(u"\u00ee\u00f0\5\16\b\2\u00ef\u00ed\3\2\2\2\u00f0\u00f3")
        buf.write(u"\3\2\2\2\u00f1\u00ef\3\2\2\2\u00f1\u00f2\3\2\2\2\u00f2")
        buf.write(u"\u00f4\3\2\2\2\u00f3\u00f1\3\2\2\2\u00f4\u00f5\7*\2\2")
        buf.write(u"\u00f5\u00f7\3\2\2\2\u00f6\u00eb\3\2\2\2\u00f6\u00f7")
        buf.write(u"\3\2\2\2\u00f7\u00f9\3\2\2\2\u00f8\u00fa\5\36\20\2\u00f9")
        buf.write(u"\u00f8\3\2\2\2\u00fa\u00fb\3\2\2\2\u00fb\u00f9\3\2\2")
        buf.write(u"\2\u00fb\u00fc\3\2\2\2\u00fc!\3\2\2\2\u00fd\u0100\5 ")
        buf.write(u"\21\2\u00fe\u0100\5\6\4\2\u00ff\u00fd\3\2\2\2\u00ff\u00fe")
        buf.write(u"\3\2\2\2\u0100#\3\2\2\2\u0101\u0102\7\62\2\2\u0102\u0103")
        buf.write(u"\5\"\22\2\u0103\u0104\7\63\2\2\u0104\u0106\3\2\2\2\u0105")
        buf.write(u"\u0101\3\2\2\2\u0106\u0109\3\2\2\2\u0107\u0105\3\2\2")
        buf.write(u"\2\u0107\u0108\3\2\2\2\u0108\u010a\3\2\2\2\u0109\u0107")
        buf.write(u"\3\2\2\2\u010a\u010b\7\62\2\2\u010b\u010c\5\"\22\2\u010c")
        buf.write(u"%\3\2\2\2\u010d\u010e\7\5\2\2\u010e\u0110\5\f\7\2\u010f")
        buf.write(u"\u0111\5(\25\2\u0110\u010f\3\2\2\2\u0110\u0111\3\2\2")
        buf.write(u"\2\u0111\'\3\2\2\2\u0112\u0113\7+\2\2\u0113\u0114\5*")
        buf.write(u"\26\2\u0114\u0115\7,\2\2\u0115)\3\2\2\2\u0116\u0118\7")
        buf.write(u"$\2\2\u0117\u0116\3\2\2\2\u0118\u0119\3\2\2\2\u0119\u0117")
        buf.write(u"\3\2\2\2\u0119\u011a\3\2\2\2\u011a+\3\2\2\2\u011b\u011c")
        buf.write(u"\7\6\2\2\u011c\u011d\5.\30\2\u011d-\3\2\2\2\u011e\u011f")
        buf.write(u"\7/\2\2\u011f\u0120\7#\2\2\u0120/\3\2\2\2\u0121\u0122")
        buf.write(u"\7\7\2\2\u0122\61\3\2\2\2\u0123\u0124\7\b\2\2\u0124\u0125")
        buf.write(u"\5.\30\2\u0125\63\3\2\2\2\u0126\u0127\7\t\2\2\u0127\u0128")
        buf.write(u"\5.\30\2\u0128\u0129\5(\25\2\u0129\65\3\2\2\2\u012a\u012b")
        buf.write(u"\7\n\2\2\u012b\u012c\5.\30\2\u012c\u012d\5(\25\2\u012d")
        buf.write(u"\67\3\2\2\2\u012e\u012f\7\13\2\2\u012f9\3\2\2\2\u0130")
        buf.write(u"\u0131\7\f\2\2\u0131;\3\2\2\2\u0132\u0133\t\2\2\2\u0133")
        buf.write(u"\u0134\5(\25\2\u0134=\3\2\2\2\u0135\u0136\t\3\2\2\u0136")
        buf.write(u"\u0137\5(\25\2\u0137\u0138\5(\25\2\u0138?\3\2\2\2\u0139")
        buf.write(u"\u013a\7\r\2\2\u013aA\3\2\2\2\u013b\u013c\7\16\2\2\u013c")
        buf.write(u"\u013d\7&\2\2\u013dC\3\2\2\2\u013e\u013f\7\17\2\2\u013f")
        buf.write(u"\u0143\7#\2\2\u0140\u0142\5F$\2\u0141\u0140\3\2\2\2\u0142")
        buf.write(u"\u0145\3\2\2\2\u0143\u0141\3\2\2\2\u0143\u0144\3\2\2")
        buf.write(u"\2\u0144\u0147\3\2\2\2\u0145\u0143\3\2\2\2\u0146\u0148")
        buf.write(u"\7&\2\2\u0147\u0146\3\2\2\2\u0147\u0148\3\2\2\2\u0148")
        buf.write(u"E\3\2\2\2\u0149\u014a\t\4\2\2\u014aG\3\2\2\2\u014b\u014c")
        buf.write(u"\b%\1\2\u014c\u014d\7)\2\2\u014d\u014e\5H%\2\u014e\u014f")
        buf.write(u"\7*\2\2\u014f\u015b\3\2\2\2\u0150\u0151\5L\'\2\u0151")
        buf.write(u"\u0152\5H%\6\u0152\u015b\3\2\2\2\u0153\u0154\5J&\2\u0154")
        buf.write(u"\u0155\7)\2\2\u0155\u0156\5H%\2\u0156\u0157\7*\2\2\u0157")
        buf.write(u"\u015b\3\2\2\2\u0158\u015b\5N(\2\u0159\u015b\5\24\13")
        buf.write(u"\2\u015a\u014b\3\2\2\2\u015a\u0150\3\2\2\2\u015a\u0153")
        buf.write(u"\3\2\2\2\u015a\u0158\3\2\2\2\u015a\u0159\3\2\2\2\u015b")
        buf.write(u"\u0167\3\2\2\2\u015c\u015d\f\t\2\2\u015d\u015e\7\"\2")
        buf.write(u"\2\u015e\u0166\5H%\t\u015f\u0160\f\b\2\2\u0160\u0161")
        buf.write(u"\t\5\2\2\u0161\u0166\5H%\t\u0162\u0163\f\7\2\2\u0163")
        buf.write(u"\u0164\t\6\2\2\u0164\u0166\5H%\b\u0165\u015c\3\2\2\2")
        buf.write(u"\u0165\u015f\3\2\2\2\u0165\u0162\3\2\2\2\u0166\u0169")
        buf.write(u"\3\2\2\2\u0167\u0165\3\2\2\2\u0167\u0168\3\2\2\2\u0168")
        buf.write(u"I\3\2\2\2\u0169\u0167\3\2\2\2\u016a\u016b\t\7\2\2\u016b")
        buf.write(u"K\3\2\2\2\u016c\u016d\t\6\2\2\u016dM\3\2\2\2\u016e\u0173")
        buf.write(u"\5R*\2\u016f\u0173\5P)\2\u0170\u0173\7\30\2\2\u0171\u0173")
        buf.write(u"\7\27\2\2\u0172\u016e\3\2\2\2\u0172\u016f\3\2\2\2\u0172")
        buf.write(u"\u0170\3\2\2\2\u0172\u0171\3\2\2\2\u0173O\3\2\2\2\u0174")
        buf.write(u"\u0175\5R*\2\u0175\u0176\7\30\2\2\u0176Q\3\2\2\2\u0177")
        buf.write(u"\u0178\t\b\2\2\u0178S\3\2\2\2\"UZ_em}\u0086\u008b\u0090")
        buf.write(u"\u0098\u009e\u00aa\u00af\u00bd\u00c8\u00d3\u00d8\u00dd")
        buf.write(u"\u00e8\u00f1\u00f6\u00fb\u00ff\u0107\u0110\u0119\u0143")
        buf.write(u"\u0147\u015a\u0165\u0167\u0172")
        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 = [ u"<INVALID>", u"'DEFGATE'", u"'DEFCIRCUIT'", u"'MEASURE'", 
                     u"'LABEL'", u"'HALT'", u"'JUMP'", u"'JUMP-WHEN'", u"'JUMP-UNLESS'", 
                     u"'RESET'", u"'WAIT'", u"'NOP'", u"'INCLUDE'", u"'PRAGMA'", 
                     u"'FALSE'", u"'TRUE'", u"'NOT'", u"'AND'", u"'OR'", 
                     u"'MOVE'", u"'EXCHANGE'", u"'pi'", u"'i'", u"'sin'", 
                     u"'cos'", u"'sqrt'", u"'exp'", u"'cis'", u"'+'", u"'-'", 
                     u"'*'", u"'/'", u"'^'", u"<INVALID>", u"<INVALID>", 
                     u"<INVALID>", u"<INVALID>", u"'.'", u"','", u"'('", 
                     u"')'", u"'['", u"']'", u"':'", u"'%'", u"'@'", u"'\"'", 
                     u"'_'", u"'    '", u"<INVALID>", u"<INVALID>", u"' '" ]

    symbolicNames = [ u"<INVALID>", u"DEFGATE", u"DEFCIRCUIT", u"MEASURE", 
                      u"LABEL", u"HALT", u"JUMP", u"JUMPWHEN", u"JUMPUNLESS", 
                      u"RESET", u"WAIT", u"NOP", u"INCLUDE", u"PRAGMA", 
                      u"FALSE", u"TRUE", u"NOT", u"AND", u"OR", u"MOVE", 
                      u"EXCHANGE", u"PI", u"I", u"SIN", u"COS", u"SQRT", 
                      u"EXP", u"CIS", u"PLUS", u"MINUS", u"TIMES", u"DIVIDE", 
                      u"POWER", u"IDENTIFIER", u"INT", u"FLOAT", u"STRING", 
                      u"PERIOD", u"COMMA", u"LPAREN", u"RPAREN", u"LBRACKET", 
                      u"RBRACKET", u"COLON", u"PERCENTAGE", u"AT", u"QUOTE", 
                      u"UNDERSCORE", u"TAB", u"NEWLINE", u"COMMENT", u"SPACE", 
                      u"INVALID" ]

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

    ruleNames =  [ u"quil", u"allInstr", u"instr", u"gate", u"name", u"qubit", 
                   u"param", u"dynamicParam", u"defGate", u"variable", u"matrix", 
                   u"matrixRow", u"defCircuit", u"qubitVariable", u"circuitQubit", 
                   u"circuitGate", u"circuitInstr", u"circuit", u"measure", 
                   u"addr", u"classicalBit", u"defLabel", u"label", u"halt", 
                   u"jump", u"jumpWhen", u"jumpUnless", u"resetState", u"wait", 
                   u"classicalUnary", u"classicalBinary", u"nop", u"include", 
                   u"pragma", u"pragma_name", u"expression", u"function", 
                   u"sign", u"number", u"imaginaryN", u"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
    FALSE=14
    TRUE=15
    NOT=16
    AND=17
    OR=18
    MOVE=19
    EXCHANGE=20
    PI=21
    I=22
    SIN=23
    COS=24
    SQRT=25
    EXP=26
    CIS=27
    PLUS=28
    MINUS=29
    TIMES=30
    DIVIDE=31
    POWER=32
    IDENTIFIER=33
    INT=34
    FLOAT=35
    STRING=36
    PERIOD=37
    COMMA=38
    LPAREN=39
    RPAREN=40
    LBRACKET=41
    RBRACKET=42
    COLON=43
    PERCENTAGE=44
    AT=45
    QUOTE=46
    UNDERSCORE=47
    TAB=48
    NEWLINE=49
    COMMENT=50
    SPACE=51
    INVALID=52

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



    class QuilContext(ParserRuleContext):

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

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

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


        def NEWLINE(self, i=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):
            if hasattr(listener, "enterQuil"):
                listener.enterQuil(self)

        def exitRule(self, listener):
            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 = 83
            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.FALSE) | (1 << QuilParser.TRUE) | (1 << QuilParser.NOT) | (1 << QuilParser.AND) | (1 << QuilParser.OR) | (1 << QuilParser.MOVE) | (1 << QuilParser.EXCHANGE) | (1 << QuilParser.IDENTIFIER))) != 0):
                self.state = 82
                self.allInstr()


            self.state = 93
            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 = 86 
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)
                    while True:
                        self.state = 85
                        self.match(QuilParser.NEWLINE)
                        self.state = 88 
                        self._errHandler.sync(self)
                        _la = self._input.LA(1)
                        if not (_la==QuilParser.NEWLINE):
                            break

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

            self.state = 99
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.NEWLINE:
                self.state = 96
                self.match(QuilParser.NEWLINE)
                self.state = 101
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 102
            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=None, invokingState=-1):
            super(QuilParser.AllInstrContext, self).__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):
            if hasattr(listener, "enterAllInstr"):
                listener.enterAllInstr(self)

        def exitRule(self, listener):
            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 = 107
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.DEFGATE]:
                self.enterOuterAlt(localctx, 1)
                self.state = 104
                self.defGate()
                pass
            elif token in [QuilParser.DEFCIRCUIT]:
                self.enterOuterAlt(localctx, 2)
                self.state = 105
                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.FALSE, QuilParser.TRUE, QuilParser.NOT, QuilParser.AND, QuilParser.OR, QuilParser.MOVE, QuilParser.EXCHANGE, QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 3)
                self.state = 106
                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=None, invokingState=-1):
            super(QuilParser.InstrContext, self).__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 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 getRuleIndex(self):
            return QuilParser.RULE_instr

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

        def exitRule(self, listener):
            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 = 123
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 1)
                self.state = 109
                self.gate()
                pass
            elif token in [QuilParser.MEASURE]:
                self.enterOuterAlt(localctx, 2)
                self.state = 110
                self.measure()
                pass
            elif token in [QuilParser.LABEL]:
                self.enterOuterAlt(localctx, 3)
                self.state = 111
                self.defLabel()
                pass
            elif token in [QuilParser.HALT]:
                self.enterOuterAlt(localctx, 4)
                self.state = 112
                self.halt()
                pass
            elif token in [QuilParser.JUMP]:
                self.enterOuterAlt(localctx, 5)
                self.state = 113
                self.jump()
                pass
            elif token in [QuilParser.JUMPWHEN]:
                self.enterOuterAlt(localctx, 6)
                self.state = 114
                self.jumpWhen()
                pass
            elif token in [QuilParser.JUMPUNLESS]:
                self.enterOuterAlt(localctx, 7)
                self.state = 115
                self.jumpUnless()
                pass
            elif token in [QuilParser.RESET]:
                self.enterOuterAlt(localctx, 8)
                self.state = 116
                self.resetState()
                pass
            elif token in [QuilParser.WAIT]:
                self.enterOuterAlt(localctx, 9)
                self.state = 117
                self.wait()
                pass
            elif token in [QuilParser.FALSE, QuilParser.TRUE, QuilParser.NOT]:
                self.enterOuterAlt(localctx, 10)
                self.state = 118
                self.classicalUnary()
                pass
            elif token in [QuilParser.AND, QuilParser.OR, QuilParser.MOVE, QuilParser.EXCHANGE]:
                self.enterOuterAlt(localctx, 11)
                self.state = 119
                self.classicalBinary()
                pass
            elif token in [QuilParser.NOP]:
                self.enterOuterAlt(localctx, 12)
                self.state = 120
                self.nop()
                pass
            elif token in [QuilParser.INCLUDE]:
                self.enterOuterAlt(localctx, 13)
                self.state = 121
                self.include()
                pass
            elif token in [QuilParser.PRAGMA]:
                self.enterOuterAlt(localctx, 14)
                self.state = 122
                self.pragma()
                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=None, invokingState=-1):
            super(QuilParser.GateContext, self).__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=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=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.QubitContext)
            else:
                return self.getTypedRuleContext(QuilParser.QubitContext,i)


        def COMMA(self, i=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):
            if hasattr(listener, "enterGate"):
                listener.enterGate(self)

        def exitRule(self, listener):
            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 = 125
            self.name()
            self.state = 137
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 126
                self.match(QuilParser.LPAREN)
                self.state = 127
                self.param()
                self.state = 132
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 128
                    self.match(QuilParser.COMMA)
                    self.state = 129
                    self.param()
                    self.state = 134
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 140 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 139
                self.qubit()
                self.state = 142 
                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=None, invokingState=-1):
            super(QuilParser.NameContext, self).__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):
            if hasattr(listener, "enterName"):
                listener.enterName(self)

        def exitRule(self, listener):
            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 = 144
            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=None, invokingState=-1):
            super(QuilParser.QubitContext, self).__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):
            if hasattr(listener, "enterQubit"):
                listener.enterQubit(self)

        def exitRule(self, listener):
            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 = 146
            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=None, invokingState=-1):
            super(QuilParser.ParamContext, self).__init__(parent, invokingState)
            self.parser = parser

        def dynamicParam(self):
            return self.getTypedRuleContext(QuilParser.DynamicParamContext,0)


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


        def getRuleIndex(self):
            return QuilParser.RULE_param

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

        def exitRule(self, listener):
            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.state = 150
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.LBRACKET]:
                self.enterOuterAlt(localctx, 1)
                self.state = 148
                self.dynamicParam()
                pass
            elif token in [QuilParser.PI, QuilParser.I, QuilParser.SIN, QuilParser.COS, QuilParser.SQRT, QuilParser.EXP, QuilParser.CIS, QuilParser.PLUS, QuilParser.MINUS, QuilParser.INT, QuilParser.FLOAT, QuilParser.LPAREN, QuilParser.PERCENTAGE]:
                self.enterOuterAlt(localctx, 2)
                self.state = 149
                self.expression(0)
                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 DynamicParamContext(ParserRuleContext):

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

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

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

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

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

        def getRuleIndex(self):
            return QuilParser.RULE_dynamicParam

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

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




    def dynamicParam(self):

        localctx = QuilParser.DynamicParamContext(self, self._ctx, self.state)
        self.enterRule(localctx, 14, self.RULE_dynamicParam)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 152
            self.match(QuilParser.LBRACKET)
            self.state = 153
            self.match(QuilParser.INT)
            self.state = 156
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.MINUS:
                self.state = 154
                self.match(QuilParser.MINUS)
                self.state = 155
                self.match(QuilParser.INT)


            self.state = 158
            self.match(QuilParser.RBRACKET)
        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=None, invokingState=-1):
            super(QuilParser.DefGateContext, self).__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=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=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):
            if hasattr(listener, "enterDefGate"):
                listener.enterDefGate(self)

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




    def defGate(self):

        localctx = QuilParser.DefGateContext(self, self._ctx, self.state)
        self.enterRule(localctx, 16, self.RULE_defGate)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 160
            self.match(QuilParser.DEFGATE)
            self.state = 161
            self.name()
            self.state = 173
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 162
                self.match(QuilParser.LPAREN)
                self.state = 163
                self.variable()
                self.state = 168
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 164
                    self.match(QuilParser.COMMA)
                    self.state = 165
                    self.variable()
                    self.state = 170
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 175
            self.match(QuilParser.COLON)
            self.state = 176
            self.match(QuilParser.NEWLINE)
            self.state = 177
            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=None, invokingState=-1):
            super(QuilParser.VariableContext, self).__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):
            if hasattr(listener, "enterVariable"):
                listener.enterVariable(self)

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




    def variable(self):

        localctx = QuilParser.VariableContext(self, self._ctx, self.state)
        self.enterRule(localctx, 18, self.RULE_variable)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 179
            self.match(QuilParser.PERCENTAGE)
            self.state = 180
            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=None, invokingState=-1):
            super(QuilParser.MatrixContext, self).__init__(parent, invokingState)
            self.parser = parser

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


        def NEWLINE(self, i=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):
            if hasattr(listener, "enterMatrix"):
                listener.enterMatrix(self)

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




    def matrix(self):

        localctx = QuilParser.MatrixContext(self, self._ctx, self.state)
        self.enterRule(localctx, 20, self.RULE_matrix)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 187
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,13,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 182
                    self.matrixRow()
                    self.state = 183
                    self.match(QuilParser.NEWLINE) 
                self.state = 189
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,13,self._ctx)

            self.state = 190
            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=None, invokingState=-1):
            super(QuilParser.MatrixRowContext, self).__init__(parent, invokingState)
            self.parser = parser

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

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


        def COMMA(self, i=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):
            if hasattr(listener, "enterMatrixRow"):
                listener.enterMatrixRow(self)

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




    def matrixRow(self):

        localctx = QuilParser.MatrixRowContext(self, self._ctx, self.state)
        self.enterRule(localctx, 22, self.RULE_matrixRow)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 192
            self.match(QuilParser.TAB)
            self.state = 193
            self.expression(0)
            self.state = 198
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.COMMA:
                self.state = 194
                self.match(QuilParser.COMMA)
                self.state = 195
                self.expression(0)
                self.state = 200
                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=None, invokingState=-1):
            super(QuilParser.DefCircuitContext, self).__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=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=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.QubitVariableContext)
            else:
                return self.getTypedRuleContext(QuilParser.QubitVariableContext,i)


        def COMMA(self, i=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):
            if hasattr(listener, "enterDefCircuit"):
                listener.enterDefCircuit(self)

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




    def defCircuit(self):

        localctx = QuilParser.DefCircuitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 24, self.RULE_defCircuit)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 201
            self.match(QuilParser.DEFCIRCUIT)
            self.state = 202
            self.name()
            self.state = 214
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 203
                self.match(QuilParser.LPAREN)
                self.state = 204
                self.variable()
                self.state = 209
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 205
                    self.match(QuilParser.COMMA)
                    self.state = 206
                    self.variable()
                    self.state = 211
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 219
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.IDENTIFIER:
                self.state = 216
                self.qubitVariable()
                self.state = 221
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 222
            self.match(QuilParser.COLON)
            self.state = 223
            self.match(QuilParser.NEWLINE)
            self.state = 224
            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=None, invokingState=-1):
            super(QuilParser.QubitVariableContext, self).__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):
            if hasattr(listener, "enterQubitVariable"):
                listener.enterQubitVariable(self)

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




    def qubitVariable(self):

        localctx = QuilParser.QubitVariableContext(self, self._ctx, self.state)
        self.enterRule(localctx, 26, self.RULE_qubitVariable)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 226
            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=None, invokingState=-1):
            super(QuilParser.CircuitQubitContext, self).__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):
            if hasattr(listener, "enterCircuitQubit"):
                listener.enterCircuitQubit(self)

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




    def circuitQubit(self):

        localctx = QuilParser.CircuitQubitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 28, self.RULE_circuitQubit)
        try:
            self.state = 230
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.INT]:
                self.enterOuterAlt(localctx, 1)
                self.state = 228
                self.qubit()
                pass
            elif token in [QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 2)
                self.state = 229
                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=None, invokingState=-1):
            super(QuilParser.CircuitGateContext, self).__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=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=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.CircuitQubitContext)
            else:
                return self.getTypedRuleContext(QuilParser.CircuitQubitContext,i)


        def COMMA(self, i=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):
            if hasattr(listener, "enterCircuitGate"):
                listener.enterCircuitGate(self)

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




    def circuitGate(self):

        localctx = QuilParser.CircuitGateContext(self, self._ctx, self.state)
        self.enterRule(localctx, 30, self.RULE_circuitGate)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 232
            self.name()
            self.state = 244
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 233
                self.match(QuilParser.LPAREN)
                self.state = 234
                self.param()
                self.state = 239
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 235
                    self.match(QuilParser.COMMA)
                    self.state = 236
                    self.param()
                    self.state = 241
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 247 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 246
                self.circuitQubit()
                self.state = 249 
                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=None, invokingState=-1):
            super(QuilParser.CircuitInstrContext, self).__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):
            if hasattr(listener, "enterCircuitInstr"):
                listener.enterCircuitInstr(self)

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




    def circuitInstr(self):

        localctx = QuilParser.CircuitInstrContext(self, self._ctx, self.state)
        self.enterRule(localctx, 32, self.RULE_circuitInstr)
        try:
            self.state = 253
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,22,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 251
                self.circuitGate()
                pass

            elif la_ == 2:
                self.enterOuterAlt(localctx, 2)
                self.state = 252
                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=None, invokingState=-1):
            super(QuilParser.CircuitContext, self).__init__(parent, invokingState)
            self.parser = parser

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

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


        def NEWLINE(self, i=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):
            if hasattr(listener, "enterCircuit"):
                listener.enterCircuit(self)

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




    def circuit(self):

        localctx = QuilParser.CircuitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 34, self.RULE_circuit)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 261
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,23,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 255
                    self.match(QuilParser.TAB)
                    self.state = 256
                    self.circuitInstr()
                    self.state = 257
                    self.match(QuilParser.NEWLINE) 
                self.state = 263
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,23,self._ctx)

            self.state = 264
            self.match(QuilParser.TAB)
            self.state = 265
            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=None, invokingState=-1):
            super(QuilParser.MeasureContext, self).__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):
            if hasattr(listener, "enterMeasure"):
                listener.enterMeasure(self)

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




    def measure(self):

        localctx = QuilParser.MeasureContext(self, self._ctx, self.state)
        self.enterRule(localctx, 36, self.RULE_measure)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 267
            self.match(QuilParser.MEASURE)
            self.state = 268
            self.qubit()
            self.state = 270
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LBRACKET:
                self.state = 269
                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=None, invokingState=-1):
            super(QuilParser.AddrContext, self).__init__(parent, invokingState)
            self.parser = parser

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

        def classicalBit(self):
            return self.getTypedRuleContext(QuilParser.ClassicalBitContext,0)


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

        def getRuleIndex(self):
            return QuilParser.RULE_addr

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

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




    def addr(self):

        localctx = QuilParser.AddrContext(self, self._ctx, self.state)
        self.enterRule(localctx, 38, self.RULE_addr)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 272
            self.match(QuilParser.LBRACKET)
            self.state = 273
            self.classicalBit()
            self.state = 274
            self.match(QuilParser.RBRACKET)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ClassicalBitContext(ParserRuleContext):

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

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

        def getRuleIndex(self):
            return QuilParser.RULE_classicalBit

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

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




    def classicalBit(self):

        localctx = QuilParser.ClassicalBitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 40, self.RULE_classicalBit)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 277 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 276
                self.match(QuilParser.INT)
                self.state = 279 
                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 DefLabelContext(ParserRuleContext):

        def __init__(self, parser, parent=None, invokingState=-1):
            super(QuilParser.DefLabelContext, self).__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):
            if hasattr(listener, "enterDefLabel"):
                listener.enterDefLabel(self)

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




    def defLabel(self):

        localctx = QuilParser.DefLabelContext(self, self._ctx, self.state)
        self.enterRule(localctx, 42, self.RULE_defLabel)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 281
            self.match(QuilParser.LABEL)
            self.state = 282
            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=None, invokingState=-1):
            super(QuilParser.LabelContext, self).__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):
            if hasattr(listener, "enterLabel"):
                listener.enterLabel(self)

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




    def label(self):

        localctx = QuilParser.LabelContext(self, self._ctx, self.state)
        self.enterRule(localctx, 44, self.RULE_label)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 284
            self.match(QuilParser.AT)
            self.state = 285
            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=None, invokingState=-1):
            super(QuilParser.HaltContext, self).__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):
            if hasattr(listener, "enterHalt"):
                listener.enterHalt(self)

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




    def halt(self):

        localctx = QuilParser.HaltContext(self, self._ctx, self.state)
        self.enterRule(localctx, 46, self.RULE_halt)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 287
            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=None, invokingState=-1):
            super(QuilParser.JumpContext, self).__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):
            if hasattr(listener, "enterJump"):
                listener.enterJump(self)

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




    def jump(self):

        localctx = QuilParser.JumpContext(self, self._ctx, self.state)
        self.enterRule(localctx, 48, self.RULE_jump)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 289
            self.match(QuilParser.JUMP)
            self.state = 290
            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=None, invokingState=-1):
            super(QuilParser.JumpWhenContext, self).__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):
            if hasattr(listener, "enterJumpWhen"):
                listener.enterJumpWhen(self)

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




    def jumpWhen(self):

        localctx = QuilParser.JumpWhenContext(self, self._ctx, self.state)
        self.enterRule(localctx, 50, self.RULE_jumpWhen)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 292
            self.match(QuilParser.JUMPWHEN)
            self.state = 293
            self.label()
            self.state = 294
            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=None, invokingState=-1):
            super(QuilParser.JumpUnlessContext, self).__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):
            if hasattr(listener, "enterJumpUnless"):
                listener.enterJumpUnless(self)

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




    def jumpUnless(self):

        localctx = QuilParser.JumpUnlessContext(self, self._ctx, self.state)
        self.enterRule(localctx, 52, self.RULE_jumpUnless)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 296
            self.match(QuilParser.JUMPUNLESS)
            self.state = 297
            self.label()
            self.state = 298
            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=None, invokingState=-1):
            super(QuilParser.ResetStateContext, self).__init__(parent, invokingState)
            self.parser = parser

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

        def getRuleIndex(self):
            return QuilParser.RULE_resetState

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

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




    def resetState(self):

        localctx = QuilParser.ResetStateContext(self, self._ctx, self.state)
        self.enterRule(localctx, 54, self.RULE_resetState)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 300
            self.match(QuilParser.RESET)
        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=None, invokingState=-1):
            super(QuilParser.WaitContext, self).__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):
            if hasattr(listener, "enterWait"):
                listener.enterWait(self)

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




    def wait(self):

        localctx = QuilParser.WaitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 56, self.RULE_wait)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 302
            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 ClassicalUnaryContext(ParserRuleContext):

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

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


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

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

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

        def getRuleIndex(self):
            return QuilParser.RULE_classicalUnary

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

        def exitRule(self, listener):
            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 = 304
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.FALSE) | (1 << QuilParser.TRUE) | (1 << QuilParser.NOT))) != 0)):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
            self.state = 305
            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=None, invokingState=-1):
            super(QuilParser.ClassicalBinaryContext, self).__init__(parent, invokingState)
            self.parser = parser

        def addr(self, i=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 MOVE(self):
            return self.getToken(QuilParser.MOVE, 0)

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

        def getRuleIndex(self):
            return QuilParser.RULE_classicalBinary

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

        def exitRule(self, listener):
            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)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 307
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.AND) | (1 << QuilParser.OR) | (1 << QuilParser.MOVE) | (1 << QuilParser.EXCHANGE))) != 0)):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
            self.state = 308
            self.addr()
            self.state = 309
            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 NopContext(ParserRuleContext):

        def __init__(self, parser, parent=None, invokingState=-1):
            super(QuilParser.NopContext, self).__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):
            if hasattr(listener, "enterNop"):
                listener.enterNop(self)

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




    def nop(self):

        localctx = QuilParser.NopContext(self, self._ctx, self.state)
        self.enterRule(localctx, 62, self.RULE_nop)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 311
            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=None, invokingState=-1):
            super(QuilParser.IncludeContext, self).__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):
            if hasattr(listener, "enterInclude"):
                listener.enterInclude(self)

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




    def include(self):

        localctx = QuilParser.IncludeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 64, self.RULE_include)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 313
            self.match(QuilParser.INCLUDE)
            self.state = 314
            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=None, invokingState=-1):
            super(QuilParser.PragmaContext, self).__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=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):
            if hasattr(listener, "enterPragma"):
                listener.enterPragma(self)

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




    def pragma(self):

        localctx = QuilParser.PragmaContext(self, self._ctx, self.state)
        self.enterRule(localctx, 66, self.RULE_pragma)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 316
            self.match(QuilParser.PRAGMA)
            self.state = 317
            self.match(QuilParser.IDENTIFIER)
            self.state = 321
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.IDENTIFIER or _la==QuilParser.INT:
                self.state = 318
                self.pragma_name()
                self.state = 323
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 325
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.STRING:
                self.state = 324
                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=None, invokingState=-1):
            super(QuilParser.Pragma_nameContext, self).__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):
            if hasattr(listener, "enterPragma_name"):
                listener.enterPragma_name(self)

        def exitRule(self, listener):
            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, 68, self.RULE_pragma_name)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 327
            _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=None, invokingState=-1):
            super(QuilParser.ExpressionContext, self).__init__(parent, invokingState)
            self.parser = parser


        def getRuleIndex(self):
            return QuilParser.RULE_expression

     
        def copyFrom(self, ctx):
            super(QuilParser.ExpressionContext, self).copyFrom(ctx)


    class NumberExpContext(ExpressionContext):

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

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


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

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


    class PowerExpContext(ExpressionContext):

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

        def expression(self, i=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):
            if hasattr(listener, "enterPowerExp"):
                listener.enterPowerExp(self)

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


    class MulDivExpContext(ExpressionContext):

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

        def expression(self, i=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):
            if hasattr(listener, "enterMulDivExp"):
                listener.enterMulDivExp(self)

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


    class ParenthesisExpContext(ExpressionContext):

        def __init__(self, parser, ctx): # actually a QuilParser.ExpressionContext)
            super(QuilParser.ParenthesisExpContext, self).__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):
            if hasattr(listener, "enterParenthesisExp"):
                listener.enterParenthesisExp(self)

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


    class VariableExpContext(ExpressionContext):

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

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


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

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


    class SignedExpContext(ExpressionContext):

        def __init__(self, parser, ctx): # actually a QuilParser.ExpressionContext)
            super(QuilParser.SignedExpContext, self).__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):
            if hasattr(listener, "enterSignedExp"):
                listener.enterSignedExp(self)

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


    class AddSubExpContext(ExpressionContext):

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

        def expression(self, i=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):
            if hasattr(listener, "enterAddSubExp"):
                listener.enterAddSubExp(self)

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


    class FunctionExpContext(ExpressionContext):

        def __init__(self, parser, ctx): # actually a QuilParser.ExpressionContext)
            super(QuilParser.FunctionExpContext, self).__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):
            if hasattr(listener, "enterFunctionExp"):
                listener.enterFunctionExp(self)

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



    def expression(self, _p=0):
        _parentctx = self._ctx
        _parentState = self.state
        localctx = QuilParser.ExpressionContext(self, self._ctx, _parentState)
        _prevctx = localctx
        _startState = 70
        self.enterRecursionRule(localctx, 70, self.RULE_expression, _p)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 344
            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 = 330
                self.match(QuilParser.LPAREN)
                self.state = 331
                self.expression(0)
                self.state = 332
                self.match(QuilParser.RPAREN)
                pass
            elif token in [QuilParser.PLUS, QuilParser.MINUS]:
                localctx = QuilParser.SignedExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 334
                self.sign()
                self.state = 335
                self.expression(4)
                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 = 337
                self.function()
                self.state = 338
                self.match(QuilParser.LPAREN)
                self.state = 339
                self.expression(0)
                self.state = 340
                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 = 342
                self.number()
                pass
            elif token in [QuilParser.PERCENTAGE]:
                localctx = QuilParser.VariableExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 343
                self.variable()
                pass
            else:
                raise NoViableAltException(self)

            self._ctx.stop = self._input.LT(-1)
            self.state = 357
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,30,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 = 355
                    self._errHandler.sync(self)
                    la_ = self._interp.adaptivePredict(self._input,29,self._ctx)
                    if la_ == 1:
                        localctx = QuilParser.PowerExpContext(self, QuilParser.ExpressionContext(self, _parentctx, _parentState))
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expression)
                        self.state = 346
                        if not self.precpred(self._ctx, 7):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 7)")
                        self.state = 347
                        self.match(QuilParser.POWER)
                        self.state = 348
                        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 = 349
                        if not self.precpred(self._ctx, 6):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 6)")
                        self.state = 350
                        _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 = 351
                        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 = 352
                        if not self.precpred(self._ctx, 5):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 5)")
                        self.state = 353
                        _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 = 354
                        self.expression(6)
                        pass

             
                self.state = 359
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,30,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=None, invokingState=-1):
            super(QuilParser.FunctionContext, self).__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):
            if hasattr(listener, "enterFunction"):
                listener.enterFunction(self)

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




    def function(self):

        localctx = QuilParser.FunctionContext(self, self._ctx, self.state)
        self.enterRule(localctx, 72, self.RULE_function)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 360
            _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=None, invokingState=-1):
            super(QuilParser.SignContext, self).__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):
            if hasattr(listener, "enterSign"):
                listener.enterSign(self)

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




    def sign(self):

        localctx = QuilParser.SignContext(self, self._ctx, self.state)
        self.enterRule(localctx, 74, self.RULE_sign)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 362
            _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=None, invokingState=-1):
            super(QuilParser.NumberContext, self).__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):
            if hasattr(listener, "enterNumber"):
                listener.enterNumber(self)

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




    def number(self):

        localctx = QuilParser.NumberContext(self, self._ctx, self.state)
        self.enterRule(localctx, 76, self.RULE_number)
        try:
            self.state = 368
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,31,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 364
                self.realN()
                pass

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

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

            elif la_ == 4:
                self.enterOuterAlt(localctx, 4)
                self.state = 367
                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=None, invokingState=-1):
            super(QuilParser.ImaginaryNContext, self).__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):
            if hasattr(listener, "enterImaginaryN"):
                listener.enterImaginaryN(self)

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




    def imaginaryN(self):

        localctx = QuilParser.ImaginaryNContext(self, self._ctx, self.state)
        self.enterRule(localctx, 78, self.RULE_imaginaryN)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 370
            self.realN()
            self.state = 371
            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=None, invokingState=-1):
            super(QuilParser.RealNContext, self).__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):
            if hasattr(listener, "enterRealN"):
                listener.enterRealN(self)

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




    def realN(self):

        localctx = QuilParser.RealNContext(self, self._ctx, self.state)
        self.enterRule(localctx, 80, self.RULE_realN)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 373
            _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, ruleIndex, predIndex):
        if self._predicates == None:
            self._predicates = dict()
        self._predicates[35] = 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, predIndex):
            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)
         




