# 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\u0172\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\3\2\6")
        buf.write(u"\2W\n\2\r\2\16\2X\3\2\7\2\\\n\2\f\2\16\2_\13\2\3\2\3")
        buf.write(u"\2\3\3\3\3\3\3\5\3f\n\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3")
        buf.write(u"\4\3\4\3\4\3\4\3\4\3\4\3\4\5\4v\n\4\3\5\3\5\3\5\3\5\3")
        buf.write(u"\5\7\5}\n\5\f\5\16\5\u0080\13\5\3\5\3\5\5\5\u0084\n\5")
        buf.write(u"\3\5\6\5\u0087\n\5\r\5\16\5\u0088\3\6\3\6\3\7\3\7\3\b")
        buf.write(u"\3\b\5\b\u0091\n\b\3\t\3\t\3\t\3\t\5\t\u0097\n\t\3\t")
        buf.write(u"\3\t\3\n\3\n\3\n\3\n\3\n\3\n\7\n\u00a1\n\n\f\n\16\n\u00a4")
        buf.write(u"\13\n\3\n\3\n\5\n\u00a8\n\n\3\n\3\n\3\n\3\n\3\13\3\13")
        buf.write(u"\3\13\3\f\3\f\3\f\7\f\u00b4\n\f\f\f\16\f\u00b7\13\f\3")
        buf.write(u"\f\3\f\3\r\3\r\3\r\3\r\7\r\u00bf\n\r\f\r\16\r\u00c2\13")
        buf.write(u"\r\3\16\3\16\3\16\3\16\3\16\3\16\7\16\u00ca\n\16\f\16")
        buf.write(u"\16\16\u00cd\13\16\3\16\3\16\5\16\u00d1\n\16\3\16\7\16")
        buf.write(u"\u00d4\n\16\f\16\16\16\u00d7\13\16\3\16\3\16\3\16\3\16")
        buf.write(u"\3\17\3\17\3\20\3\20\5\20\u00e1\n\20\3\21\3\21\3\21\3")
        buf.write(u"\21\3\21\7\21\u00e8\n\21\f\21\16\21\u00eb\13\21\3\21")
        buf.write(u"\3\21\5\21\u00ef\n\21\3\21\6\21\u00f2\n\21\r\21\16\21")
        buf.write(u"\u00f3\3\22\3\22\5\22\u00f8\n\22\3\23\3\23\3\23\3\23")
        buf.write(u"\7\23\u00fe\n\23\f\23\16\23\u0101\13\23\3\23\3\23\3\23")
        buf.write(u"\3\24\3\24\3\24\5\24\u0109\n\24\3\25\3\25\3\25\3\25\3")
        buf.write(u"\26\6\26\u0110\n\26\r\26\16\26\u0111\3\27\3\27\3\27\3")
        buf.write(u"\30\3\30\3\30\3\31\3\31\3\32\3\32\3\32\3\33\3\33\3\33")
        buf.write(u"\3\33\3\34\3\34\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3")
        buf.write(u"\37\3\37\3 \3 \3 \3 \3!\3!\3\"\3\"\3\"\3#\3#\3#\7#\u013a")
        buf.write(u"\n#\f#\16#\u013d\13#\3#\5#\u0140\n#\3$\3$\3%\3%\3%\3")
        buf.write(u"%\3%\3%\3%\3%\3%\3%\3%\3%\3%\3%\3%\5%\u0153\n%\3%\3%")
        buf.write(u"\3%\3%\3%\3%\3%\3%\3%\7%\u015e\n%\f%\16%\u0161\13%\3")
        buf.write(u"&\3&\3\'\3\'\3(\3(\3(\3(\5(\u016b\n(\3)\3)\3)\3*\3*\3")
        buf.write(u"*\2\3H+\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(")
        buf.write(u"*,.\60\62\64\668:<>@BDFHJLNPR\2\t\3\2\20\22\3\2\23\26")
        buf.write(u"\3\2#$\3\2 !\3\2\36\37\3\2\31\35\3\2$%\2\u0179\2T\3\2")
        buf.write(u"\2\2\4e\3\2\2\2\6u\3\2\2\2\bw\3\2\2\2\n\u008a\3\2\2\2")
        buf.write(u"\f\u008c\3\2\2\2\16\u0090\3\2\2\2\20\u0092\3\2\2\2\22")
        buf.write(u"\u009a\3\2\2\2\24\u00ad\3\2\2\2\26\u00b5\3\2\2\2\30\u00ba")
        buf.write(u"\3\2\2\2\32\u00c3\3\2\2\2\34\u00dc\3\2\2\2\36\u00e0\3")
        buf.write(u"\2\2\2 \u00e2\3\2\2\2\"\u00f7\3\2\2\2$\u00ff\3\2\2\2")
        buf.write(u"&\u0105\3\2\2\2(\u010a\3\2\2\2*\u010f\3\2\2\2,\u0113")
        buf.write(u"\3\2\2\2.\u0116\3\2\2\2\60\u0119\3\2\2\2\62\u011b\3\2")
        buf.write(u"\2\2\64\u011e\3\2\2\2\66\u0122\3\2\2\28\u0126\3\2\2\2")
        buf.write(u":\u0128\3\2\2\2<\u012a\3\2\2\2>\u012d\3\2\2\2@\u0131")
        buf.write(u"\3\2\2\2B\u0133\3\2\2\2D\u0136\3\2\2\2F\u0141\3\2\2\2")
        buf.write(u"H\u0152\3\2\2\2J\u0162\3\2\2\2L\u0164\3\2\2\2N\u016a")
        buf.write(u"\3\2\2\2P\u016c\3\2\2\2R\u016f\3\2\2\2T]\5\4\3\2UW\7")
        buf.write(u"\63\2\2VU\3\2\2\2WX\3\2\2\2XV\3\2\2\2XY\3\2\2\2YZ\3\2")
        buf.write(u"\2\2Z\\\5\4\3\2[V\3\2\2\2\\_\3\2\2\2][\3\2\2\2]^\3\2")
        buf.write(u"\2\2^`\3\2\2\2_]\3\2\2\2`a\7\2\2\3a\3\3\2\2\2bf\5\22")
        buf.write(u"\n\2cf\5\32\16\2df\5\6\4\2eb\3\2\2\2ec\3\2\2\2ed\3\2")
        buf.write(u"\2\2f\5\3\2\2\2gv\5\b\5\2hv\5&\24\2iv\5,\27\2jv\5\60")
        buf.write(u"\31\2kv\5\62\32\2lv\5\64\33\2mv\5\66\34\2nv\58\35\2o")
        buf.write(u"v\5:\36\2pv\5<\37\2qv\5> \2rv\5@!\2sv\5B\"\2tv\5D#\2")
        buf.write(u"ug\3\2\2\2uh\3\2\2\2ui\3\2\2\2uj\3\2\2\2uk\3\2\2\2ul")
        buf.write(u"\3\2\2\2um\3\2\2\2un\3\2\2\2uo\3\2\2\2up\3\2\2\2uq\3")
        buf.write(u"\2\2\2ur\3\2\2\2us\3\2\2\2ut\3\2\2\2v\7\3\2\2\2w\u0083")
        buf.write(u"\5\n\6\2xy\7)\2\2y~\5\16\b\2z{\7(\2\2{}\5\16\b\2|z\3")
        buf.write(u"\2\2\2}\u0080\3\2\2\2~|\3\2\2\2~\177\3\2\2\2\177\u0081")
        buf.write(u"\3\2\2\2\u0080~\3\2\2\2\u0081\u0082\7*\2\2\u0082\u0084")
        buf.write(u"\3\2\2\2\u0083x\3\2\2\2\u0083\u0084\3\2\2\2\u0084\u0086")
        buf.write(u"\3\2\2\2\u0085\u0087\5\f\7\2\u0086\u0085\3\2\2\2\u0087")
        buf.write(u"\u0088\3\2\2\2\u0088\u0086\3\2\2\2\u0088\u0089\3\2\2")
        buf.write(u"\2\u0089\t\3\2\2\2\u008a\u008b\7#\2\2\u008b\13\3\2\2")
        buf.write(u"\2\u008c\u008d\7$\2\2\u008d\r\3\2\2\2\u008e\u0091\5\20")
        buf.write(u"\t\2\u008f\u0091\5H%\2\u0090\u008e\3\2\2\2\u0090\u008f")
        buf.write(u"\3\2\2\2\u0091\17\3\2\2\2\u0092\u0093\7+\2\2\u0093\u0096")
        buf.write(u"\7$\2\2\u0094\u0095\7\37\2\2\u0095\u0097\7$\2\2\u0096")
        buf.write(u"\u0094\3\2\2\2\u0096\u0097\3\2\2\2\u0097\u0098\3\2\2")
        buf.write(u"\2\u0098\u0099\7,\2\2\u0099\21\3\2\2\2\u009a\u009b\7")
        buf.write(u"\3\2\2\u009b\u00a7\5\n\6\2\u009c\u009d\7)\2\2\u009d\u00a2")
        buf.write(u"\5\24\13\2\u009e\u009f\7(\2\2\u009f\u00a1\5\24\13\2\u00a0")
        buf.write(u"\u009e\3\2\2\2\u00a1\u00a4\3\2\2\2\u00a2\u00a0\3\2\2")
        buf.write(u"\2\u00a2\u00a3\3\2\2\2\u00a3\u00a5\3\2\2\2\u00a4\u00a2")
        buf.write(u"\3\2\2\2\u00a5\u00a6\7*\2\2\u00a6\u00a8\3\2\2\2\u00a7")
        buf.write(u"\u009c\3\2\2\2\u00a7\u00a8\3\2\2\2\u00a8\u00a9\3\2\2")
        buf.write(u"\2\u00a9\u00aa\7-\2\2\u00aa\u00ab\7\63\2\2\u00ab\u00ac")
        buf.write(u"\5\26\f\2\u00ac\23\3\2\2\2\u00ad\u00ae\7.\2\2\u00ae\u00af")
        buf.write(u"\7#\2\2\u00af\25\3\2\2\2\u00b0\u00b1\5\30\r\2\u00b1\u00b2")
        buf.write(u"\7\63\2\2\u00b2\u00b4\3\2\2\2\u00b3\u00b0\3\2\2\2\u00b4")
        buf.write(u"\u00b7\3\2\2\2\u00b5\u00b3\3\2\2\2\u00b5\u00b6\3\2\2")
        buf.write(u"\2\u00b6\u00b8\3\2\2\2\u00b7\u00b5\3\2\2\2\u00b8\u00b9")
        buf.write(u"\5\30\r\2\u00b9\27\3\2\2\2\u00ba\u00bb\7\62\2\2\u00bb")
        buf.write(u"\u00c0\5H%\2\u00bc\u00bd\7(\2\2\u00bd\u00bf\5H%\2\u00be")
        buf.write(u"\u00bc\3\2\2\2\u00bf\u00c2\3\2\2\2\u00c0\u00be\3\2\2")
        buf.write(u"\2\u00c0\u00c1\3\2\2\2\u00c1\31\3\2\2\2\u00c2\u00c0\3")
        buf.write(u"\2\2\2\u00c3\u00c4\7\4\2\2\u00c4\u00d0\5\n\6\2\u00c5")
        buf.write(u"\u00c6\7)\2\2\u00c6\u00cb\5\24\13\2\u00c7\u00c8\7(\2")
        buf.write(u"\2\u00c8\u00ca\5\24\13\2\u00c9\u00c7\3\2\2\2\u00ca\u00cd")
        buf.write(u"\3\2\2\2\u00cb\u00c9\3\2\2\2\u00cb\u00cc\3\2\2\2\u00cc")
        buf.write(u"\u00ce\3\2\2\2\u00cd\u00cb\3\2\2\2\u00ce\u00cf\7*\2\2")
        buf.write(u"\u00cf\u00d1\3\2\2\2\u00d0\u00c5\3\2\2\2\u00d0\u00d1")
        buf.write(u"\3\2\2\2\u00d1\u00d5\3\2\2\2\u00d2\u00d4\5\34\17\2\u00d3")
        buf.write(u"\u00d2\3\2\2\2\u00d4\u00d7\3\2\2\2\u00d5\u00d3\3\2\2")
        buf.write(u"\2\u00d5\u00d6\3\2\2\2\u00d6\u00d8\3\2\2\2\u00d7\u00d5")
        buf.write(u"\3\2\2\2\u00d8\u00d9\7-\2\2\u00d9\u00da\7\63\2\2\u00da")
        buf.write(u"\u00db\5$\23\2\u00db\33\3\2\2\2\u00dc\u00dd\7#\2\2\u00dd")
        buf.write(u"\35\3\2\2\2\u00de\u00e1\5\f\7\2\u00df\u00e1\5\34\17\2")
        buf.write(u"\u00e0\u00de\3\2\2\2\u00e0\u00df\3\2\2\2\u00e1\37\3\2")
        buf.write(u"\2\2\u00e2\u00ee\5\n\6\2\u00e3\u00e4\7)\2\2\u00e4\u00e9")
        buf.write(u"\5\16\b\2\u00e5\u00e6\7(\2\2\u00e6\u00e8\5\16\b\2\u00e7")
        buf.write(u"\u00e5\3\2\2\2\u00e8\u00eb\3\2\2\2\u00e9\u00e7\3\2\2")
        buf.write(u"\2\u00e9\u00ea\3\2\2\2\u00ea\u00ec\3\2\2\2\u00eb\u00e9")
        buf.write(u"\3\2\2\2\u00ec\u00ed\7*\2\2\u00ed\u00ef\3\2\2\2\u00ee")
        buf.write(u"\u00e3\3\2\2\2\u00ee\u00ef\3\2\2\2\u00ef\u00f1\3\2\2")
        buf.write(u"\2\u00f0\u00f2\5\36\20\2\u00f1\u00f0\3\2\2\2\u00f2\u00f3")
        buf.write(u"\3\2\2\2\u00f3\u00f1\3\2\2\2\u00f3\u00f4\3\2\2\2\u00f4")
        buf.write(u"!\3\2\2\2\u00f5\u00f8\5 \21\2\u00f6\u00f8\5\6\4\2\u00f7")
        buf.write(u"\u00f5\3\2\2\2\u00f7\u00f6\3\2\2\2\u00f8#\3\2\2\2\u00f9")
        buf.write(u"\u00fa\7\62\2\2\u00fa\u00fb\5\"\22\2\u00fb\u00fc\7\63")
        buf.write(u"\2\2\u00fc\u00fe\3\2\2\2\u00fd\u00f9\3\2\2\2\u00fe\u0101")
        buf.write(u"\3\2\2\2\u00ff\u00fd\3\2\2\2\u00ff\u0100\3\2\2\2\u0100")
        buf.write(u"\u0102\3\2\2\2\u0101\u00ff\3\2\2\2\u0102\u0103\7\62\2")
        buf.write(u"\2\u0103\u0104\5\"\22\2\u0104%\3\2\2\2\u0105\u0106\7")
        buf.write(u"\5\2\2\u0106\u0108\5\f\7\2\u0107\u0109\5(\25\2\u0108")
        buf.write(u"\u0107\3\2\2\2\u0108\u0109\3\2\2\2\u0109\'\3\2\2\2\u010a")
        buf.write(u"\u010b\7+\2\2\u010b\u010c\5*\26\2\u010c\u010d\7,\2\2")
        buf.write(u"\u010d)\3\2\2\2\u010e\u0110\7$\2\2\u010f\u010e\3\2\2")
        buf.write(u"\2\u0110\u0111\3\2\2\2\u0111\u010f\3\2\2\2\u0111\u0112")
        buf.write(u"\3\2\2\2\u0112+\3\2\2\2\u0113\u0114\7\6\2\2\u0114\u0115")
        buf.write(u"\5.\30\2\u0115-\3\2\2\2\u0116\u0117\7/\2\2\u0117\u0118")
        buf.write(u"\7#\2\2\u0118/\3\2\2\2\u0119\u011a\7\7\2\2\u011a\61\3")
        buf.write(u"\2\2\2\u011b\u011c\7\b\2\2\u011c\u011d\5.\30\2\u011d")
        buf.write(u"\63\3\2\2\2\u011e\u011f\7\t\2\2\u011f\u0120\5.\30\2\u0120")
        buf.write(u"\u0121\5(\25\2\u0121\65\3\2\2\2\u0122\u0123\7\n\2\2\u0123")
        buf.write(u"\u0124\5.\30\2\u0124\u0125\5(\25\2\u0125\67\3\2\2\2\u0126")
        buf.write(u"\u0127\7\13\2\2\u01279\3\2\2\2\u0128\u0129\7\f\2\2\u0129")
        buf.write(u";\3\2\2\2\u012a\u012b\t\2\2\2\u012b\u012c\5(\25\2\u012c")
        buf.write(u"=\3\2\2\2\u012d\u012e\t\3\2\2\u012e\u012f\5(\25\2\u012f")
        buf.write(u"\u0130\5(\25\2\u0130?\3\2\2\2\u0131\u0132\7\r\2\2\u0132")
        buf.write(u"A\3\2\2\2\u0133\u0134\7\16\2\2\u0134\u0135\7&\2\2\u0135")
        buf.write(u"C\3\2\2\2\u0136\u0137\7\17\2\2\u0137\u013b\7#\2\2\u0138")
        buf.write(u"\u013a\5F$\2\u0139\u0138\3\2\2\2\u013a\u013d\3\2\2\2")
        buf.write(u"\u013b\u0139\3\2\2\2\u013b\u013c\3\2\2\2\u013c\u013f")
        buf.write(u"\3\2\2\2\u013d\u013b\3\2\2\2\u013e\u0140\7&\2\2\u013f")
        buf.write(u"\u013e\3\2\2\2\u013f\u0140\3\2\2\2\u0140E\3\2\2\2\u0141")
        buf.write(u"\u0142\t\4\2\2\u0142G\3\2\2\2\u0143\u0144\b%\1\2\u0144")
        buf.write(u"\u0145\7)\2\2\u0145\u0146\5H%\2\u0146\u0147\7*\2\2\u0147")
        buf.write(u"\u0153\3\2\2\2\u0148\u0149\5L\'\2\u0149\u014a\5H%\6\u014a")
        buf.write(u"\u0153\3\2\2\2\u014b\u014c\5J&\2\u014c\u014d\7)\2\2\u014d")
        buf.write(u"\u014e\5H%\2\u014e\u014f\7*\2\2\u014f\u0153\3\2\2\2\u0150")
        buf.write(u"\u0153\5N(\2\u0151\u0153\5\24\13\2\u0152\u0143\3\2\2")
        buf.write(u"\2\u0152\u0148\3\2\2\2\u0152\u014b\3\2\2\2\u0152\u0150")
        buf.write(u"\3\2\2\2\u0152\u0151\3\2\2\2\u0153\u015f\3\2\2\2\u0154")
        buf.write(u"\u0155\f\t\2\2\u0155\u0156\7\"\2\2\u0156\u015e\5H%\t")
        buf.write(u"\u0157\u0158\f\b\2\2\u0158\u0159\t\5\2\2\u0159\u015e")
        buf.write(u"\5H%\t\u015a\u015b\f\7\2\2\u015b\u015c\t\6\2\2\u015c")
        buf.write(u"\u015e\5H%\b\u015d\u0154\3\2\2\2\u015d\u0157\3\2\2\2")
        buf.write(u"\u015d\u015a\3\2\2\2\u015e\u0161\3\2\2\2\u015f\u015d")
        buf.write(u"\3\2\2\2\u015f\u0160\3\2\2\2\u0160I\3\2\2\2\u0161\u015f")
        buf.write(u"\3\2\2\2\u0162\u0163\t\7\2\2\u0163K\3\2\2\2\u0164\u0165")
        buf.write(u"\t\6\2\2\u0165M\3\2\2\2\u0166\u016b\5R*\2\u0167\u016b")
        buf.write(u"\5P)\2\u0168\u016b\7\30\2\2\u0169\u016b\7\27\2\2\u016a")
        buf.write(u"\u0166\3\2\2\2\u016a\u0167\3\2\2\2\u016a\u0168\3\2\2")
        buf.write(u"\2\u016a\u0169\3\2\2\2\u016bO\3\2\2\2\u016c\u016d\5R")
        buf.write(u"*\2\u016d\u016e\7\30\2\2\u016eQ\3\2\2\2\u016f\u0170\t")
        buf.write(u"\b\2\2\u0170S\3\2\2\2 X]eu~\u0083\u0088\u0090\u0096\u00a2")
        buf.write(u"\u00a7\u00b5\u00c0\u00cb\u00d0\u00d5\u00e0\u00e9\u00ee")
        buf.write(u"\u00f3\u00f7\u00ff\u0108\u0111\u013b\u013f\u0152\u015d")
        buf.write(u"\u015f\u016a")
        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 allInstr(self, i=None):
            if i is None:
                return self.getTypedRuleContexts(QuilParser.AllInstrContext)
            else:
                return self.getTypedRuleContext(QuilParser.AllInstrContext,i)


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

        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 = 82
            self.allInstr()
            self.state = 91
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.NEWLINE:
                self.state = 84 
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while True:
                    self.state = 83
                    self.match(QuilParser.NEWLINE)
                    self.state = 86 
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)
                    if not (_la==QuilParser.NEWLINE):
                        break

                self.state = 88
                self.allInstr()
                self.state = 93
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 94
            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 = 99
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.DEFGATE]:
                self.enterOuterAlt(localctx, 1)
                self.state = 96
                self.defGate()
                pass
            elif token in [QuilParser.DEFCIRCUIT]:
                self.enterOuterAlt(localctx, 2)
                self.state = 97
                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 = 98
                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 = 115
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 1)
                self.state = 101
                self.gate()
                pass
            elif token in [QuilParser.MEASURE]:
                self.enterOuterAlt(localctx, 2)
                self.state = 102
                self.measure()
                pass
            elif token in [QuilParser.LABEL]:
                self.enterOuterAlt(localctx, 3)
                self.state = 103
                self.defLabel()
                pass
            elif token in [QuilParser.HALT]:
                self.enterOuterAlt(localctx, 4)
                self.state = 104
                self.halt()
                pass
            elif token in [QuilParser.JUMP]:
                self.enterOuterAlt(localctx, 5)
                self.state = 105
                self.jump()
                pass
            elif token in [QuilParser.JUMPWHEN]:
                self.enterOuterAlt(localctx, 6)
                self.state = 106
                self.jumpWhen()
                pass
            elif token in [QuilParser.JUMPUNLESS]:
                self.enterOuterAlt(localctx, 7)
                self.state = 107
                self.jumpUnless()
                pass
            elif token in [QuilParser.RESET]:
                self.enterOuterAlt(localctx, 8)
                self.state = 108
                self.resetState()
                pass
            elif token in [QuilParser.WAIT]:
                self.enterOuterAlt(localctx, 9)
                self.state = 109
                self.wait()
                pass
            elif token in [QuilParser.FALSE, QuilParser.TRUE, QuilParser.NOT]:
                self.enterOuterAlt(localctx, 10)
                self.state = 110
                self.classicalUnary()
                pass
            elif token in [QuilParser.AND, QuilParser.OR, QuilParser.MOVE, QuilParser.EXCHANGE]:
                self.enterOuterAlt(localctx, 11)
                self.state = 111
                self.classicalBinary()
                pass
            elif token in [QuilParser.NOP]:
                self.enterOuterAlt(localctx, 12)
                self.state = 112
                self.nop()
                pass
            elif token in [QuilParser.INCLUDE]:
                self.enterOuterAlt(localctx, 13)
                self.state = 113
                self.include()
                pass
            elif token in [QuilParser.PRAGMA]:
                self.enterOuterAlt(localctx, 14)
                self.state = 114
                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 = 117
            self.name()
            self.state = 129
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 118
                self.match(QuilParser.LPAREN)
                self.state = 119
                self.param()
                self.state = 124
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 120
                    self.match(QuilParser.COMMA)
                    self.state = 121
                    self.param()
                    self.state = 126
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 132 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 131
                self.qubit()
                self.state = 134 
                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 = 136
            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 = 138
            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 = 142
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.LBRACKET]:
                self.enterOuterAlt(localctx, 1)
                self.state = 140
                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 = 141
                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 = 144
            self.match(QuilParser.LBRACKET)
            self.state = 145
            self.match(QuilParser.INT)
            self.state = 148
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.MINUS:
                self.state = 146
                self.match(QuilParser.MINUS)
                self.state = 147
                self.match(QuilParser.INT)


            self.state = 150
            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 = 152
            self.match(QuilParser.DEFGATE)
            self.state = 153
            self.name()
            self.state = 165
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 154
                self.match(QuilParser.LPAREN)
                self.state = 155
                self.variable()
                self.state = 160
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 156
                    self.match(QuilParser.COMMA)
                    self.state = 157
                    self.variable()
                    self.state = 162
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 167
            self.match(QuilParser.COLON)
            self.state = 168
            self.match(QuilParser.NEWLINE)
            self.state = 169
            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 = 171
            self.match(QuilParser.PERCENTAGE)
            self.state = 172
            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 = 179
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,11,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 174
                    self.matrixRow()
                    self.state = 175
                    self.match(QuilParser.NEWLINE) 
                self.state = 181
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,11,self._ctx)

            self.state = 182
            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 = 184
            self.match(QuilParser.TAB)
            self.state = 185
            self.expression(0)
            self.state = 190
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.COMMA:
                self.state = 186
                self.match(QuilParser.COMMA)
                self.state = 187
                self.expression(0)
                self.state = 192
                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 = 193
            self.match(QuilParser.DEFCIRCUIT)
            self.state = 194
            self.name()
            self.state = 206
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 195
                self.match(QuilParser.LPAREN)
                self.state = 196
                self.variable()
                self.state = 201
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 197
                    self.match(QuilParser.COMMA)
                    self.state = 198
                    self.variable()
                    self.state = 203
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 211
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.IDENTIFIER:
                self.state = 208
                self.qubitVariable()
                self.state = 213
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 214
            self.match(QuilParser.COLON)
            self.state = 215
            self.match(QuilParser.NEWLINE)
            self.state = 216
            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 = 218
            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 = 222
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [QuilParser.INT]:
                self.enterOuterAlt(localctx, 1)
                self.state = 220
                self.qubit()
                pass
            elif token in [QuilParser.IDENTIFIER]:
                self.enterOuterAlt(localctx, 2)
                self.state = 221
                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 = 224
            self.name()
            self.state = 236
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LPAREN:
                self.state = 225
                self.match(QuilParser.LPAREN)
                self.state = 226
                self.param()
                self.state = 231
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==QuilParser.COMMA:
                    self.state = 227
                    self.match(QuilParser.COMMA)
                    self.state = 228
                    self.param()
                    self.state = 233
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

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


            self.state = 239 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 238
                self.circuitQubit()
                self.state = 241 
                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 = 245
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,20,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 243
                self.circuitGate()
                pass

            elif la_ == 2:
                self.enterOuterAlt(localctx, 2)
                self.state = 244
                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 = 253
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,21,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 247
                    self.match(QuilParser.TAB)
                    self.state = 248
                    self.circuitInstr()
                    self.state = 249
                    self.match(QuilParser.NEWLINE) 
                self.state = 255
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,21,self._ctx)

            self.state = 256
            self.match(QuilParser.TAB)
            self.state = 257
            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 = 259
            self.match(QuilParser.MEASURE)
            self.state = 260
            self.qubit()
            self.state = 262
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.LBRACKET:
                self.state = 261
                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 = 264
            self.match(QuilParser.LBRACKET)
            self.state = 265
            self.classicalBit()
            self.state = 266
            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 = 269 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 268
                self.match(QuilParser.INT)
                self.state = 271 
                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 = 273
            self.match(QuilParser.LABEL)
            self.state = 274
            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 = 276
            self.match(QuilParser.AT)
            self.state = 277
            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 = 279
            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 = 281
            self.match(QuilParser.JUMP)
            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 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 = 284
            self.match(QuilParser.JUMPWHEN)
            self.state = 285
            self.label()
            self.state = 286
            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 = 288
            self.match(QuilParser.JUMPUNLESS)
            self.state = 289
            self.label()
            self.state = 290
            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 = 292
            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 = 294
            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 = 296
            _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 = 297
            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 = 299
            _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 = 300
            self.addr()
            self.state = 301
            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 = 303
            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 = 305
            self.match(QuilParser.INCLUDE)
            self.state = 306
            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 = 308
            self.match(QuilParser.PRAGMA)
            self.state = 309
            self.match(QuilParser.IDENTIFIER)
            self.state = 313
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==QuilParser.IDENTIFIER or _la==QuilParser.INT:
                self.state = 310
                self.pragma_name()
                self.state = 315
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 317
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==QuilParser.STRING:
                self.state = 316
                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 = 319
            _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 = 336
            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 = 322
                self.match(QuilParser.LPAREN)
                self.state = 323
                self.expression(0)
                self.state = 324
                self.match(QuilParser.RPAREN)
                pass
            elif token in [QuilParser.PLUS, QuilParser.MINUS]:
                localctx = QuilParser.SignedExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 326
                self.sign()
                self.state = 327
                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 = 329
                self.function()
                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.PI, QuilParser.I, QuilParser.INT, QuilParser.FLOAT]:
                localctx = QuilParser.NumberExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 334
                self.number()
                pass
            elif token in [QuilParser.PERCENTAGE]:
                localctx = QuilParser.VariableExpContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 335
                self.variable()
                pass
            else:
                raise NoViableAltException(self)

            self._ctx.stop = self._input.LT(-1)
            self.state = 349
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,28,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 = 347
                    self._errHandler.sync(self)
                    la_ = self._interp.adaptivePredict(self._input,27,self._ctx)
                    if la_ == 1:
                        localctx = QuilParser.PowerExpContext(self, QuilParser.ExpressionContext(self, _parentctx, _parentState))
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expression)
                        self.state = 338
                        if not self.precpred(self._ctx, 7):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 7)")
                        self.state = 339
                        self.match(QuilParser.POWER)
                        self.state = 340
                        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 = 341
                        if not self.precpred(self._ctx, 6):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 6)")
                        self.state = 342
                        _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 = 343
                        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 = 344
                        if not self.precpred(self._ctx, 5):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 5)")
                        self.state = 345
                        _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 = 346
                        self.expression(6)
                        pass

             
                self.state = 351
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,28,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 = 352
            _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 = 354
            _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 = 360
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,29,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 356
                self.realN()
                pass

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

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

            elif la_ == 4:
                self.enterOuterAlt(localctx, 4)
                self.state = 359
                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 = 362
            self.realN()
            self.state = 363
            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 = 365
            _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)
         




