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

def serializedATN():
    with StringIO() as buf:
        buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3<")
        buf.write("\u012b\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7")
        buf.write("\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16")
        buf.write("\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22\4\23\t\23")
        buf.write("\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31")
        buf.write("\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36")
        buf.write("\4\37\t\37\3\2\7\2@\n\2\f\2\16\2C\13\2\3\2\3\2\7\2G\n")
        buf.write("\2\f\2\16\2J\13\2\3\2\3\2\7\2N\n\2\f\2\16\2Q\13\2\3\2")
        buf.write("\3\2\3\3\3\3\6\3W\n\3\r\3\16\3X\3\3\3\3\6\3]\n\3\r\3\16")
        buf.write("\3^\3\3\5\3b\n\3\3\3\3\3\7\3f\n\3\f\3\16\3i\13\3\3\4\3")
        buf.write("\4\3\4\3\5\3\5\3\6\3\6\3\6\3\7\3\7\3\b\3\b\3\b\5\bx\n")
        buf.write("\b\3\t\3\t\3\n\3\n\3\n\3\13\3\13\3\13\3\13\7\13\u0083")
        buf.write("\n\13\f\13\16\13\u0086\13\13\3\f\3\f\3\f\3\f\3\f\5\f\u008d")
        buf.write("\n\f\3\r\3\r\3\r\3\r\3\r\3\r\3\r\5\r\u0096\n\r\3\r\3\r")
        buf.write("\3\r\3\r\3\16\3\16\5\16\u009e\n\16\3\17\3\17\5\17\u00a2")
        buf.write("\n\17\3\20\3\20\3\21\3\21\3\22\3\22\3\23\3\23\3\23\7\23")
        buf.write("\u00ad\n\23\f\23\16\23\u00b0\13\23\3\24\3\24\3\24\3\24")
        buf.write("\7\24\u00b6\n\24\f\24\16\24\u00b9\13\24\3\25\3\25\3\25")
        buf.write("\7\25\u00be\n\25\f\25\16\25\u00c1\13\25\3\26\3\26\5\26")
        buf.write("\u00c5\n\26\3\26\5\26\u00c8\n\26\3\26\3\26\5\26\u00cc")
        buf.write("\n\26\3\26\3\26\5\26\u00d0\n\26\3\26\7\26\u00d3\n\26\f")
        buf.write("\26\16\26\u00d6\13\26\3\27\3\27\3\30\3\30\3\31\3\31\3")
        buf.write("\31\3\31\7\31\u00e0\n\31\f\31\16\31\u00e3\13\31\5\31\u00e5")
        buf.write("\n\31\3\31\5\31\u00e8\n\31\3\31\3\31\3\31\7\31\u00ed\n")
        buf.write("\31\f\31\16\31\u00f0\13\31\5\31\u00f2\n\31\3\31\3\31\3")
        buf.write("\32\3\32\3\32\3\32\3\33\3\33\5\33\u00fc\n\33\3\34\3\34")
        buf.write("\3\34\7\34\u0101\n\34\f\34\16\34\u0104\13\34\3\35\3\35")
        buf.write("\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35")
        buf.write("\3\35\3\35\3\35\3\35\5\35\u0117\n\35\3\35\3\35\3\35\3")
        buf.write("\35\3\35\3\35\3\35\3\35\3\35\7\35\u0122\n\35\f\35\16\35")
        buf.write("\u0125\13\35\3\36\3\36\3\37\3\37\3\37\2\38 \2\4\6\b\n")
        buf.write("\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62\64\668:<")
        buf.write("\2\r\3\29:\3\2\23\25\3\2\61\66\3\2\f\r\4\2**,,\4\2++-")
        buf.write("-\3\2\3\4\4\2\67\6799\3\2\5\6\4\2\t\13\17\17\3\2\27%\2")
        buf.write("\u0134\2A\3\2\2\2\4T\3\2\2\2\6j\3\2\2\2\bm\3\2\2\2\no")
        buf.write("\3\2\2\2\fr\3\2\2\2\16t\3\2\2\2\20y\3\2\2\2\22{\3\2\2")
        buf.write("\2\24\u0084\3\2\2\2\26\u0087\3\2\2\2\30\u008e\3\2\2\2")
        buf.write("\32\u009d\3\2\2\2\34\u00a1\3\2\2\2\36\u00a3\3\2\2\2 \u00a5")
        buf.write("\3\2\2\2\"\u00a7\3\2\2\2$\u00a9\3\2\2\2&\u00b7\3\2\2\2")
        buf.write("(\u00ba\3\2\2\2*\u00c4\3\2\2\2,\u00d7\3\2\2\2.\u00d9\3")
        buf.write("\2\2\2\60\u00db\3\2\2\2\62\u00f5\3\2\2\2\64\u00fb\3\2")
        buf.write("\2\2\66\u00fd\3\2\2\28\u0116\3\2\2\2:\u0126\3\2\2\2<\u0128")
        buf.write("\3\2\2\2>@\7\20\2\2?>\3\2\2\2@C\3\2\2\2A?\3\2\2\2AB\3")
        buf.write("\2\2\2BD\3\2\2\2CA\3\2\2\2DH\5\4\3\2EG\7\20\2\2FE\3\2")
        buf.write("\2\2GJ\3\2\2\2HF\3\2\2\2HI\3\2\2\2IK\3\2\2\2JH\3\2\2\2")
        buf.write("KO\5\24\13\2LN\7\20\2\2ML\3\2\2\2NQ\3\2\2\2OM\3\2\2\2")
        buf.write("OP\3\2\2\2PR\3\2\2\2QO\3\2\2\2RS\7\2\2\3S\3\3\2\2\2TV")
        buf.write("\5\6\4\2UW\7\20\2\2VU\3\2\2\2WX\3\2\2\2XV\3\2\2\2XY\3")
        buf.write("\2\2\2YZ\3\2\2\2Z\\\5\n\6\2[]\7\20\2\2\\[\3\2\2\2]^\3")
        buf.write("\2\2\2^\\\3\2\2\2^_\3\2\2\2_a\3\2\2\2`b\5\16\b\2a`\3\2")
        buf.write("\2\2ab\3\2\2\2bg\3\2\2\2cf\7\20\2\2df\5\22\n\2ec\3\2\2")
        buf.write("\2ed\3\2\2\2fi\3\2\2\2ge\3\2\2\2gh\3\2\2\2h\5\3\2\2\2")
        buf.write("ig\3\2\2\2jk\7\23\2\2kl\5\b\5\2l\7\3\2\2\2mn\79\2\2n\t")
        buf.write("\3\2\2\2op\7\24\2\2pq\5\f\7\2q\13\3\2\2\2rs\7\n\2\2s\r")
        buf.write("\3\2\2\2tu\7\25\2\2uw\5\20\t\2vx\5\60\31\2wv\3\2\2\2w")
        buf.write("x\3\2\2\2x\17\3\2\2\2yz\t\2\2\2z\21\3\2\2\2{|\7\26\2\2")
        buf.write("|}\7\f\2\2}\23\3\2\2\2~\u0083\7\20\2\2\177\u0083\5\26")
        buf.write("\f\2\u0080\u0083\5\30\r\2\u0081\u0083\5*\26\2\u0082~\3")
        buf.write("\2\2\2\u0082\177\3\2\2\2\u0082\u0080\3\2\2\2\u0082\u0081")
        buf.write("\3\2\2\2\u0083\u0086\3\2\2\2\u0084\u0082\3\2\2\2\u0084")
        buf.write("\u0085\3\2\2\2\u0085\25\3\2\2\2\u0086\u0084\3\2\2\2\u0087")
        buf.write("\u0088\5 \21\2\u0088\u0089\5\32\16\2\u0089\u008c\7\b\2")
        buf.write("\2\u008a\u008d\58\35\2\u008b\u008d\5\"\22\2\u008c\u008a")
        buf.write("\3\2\2\2\u008c\u008b\3\2\2\2\u008d\27\3\2\2\2\u008e\u008f")
        buf.write("\5 \21\2\u008f\u0090\7\61\2\2\u0090\u0095\5\32\16\2\u0091")
        buf.write("\u0092\7,\2\2\u0092\u0093\5$\23\2\u0093\u0094\7-\2\2\u0094")
        buf.write("\u0096\3\2\2\2\u0095\u0091\3\2\2\2\u0095\u0096\3\2\2\2")
        buf.write("\u0096\u0097\3\2\2\2\u0097\u0098\7\b\2\2\u0098\u0099\7")
        buf.write("\20\2\2\u0099\u009a\5&\24\2\u009a\31\3\2\2\2\u009b\u009e")
        buf.write("\5\34\17\2\u009c\u009e\79\2\2\u009d\u009b\3\2\2\2\u009d")
        buf.write("\u009c\3\2\2\2\u009e\33\3\2\2\2\u009f\u00a2\7\67\2\2\u00a0")
        buf.write("\u00a2\5\36\20\2\u00a1\u009f\3\2\2\2\u00a1\u00a0\3\2\2")
        buf.write("\2\u00a2\35\3\2\2\2\u00a3\u00a4\t\3\2\2\u00a4\37\3\2\2")
        buf.write("\2\u00a5\u00a6\t\4\2\2\u00a6!\3\2\2\2\u00a7\u00a8\t\5")
        buf.write("\2\2\u00a8#\3\2\2\2\u00a9\u00ae\7\t\2\2\u00aa\u00ab\7")
        buf.write("\'\2\2\u00ab\u00ad\7\t\2\2\u00ac\u00aa\3\2\2\2\u00ad\u00b0")
        buf.write("\3\2\2\2\u00ae\u00ac\3\2\2\2\u00ae\u00af\3\2\2\2\u00af")
        buf.write("%\3\2\2\2\u00b0\u00ae\3\2\2\2\u00b1\u00b2\7\21\2\2\u00b2")
        buf.write("\u00b3\5(\25\2\u00b3\u00b4\7\20\2\2\u00b4\u00b6\3\2\2")
        buf.write("\2\u00b5\u00b1\3\2\2\2\u00b6\u00b9\3\2\2\2\u00b7\u00b5")
        buf.write("\3\2\2\2\u00b7\u00b8\3\2\2\2\u00b8\'\3\2\2\2\u00b9\u00b7")
        buf.write("\3\2\2\2\u00ba\u00bf\58\35\2\u00bb\u00bc\7\'\2\2\u00bc")
        buf.write("\u00be\58\35\2\u00bd\u00bb\3\2\2\2\u00be\u00c1\3\2\2\2")
        buf.write("\u00bf\u00bd\3\2\2\2\u00bf\u00c0\3\2\2\2\u00c0)\3\2\2")
        buf.write("\2\u00c1\u00bf\3\2\2\2\u00c2\u00c5\5,\27\2\u00c3\u00c5")
        buf.write("\5.\30\2\u00c4\u00c2\3\2\2\2\u00c4\u00c3\3\2\2\2\u00c5")
        buf.write("\u00c7\3\2\2\2\u00c6\u00c8\5\60\31\2\u00c7\u00c6\3\2\2")
        buf.write("\2\u00c7\u00c8\3\2\2\2\u00c8\u00c9\3\2\2\2\u00c9\u00cb")
        buf.write("\7\60\2\2\u00ca\u00cc\t\6\2\2\u00cb\u00ca\3\2\2\2\u00cb")
        buf.write("\u00cc\3\2\2\2\u00cc\u00cd\3\2\2\2\u00cd\u00cf\5\66\34")
        buf.write("\2\u00ce\u00d0\t\7\2\2\u00cf\u00ce\3\2\2\2\u00cf\u00d0")
        buf.write("\3\2\2\2\u00d0\u00d4\3\2\2\2\u00d1\u00d3\7\20\2\2\u00d2")
        buf.write("\u00d1\3\2\2\2\u00d3\u00d6\3\2\2\2\u00d4\u00d2\3\2\2\2")
        buf.write("\u00d4\u00d5\3\2\2\2\u00d5+\3\2\2\2\u00d6\u00d4\3\2\2")
        buf.write("\2\u00d7\u00d8\79\2\2\u00d8-\3\2\2\2\u00d9\u00da\78\2")
        buf.write("\2\u00da/\3\2\2\2\u00db\u00e4\7*\2\2\u00dc\u00e1\5\64")
        buf.write("\33\2\u00dd\u00de\7\'\2\2\u00de\u00e0\5\64\33\2\u00df")
        buf.write("\u00dd\3\2\2\2\u00e0\u00e3\3\2\2\2\u00e1\u00df\3\2\2\2")
        buf.write("\u00e1\u00e2\3\2\2\2\u00e2\u00e5\3\2\2\2\u00e3\u00e1\3")
        buf.write("\2\2\2\u00e4\u00dc\3\2\2\2\u00e4\u00e5\3\2\2\2\u00e5\u00e7")
        buf.write("\3\2\2\2\u00e6\u00e8\7\'\2\2\u00e7\u00e6\3\2\2\2\u00e7")
        buf.write("\u00e8\3\2\2\2\u00e8\u00f1\3\2\2\2\u00e9\u00ee\5\62\32")
        buf.write("\2\u00ea\u00eb\7\'\2\2\u00eb\u00ed\5\62\32\2\u00ec\u00ea")
        buf.write("\3\2\2\2\u00ed\u00f0\3\2\2\2\u00ee\u00ec\3\2\2\2\u00ee")
        buf.write("\u00ef\3\2\2\2\u00ef\u00f2\3\2\2\2\u00f0\u00ee\3\2\2\2")
        buf.write("\u00f1\u00e9\3\2\2\2\u00f1\u00f2\3\2\2\2\u00f2\u00f3\3")
        buf.write("\2\2\2\u00f3\u00f4\7+\2\2\u00f4\61\3\2\2\2\u00f5\u00f6")
        buf.write("\79\2\2\u00f6\u00f7\7\b\2\2\u00f7\u00f8\5\64\33\2\u00f8")
        buf.write("\63\3\2\2\2\u00f9\u00fc\5\"\22\2\u00fa\u00fc\58\35\2\u00fb")
        buf.write("\u00f9\3\2\2\2\u00fb\u00fa\3\2\2\2\u00fc\65\3\2\2\2\u00fd")
        buf.write("\u0102\7\t\2\2\u00fe\u00ff\7\'\2\2\u00ff\u0101\7\t\2\2")
        buf.write("\u0100\u00fe\3\2\2\2\u0101\u0104\3\2\2\2\u0102\u0100\3")
        buf.write("\2\2\2\u0102\u0103\3\2\2\2\u0103\67\3\2\2\2\u0104\u0102")
        buf.write("\3\2\2\2\u0105\u0106\b\35\1\2\u0106\u0107\7*\2\2\u0107")
        buf.write("\u0108\58\35\2\u0108\u0109\7+\2\2\u0109\u0117\3\2\2\2")
        buf.write("\u010a\u010b\t\b\2\2\u010b\u0117\58\35\n\u010c\u010d\5")
        buf.write("<\37\2\u010d\u010e\7*\2\2\u010e\u010f\58\35\2\u010f\u0110")
        buf.write("\7+\2\2\u0110\u0117\3\2\2\2\u0111\u0117\5:\36\2\u0112")
        buf.write("\u0117\t\t\2\2\u0113\u0114\7.\2\2\u0114\u0115\79\2\2\u0115")
        buf.write("\u0117\7/\2\2\u0116\u0105\3\2\2\2\u0116\u010a\3\2\2\2")
        buf.write("\u0116\u010c\3\2\2\2\u0116\u0111\3\2\2\2\u0116\u0112\3")
        buf.write("\2\2\2\u0116\u0113\3\2\2\2\u0117\u0123\3\2\2\2\u0118\u0119")
        buf.write("\f\t\2\2\u0119\u011a\7\7\2\2\u011a\u0122\58\35\t\u011b")
        buf.write("\u011c\f\b\2\2\u011c\u011d\t\n\2\2\u011d\u0122\58\35\t")
        buf.write("\u011e\u011f\f\7\2\2\u011f\u0120\t\b\2\2\u0120\u0122\5")
        buf.write("8\35\b\u0121\u0118\3\2\2\2\u0121\u011b\3\2\2\2\u0121\u011e")
        buf.write("\3\2\2\2\u0122\u0125\3\2\2\2\u0123\u0121\3\2\2\2\u0123")
        buf.write("\u0124\3\2\2\2\u01249\3\2\2\2\u0125\u0123\3\2\2\2\u0126")
        buf.write("\u0127\t\13\2\2\u0127;\3\2\2\2\u0128\u0129\t\f\2\2\u0129")
        buf.write("=\3\2\2\2#AHOX^aegw\u0082\u0084\u008c\u0095\u009d\u00a1")
        buf.write("\u00ae\u00b7\u00bf\u00c4\u00c7\u00cb\u00cf\u00d4\u00e1")
        buf.write("\u00e4\u00e7\u00ee\u00f1\u00fb\u0102\u0116\u0121\u0123")
        return buf.getvalue()


class blackbirdParser ( Parser ):

    grammarFileName = "blackbird.g4"

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

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

    sharedContextCache = PredictionContextCache()

    literalNames = [ "<INVALID>", "'+'", "'-'", "'*'", "'/'", "'**'", "'='", 
                     "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 
                     "<INVALID>", "<INVALID>", "'pi'", "<INVALID>", "<INVALID>", 
                     "<INVALID>", "'name'", "'version'", "'target'", "'include'", 
                     "'sqrt'", "'sin'", "'cos'", "'tan'", "'arcsin'", "'arccos'", 
                     "'arctan'", "'sinh'", "'cosh'", "'tanh'", "'arcsinh'", 
                     "'arccosh'", "'arctanh'", "'exp'", "'log'", "'.'", 
                     "','", "':'", "'\"'", "'('", "')'", "'['", "']'", "'{'", 
                     "'}'", "'|'", "'array'", "'float'", "'complex'", "'int'", 
                     "'str'", "'bool'" ]

    symbolicNames = [ "<INVALID>", "PLUS", "MINUS", "TIMES", "DIVIDE", "PWR", 
                      "ASSIGN", "INT", "FLOAT", "COMPLEX", "STR", "BOOL", 
                      "SEQUENCE", "PI", "NEWLINE", "TAB", "SPACE", "PROGNAME", 
                      "VERSION", "TARGET", "INCLUDE", "SQRT", "SIN", "COS", 
                      "TAN", "ARCSIN", "ARCCOS", "ARCTAN", "SINH", "COSH", 
                      "TANH", "ARCSINH", "ARCCOSH", "ARCTANH", "EXP", "LOG", 
                      "PERIOD", "COMMA", "COLON", "QUOTE", "LBRAC", "RBRAC", 
                      "LSQBRAC", "RSQBRAC", "LBRACE", "RBRACE", "APPLY", 
                      "TYPE_ARRAY", "TYPE_FLOAT", "TYPE_COMPLEX", "TYPE_INT", 
                      "TYPE_STR", "TYPE_BOOL", "REGREF", "MEASURE", "NAME", 
                      "DEVICE", "COMMENT", "ANY" ]

    RULE_start = 0
    RULE_metadatablock = 1
    RULE_declarename = 2
    RULE_programname = 3
    RULE_version = 4
    RULE_versionnumber = 5
    RULE_target = 6
    RULE_device = 7
    RULE_include = 8
    RULE_program = 9
    RULE_expressionvar = 10
    RULE_arrayvar = 11
    RULE_name = 12
    RULE_invalid = 13
    RULE_reserved = 14
    RULE_vartype = 15
    RULE_nonnumeric = 16
    RULE_shape = 17
    RULE_arrayval = 18
    RULE_arrayrow = 19
    RULE_statement = 20
    RULE_operation = 21
    RULE_measure = 22
    RULE_arguments = 23
    RULE_kwarg = 24
    RULE_val = 25
    RULE_modes = 26
    RULE_expression = 27
    RULE_number = 28
    RULE_function = 29

    ruleNames =  [ "start", "metadatablock", "declarename", "programname", 
                   "version", "versionnumber", "target", "device", "include", 
                   "program", "expressionvar", "arrayvar", "name", "invalid", 
                   "reserved", "vartype", "nonnumeric", "shape", "arrayval", 
                   "arrayrow", "statement", "operation", "measure", "arguments", 
                   "kwarg", "val", "modes", "expression", "number", "function" ]

    EOF = Token.EOF
    PLUS=1
    MINUS=2
    TIMES=3
    DIVIDE=4
    PWR=5
    ASSIGN=6
    INT=7
    FLOAT=8
    COMPLEX=9
    STR=10
    BOOL=11
    SEQUENCE=12
    PI=13
    NEWLINE=14
    TAB=15
    SPACE=16
    PROGNAME=17
    VERSION=18
    TARGET=19
    INCLUDE=20
    SQRT=21
    SIN=22
    COS=23
    TAN=24
    ARCSIN=25
    ARCCOS=26
    ARCTAN=27
    SINH=28
    COSH=29
    TANH=30
    ARCSINH=31
    ARCCOSH=32
    ARCTANH=33
    EXP=34
    LOG=35
    PERIOD=36
    COMMA=37
    COLON=38
    QUOTE=39
    LBRAC=40
    RBRAC=41
    LSQBRAC=42
    RSQBRAC=43
    LBRACE=44
    RBRACE=45
    APPLY=46
    TYPE_ARRAY=47
    TYPE_FLOAT=48
    TYPE_COMPLEX=49
    TYPE_INT=50
    TYPE_STR=51
    TYPE_BOOL=52
    REGREF=53
    MEASURE=54
    NAME=55
    DEVICE=56
    COMMENT=57
    ANY=58

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



    class StartContext(ParserRuleContext):

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

        def metadatablock(self):
            return self.getTypedRuleContext(blackbirdParser.MetadatablockContext,0)


        def program(self):
            return self.getTypedRuleContext(blackbirdParser.ProgramContext,0)


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

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

        def getRuleIndex(self):
            return blackbirdParser.RULE_start

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

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




    def start(self):

        localctx = blackbirdParser.StartContext(self, self._ctx, self.state)
        self.enterRule(localctx, 0, self.RULE_start)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 63
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==blackbirdParser.NEWLINE:
                self.state = 60
                self.match(blackbirdParser.NEWLINE)
                self.state = 65
                self._errHandler.sync(self)
                _la = self._input.LA(1)

            self.state = 66
            self.metadatablock()
            self.state = 70
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,1,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 67
                    self.match(blackbirdParser.NEWLINE) 
                self.state = 72
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,1,self._ctx)

            self.state = 73
            self.program()
            self.state = 77
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==blackbirdParser.NEWLINE:
                self.state = 74
                self.match(blackbirdParser.NEWLINE)
                self.state = 79
                self._errHandler.sync(self)
                _la = self._input.LA(1)

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

    class MetadatablockContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser
            self._include = None # IncludeContext
            self.include_list = list() # of IncludeContexts

        def declarename(self):
            return self.getTypedRuleContext(blackbirdParser.DeclarenameContext,0)


        def version(self):
            return self.getTypedRuleContext(blackbirdParser.VersionContext,0)


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

        def target(self):
            return self.getTypedRuleContext(blackbirdParser.TargetContext,0)


        def include(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(blackbirdParser.IncludeContext)
            else:
                return self.getTypedRuleContext(blackbirdParser.IncludeContext,i)


        def getRuleIndex(self):
            return blackbirdParser.RULE_metadatablock

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

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




    def metadatablock(self):

        localctx = blackbirdParser.MetadatablockContext(self, self._ctx, self.state)
        self.enterRule(localctx, 2, self.RULE_metadatablock)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 82
            self.declarename()
            self.state = 84 
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while True:
                self.state = 83
                self.match(blackbirdParser.NEWLINE)
                self.state = 86 
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                if not (_la==blackbirdParser.NEWLINE):
                    break

            self.state = 88
            self.version()
            self.state = 90 
            self._errHandler.sync(self)
            _alt = 1
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt == 1:
                    self.state = 89
                    self.match(blackbirdParser.NEWLINE)

                else:
                    raise NoViableAltException(self)
                self.state = 92 
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,4,self._ctx)

            self.state = 95
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.TARGET:
                self.state = 94
                self.target()


            self.state = 101
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,7,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 99
                    self._errHandler.sync(self)
                    token = self._input.LA(1)
                    if token in [blackbirdParser.NEWLINE]:
                        self.state = 97
                        self.match(blackbirdParser.NEWLINE)
                        pass
                    elif token in [blackbirdParser.INCLUDE]:
                        self.state = 98
                        localctx._include = self.include()
                        localctx.include_list.append(localctx._include)
                        pass
                    else:
                        raise NoViableAltException(self)
             
                self.state = 103
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,7,self._ctx)

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

    class DeclarenameContext(ParserRuleContext):

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

        def PROGNAME(self):
            return self.getToken(blackbirdParser.PROGNAME, 0)

        def programname(self):
            return self.getTypedRuleContext(blackbirdParser.ProgramnameContext,0)


        def getRuleIndex(self):
            return blackbirdParser.RULE_declarename

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

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




    def declarename(self):

        localctx = blackbirdParser.DeclarenameContext(self, self._ctx, self.state)
        self.enterRule(localctx, 4, self.RULE_declarename)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 104
            self.match(blackbirdParser.PROGNAME)
            self.state = 105
            self.programname()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ProgramnameContext(ParserRuleContext):

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

        def NAME(self):
            return self.getToken(blackbirdParser.NAME, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_programname

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

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




    def programname(self):

        localctx = blackbirdParser.ProgramnameContext(self, self._ctx, self.state)
        self.enterRule(localctx, 6, self.RULE_programname)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 107
            self.match(blackbirdParser.NAME)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class VersionContext(ParserRuleContext):

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

        def VERSION(self):
            return self.getToken(blackbirdParser.VERSION, 0)

        def versionnumber(self):
            return self.getTypedRuleContext(blackbirdParser.VersionnumberContext,0)


        def getRuleIndex(self):
            return blackbirdParser.RULE_version

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

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




    def version(self):

        localctx = blackbirdParser.VersionContext(self, self._ctx, self.state)
        self.enterRule(localctx, 8, self.RULE_version)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 109
            self.match(blackbirdParser.VERSION)
            self.state = 110
            self.versionnumber()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class VersionnumberContext(ParserRuleContext):

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

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

        def getRuleIndex(self):
            return blackbirdParser.RULE_versionnumber

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

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




    def versionnumber(self):

        localctx = blackbirdParser.VersionnumberContext(self, self._ctx, self.state)
        self.enterRule(localctx, 10, self.RULE_versionnumber)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 112
            self.match(blackbirdParser.FLOAT)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class TargetContext(ParserRuleContext):

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

        def TARGET(self):
            return self.getToken(blackbirdParser.TARGET, 0)

        def device(self):
            return self.getTypedRuleContext(blackbirdParser.DeviceContext,0)


        def arguments(self):
            return self.getTypedRuleContext(blackbirdParser.ArgumentsContext,0)


        def getRuleIndex(self):
            return blackbirdParser.RULE_target

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

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




    def target(self):

        localctx = blackbirdParser.TargetContext(self, self._ctx, self.state)
        self.enterRule(localctx, 12, self.RULE_target)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 114
            self.match(blackbirdParser.TARGET)
            self.state = 115
            self.device()
            self.state = 117
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.LBRAC:
                self.state = 116
                self.arguments()


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

    class DeviceContext(ParserRuleContext):

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

        def NAME(self):
            return self.getToken(blackbirdParser.NAME, 0)

        def DEVICE(self):
            return self.getToken(blackbirdParser.DEVICE, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_device

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

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




    def device(self):

        localctx = blackbirdParser.DeviceContext(self, self._ctx, self.state)
        self.enterRule(localctx, 14, self.RULE_device)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 119
            _la = self._input.LA(1)
            if not(_la==blackbirdParser.NAME or _la==blackbirdParser.DEVICE):
                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 IncludeContext(ParserRuleContext):

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

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

        def STR(self):
            return self.getToken(blackbirdParser.STR, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_include

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

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




    def include(self):

        localctx = blackbirdParser.IncludeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 16, self.RULE_include)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 121
            self.match(blackbirdParser.INCLUDE)
            self.state = 122
            self.match(blackbirdParser.STR)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ProgramContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser
            self._expressionvar = None # ExpressionvarContext
            self.var_list = list() # of ExpressionvarContexts
            self._arrayvar = None # ArrayvarContext
            self.array_list = list() # of ArrayvarContexts
            self._statement = None # StatementContext
            self.statement_list = list() # of StatementContexts

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

        def expressionvar(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(blackbirdParser.ExpressionvarContext)
            else:
                return self.getTypedRuleContext(blackbirdParser.ExpressionvarContext,i)


        def arrayvar(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(blackbirdParser.ArrayvarContext)
            else:
                return self.getTypedRuleContext(blackbirdParser.ArrayvarContext,i)


        def statement(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(blackbirdParser.StatementContext)
            else:
                return self.getTypedRuleContext(blackbirdParser.StatementContext,i)


        def getRuleIndex(self):
            return blackbirdParser.RULE_program

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

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




    def program(self):

        localctx = blackbirdParser.ProgramContext(self, self._ctx, self.state)
        self.enterRule(localctx, 18, self.RULE_program)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 130
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,10,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 128
                    self._errHandler.sync(self)
                    la_ = self._interp.adaptivePredict(self._input,9,self._ctx)
                    if la_ == 1:
                        self.state = 124
                        self.match(blackbirdParser.NEWLINE)
                        pass

                    elif la_ == 2:
                        self.state = 125
                        localctx._expressionvar = self.expressionvar()
                        localctx.var_list.append(localctx._expressionvar)
                        pass

                    elif la_ == 3:
                        self.state = 126
                        localctx._arrayvar = self.arrayvar()
                        localctx.array_list.append(localctx._arrayvar)
                        pass

                    elif la_ == 4:
                        self.state = 127
                        localctx._statement = self.statement()
                        localctx.statement_list.append(localctx._statement)
                        pass

             
                self.state = 132
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,10,self._ctx)

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

    class ExpressionvarContext(ParserRuleContext):

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

        def vartype(self):
            return self.getTypedRuleContext(blackbirdParser.VartypeContext,0)


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


        def ASSIGN(self):
            return self.getToken(blackbirdParser.ASSIGN, 0)

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


        def nonnumeric(self):
            return self.getTypedRuleContext(blackbirdParser.NonnumericContext,0)


        def getRuleIndex(self):
            return blackbirdParser.RULE_expressionvar

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

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




    def expressionvar(self):

        localctx = blackbirdParser.ExpressionvarContext(self, self._ctx, self.state)
        self.enterRule(localctx, 20, self.RULE_expressionvar)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 133
            self.vartype()
            self.state = 134
            self.name()
            self.state = 135
            self.match(blackbirdParser.ASSIGN)
            self.state = 138
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [blackbirdParser.PLUS, blackbirdParser.MINUS, blackbirdParser.INT, blackbirdParser.FLOAT, blackbirdParser.COMPLEX, blackbirdParser.PI, blackbirdParser.SQRT, blackbirdParser.SIN, blackbirdParser.COS, blackbirdParser.TAN, blackbirdParser.ARCSIN, blackbirdParser.ARCCOS, blackbirdParser.ARCTAN, blackbirdParser.SINH, blackbirdParser.COSH, blackbirdParser.TANH, blackbirdParser.ARCSINH, blackbirdParser.ARCCOSH, blackbirdParser.ARCTANH, blackbirdParser.EXP, blackbirdParser.LOG, blackbirdParser.LBRAC, blackbirdParser.LBRACE, blackbirdParser.REGREF, blackbirdParser.NAME]:
                self.state = 136
                self.expression(0)
                pass
            elif token in [blackbirdParser.STR, blackbirdParser.BOOL]:
                self.state = 137
                self.nonnumeric()
                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 ArrayvarContext(ParserRuleContext):

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

        def vartype(self):
            return self.getTypedRuleContext(blackbirdParser.VartypeContext,0)


        def TYPE_ARRAY(self):
            return self.getToken(blackbirdParser.TYPE_ARRAY, 0)

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


        def ASSIGN(self):
            return self.getToken(blackbirdParser.ASSIGN, 0)

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

        def arrayval(self):
            return self.getTypedRuleContext(blackbirdParser.ArrayvalContext,0)


        def LSQBRAC(self):
            return self.getToken(blackbirdParser.LSQBRAC, 0)

        def shape(self):
            return self.getTypedRuleContext(blackbirdParser.ShapeContext,0)


        def RSQBRAC(self):
            return self.getToken(blackbirdParser.RSQBRAC, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_arrayvar

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

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




    def arrayvar(self):

        localctx = blackbirdParser.ArrayvarContext(self, self._ctx, self.state)
        self.enterRule(localctx, 22, self.RULE_arrayvar)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 140
            self.vartype()
            self.state = 141
            self.match(blackbirdParser.TYPE_ARRAY)
            self.state = 142
            self.name()
            self.state = 147
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.LSQBRAC:
                self.state = 143
                self.match(blackbirdParser.LSQBRAC)
                self.state = 144
                self.shape()
                self.state = 145
                self.match(blackbirdParser.RSQBRAC)


            self.state = 149
            self.match(blackbirdParser.ASSIGN)
            self.state = 150
            self.match(blackbirdParser.NEWLINE)
            self.state = 151
            self.arrayval()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class NameContext(ParserRuleContext):

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

        def invalid(self):
            return self.getTypedRuleContext(blackbirdParser.InvalidContext,0)


        def NAME(self):
            return self.getToken(blackbirdParser.NAME, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_name

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

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




    def name(self):

        localctx = blackbirdParser.NameContext(self, self._ctx, self.state)
        self.enterRule(localctx, 24, self.RULE_name)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 155
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [blackbirdParser.PROGNAME, blackbirdParser.VERSION, blackbirdParser.TARGET, blackbirdParser.REGREF]:
                self.state = 153
                self.invalid()
                pass
            elif token in [blackbirdParser.NAME]:
                self.state = 154
                self.match(blackbirdParser.NAME)
                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 InvalidContext(ParserRuleContext):

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

        def REGREF(self):
            return self.getToken(blackbirdParser.REGREF, 0)

        def reserved(self):
            return self.getTypedRuleContext(blackbirdParser.ReservedContext,0)


        def getRuleIndex(self):
            return blackbirdParser.RULE_invalid

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

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




    def invalid(self):

        localctx = blackbirdParser.InvalidContext(self, self._ctx, self.state)
        self.enterRule(localctx, 26, self.RULE_invalid)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 159
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [blackbirdParser.REGREF]:
                self.state = 157
                self.match(blackbirdParser.REGREF)
                pass
            elif token in [blackbirdParser.PROGNAME, blackbirdParser.VERSION, blackbirdParser.TARGET]:
                self.state = 158
                self.reserved()
                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 ReservedContext(ParserRuleContext):

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

        def PROGNAME(self):
            return self.getToken(blackbirdParser.PROGNAME, 0)

        def VERSION(self):
            return self.getToken(blackbirdParser.VERSION, 0)

        def TARGET(self):
            return self.getToken(blackbirdParser.TARGET, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_reserved

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

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




    def reserved(self):

        localctx = blackbirdParser.ReservedContext(self, self._ctx, self.state)
        self.enterRule(localctx, 28, self.RULE_reserved)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 161
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << blackbirdParser.PROGNAME) | (1 << blackbirdParser.VERSION) | (1 << blackbirdParser.TARGET))) != 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 VartypeContext(ParserRuleContext):

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

        def TYPE_ARRAY(self):
            return self.getToken(blackbirdParser.TYPE_ARRAY, 0)

        def TYPE_FLOAT(self):
            return self.getToken(blackbirdParser.TYPE_FLOAT, 0)

        def TYPE_COMPLEX(self):
            return self.getToken(blackbirdParser.TYPE_COMPLEX, 0)

        def TYPE_INT(self):
            return self.getToken(blackbirdParser.TYPE_INT, 0)

        def TYPE_STR(self):
            return self.getToken(blackbirdParser.TYPE_STR, 0)

        def TYPE_BOOL(self):
            return self.getToken(blackbirdParser.TYPE_BOOL, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_vartype

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

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




    def vartype(self):

        localctx = blackbirdParser.VartypeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 30, self.RULE_vartype)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 163
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << blackbirdParser.TYPE_ARRAY) | (1 << blackbirdParser.TYPE_FLOAT) | (1 << blackbirdParser.TYPE_COMPLEX) | (1 << blackbirdParser.TYPE_INT) | (1 << blackbirdParser.TYPE_STR) | (1 << blackbirdParser.TYPE_BOOL))) != 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 NonnumericContext(ParserRuleContext):

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

        def STR(self):
            return self.getToken(blackbirdParser.STR, 0)

        def BOOL(self):
            return self.getToken(blackbirdParser.BOOL, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_nonnumeric

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

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




    def nonnumeric(self):

        localctx = blackbirdParser.NonnumericContext(self, self._ctx, self.state)
        self.enterRule(localctx, 32, self.RULE_nonnumeric)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 165
            _la = self._input.LA(1)
            if not(_la==blackbirdParser.STR or _la==blackbirdParser.BOOL):
                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 ShapeContext(ParserRuleContext):

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

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

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

        def getRuleIndex(self):
            return blackbirdParser.RULE_shape

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

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




    def shape(self):

        localctx = blackbirdParser.ShapeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 34, self.RULE_shape)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 167
            self.match(blackbirdParser.INT)
            self.state = 172
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==blackbirdParser.COMMA:
                self.state = 168
                self.match(blackbirdParser.COMMA)
                self.state = 169
                self.match(blackbirdParser.INT)
                self.state = 174
                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 ArrayvalContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser
            self._arrayrow = None # ArrayrowContext
            self.row_list = list() # of ArrayrowContexts

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

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

        def arrayrow(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(blackbirdParser.ArrayrowContext)
            else:
                return self.getTypedRuleContext(blackbirdParser.ArrayrowContext,i)


        def getRuleIndex(self):
            return blackbirdParser.RULE_arrayval

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

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




    def arrayval(self):

        localctx = blackbirdParser.ArrayvalContext(self, self._ctx, self.state)
        self.enterRule(localctx, 36, self.RULE_arrayval)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 181
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==blackbirdParser.TAB:
                self.state = 175
                self.match(blackbirdParser.TAB)
                self.state = 176
                localctx._arrayrow = self.arrayrow()
                localctx.row_list.append(localctx._arrayrow)
                self.state = 177
                self.match(blackbirdParser.NEWLINE)
                self.state = 183
                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 ArrayrowContext(ParserRuleContext):

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

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


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

        def getRuleIndex(self):
            return blackbirdParser.RULE_arrayrow

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

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




    def arrayrow(self):

        localctx = blackbirdParser.ArrayrowContext(self, self._ctx, self.state)
        self.enterRule(localctx, 38, self.RULE_arrayrow)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 184
            self.expression(0)
            self.state = 189
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==blackbirdParser.COMMA:
                self.state = 185
                self.match(blackbirdParser.COMMA)
                self.state = 186
                self.expression(0)
                self.state = 191
                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 StatementContext(ParserRuleContext):

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

        def APPLY(self):
            return self.getToken(blackbirdParser.APPLY, 0)

        def modes(self):
            return self.getTypedRuleContext(blackbirdParser.ModesContext,0)


        def operation(self):
            return self.getTypedRuleContext(blackbirdParser.OperationContext,0)


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


        def arguments(self):
            return self.getTypedRuleContext(blackbirdParser.ArgumentsContext,0)


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

        def LBRAC(self):
            return self.getToken(blackbirdParser.LBRAC, 0)

        def LSQBRAC(self):
            return self.getToken(blackbirdParser.LSQBRAC, 0)

        def RBRAC(self):
            return self.getToken(blackbirdParser.RBRAC, 0)

        def RSQBRAC(self):
            return self.getToken(blackbirdParser.RSQBRAC, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_statement

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

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




    def statement(self):

        localctx = blackbirdParser.StatementContext(self, self._ctx, self.state)
        self.enterRule(localctx, 40, self.RULE_statement)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 194
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [blackbirdParser.NAME]:
                self.state = 192
                self.operation()
                pass
            elif token in [blackbirdParser.MEASURE]:
                self.state = 193
                self.measure()
                pass
            else:
                raise NoViableAltException(self)

            self.state = 197
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.LBRAC:
                self.state = 196
                self.arguments()


            self.state = 199
            self.match(blackbirdParser.APPLY)
            self.state = 201
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.LBRAC or _la==blackbirdParser.LSQBRAC:
                self.state = 200
                _la = self._input.LA(1)
                if not(_la==blackbirdParser.LBRAC or _la==blackbirdParser.LSQBRAC):
                    self._errHandler.recoverInline(self)
                else:
                    self._errHandler.reportMatch(self)
                    self.consume()


            self.state = 203
            self.modes()
            self.state = 205
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.RBRAC or _la==blackbirdParser.RSQBRAC:
                self.state = 204
                _la = self._input.LA(1)
                if not(_la==blackbirdParser.RBRAC or _la==blackbirdParser.RSQBRAC):
                    self._errHandler.recoverInline(self)
                else:
                    self._errHandler.reportMatch(self)
                    self.consume()


            self.state = 210
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,22,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 207
                    self.match(blackbirdParser.NEWLINE) 
                self.state = 212
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,22,self._ctx)

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

    class OperationContext(ParserRuleContext):

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

        def NAME(self):
            return self.getToken(blackbirdParser.NAME, 0)

        def getRuleIndex(self):
            return blackbirdParser.RULE_operation

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

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




    def operation(self):

        localctx = blackbirdParser.OperationContext(self, self._ctx, self.state)
        self.enterRule(localctx, 42, self.RULE_operation)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 213
            self.match(blackbirdParser.NAME)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class MeasureContext(ParserRuleContext):

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

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

        def getRuleIndex(self):
            return blackbirdParser.RULE_measure

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

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




    def measure(self):

        localctx = blackbirdParser.MeasureContext(self, self._ctx, self.state)
        self.enterRule(localctx, 44, self.RULE_measure)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 215
            self.match(blackbirdParser.MEASURE)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ArgumentsContext(ParserRuleContext):

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser
            self._val = None # ValContext
            self.val_list = list() # of ValContexts
            self._kwarg = None # KwargContext
            self.kwarg_list = list() # of KwargContexts

        def LBRAC(self):
            return self.getToken(blackbirdParser.LBRAC, 0)

        def RBRAC(self):
            return self.getToken(blackbirdParser.RBRAC, 0)

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

        def val(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(blackbirdParser.ValContext)
            else:
                return self.getTypedRuleContext(blackbirdParser.ValContext,i)


        def kwarg(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(blackbirdParser.KwargContext)
            else:
                return self.getTypedRuleContext(blackbirdParser.KwargContext,i)


        def getRuleIndex(self):
            return blackbirdParser.RULE_arguments

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

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




    def arguments(self):

        localctx = blackbirdParser.ArgumentsContext(self, self._ctx, self.state)
        self.enterRule(localctx, 46, self.RULE_arguments)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 217
            self.match(blackbirdParser.LBRAC)
            self.state = 226
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,24,self._ctx)
            if la_ == 1:
                self.state = 218
                localctx._val = self.val()
                localctx.val_list.append(localctx._val)
                self.state = 223
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,23,self._ctx)
                while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                    if _alt==1:
                        self.state = 219
                        self.match(blackbirdParser.COMMA)
                        self.state = 220
                        localctx._val = self.val()
                        localctx.val_list.append(localctx._val) 
                    self.state = 225
                    self._errHandler.sync(self)
                    _alt = self._interp.adaptivePredict(self._input,23,self._ctx)



            self.state = 229
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.COMMA:
                self.state = 228
                self.match(blackbirdParser.COMMA)


            self.state = 239
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if _la==blackbirdParser.NAME:
                self.state = 231
                localctx._kwarg = self.kwarg()
                localctx.kwarg_list.append(localctx._kwarg)
                self.state = 236
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==blackbirdParser.COMMA:
                    self.state = 232
                    self.match(blackbirdParser.COMMA)
                    self.state = 233
                    localctx._kwarg = self.kwarg()
                    localctx.kwarg_list.append(localctx._kwarg)
                    self.state = 238
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)



            self.state = 241
            self.match(blackbirdParser.RBRAC)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class KwargContext(ParserRuleContext):

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

        def NAME(self):
            return self.getToken(blackbirdParser.NAME, 0)

        def ASSIGN(self):
            return self.getToken(blackbirdParser.ASSIGN, 0)

        def val(self):
            return self.getTypedRuleContext(blackbirdParser.ValContext,0)


        def getRuleIndex(self):
            return blackbirdParser.RULE_kwarg

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

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




    def kwarg(self):

        localctx = blackbirdParser.KwargContext(self, self._ctx, self.state)
        self.enterRule(localctx, 48, self.RULE_kwarg)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 243
            self.match(blackbirdParser.NAME)
            self.state = 244
            self.match(blackbirdParser.ASSIGN)
            self.state = 245
            self.val()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ValContext(ParserRuleContext):

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

        def nonnumeric(self):
            return self.getTypedRuleContext(blackbirdParser.NonnumericContext,0)


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


        def getRuleIndex(self):
            return blackbirdParser.RULE_val

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

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




    def val(self):

        localctx = blackbirdParser.ValContext(self, self._ctx, self.state)
        self.enterRule(localctx, 50, self.RULE_val)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 249
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [blackbirdParser.STR, blackbirdParser.BOOL]:
                self.state = 247
                self.nonnumeric()
                pass
            elif token in [blackbirdParser.PLUS, blackbirdParser.MINUS, blackbirdParser.INT, blackbirdParser.FLOAT, blackbirdParser.COMPLEX, blackbirdParser.PI, blackbirdParser.SQRT, blackbirdParser.SIN, blackbirdParser.COS, blackbirdParser.TAN, blackbirdParser.ARCSIN, blackbirdParser.ARCCOS, blackbirdParser.ARCTAN, blackbirdParser.SINH, blackbirdParser.COSH, blackbirdParser.TANH, blackbirdParser.ARCSINH, blackbirdParser.ARCCOSH, blackbirdParser.ARCTANH, blackbirdParser.EXP, blackbirdParser.LOG, blackbirdParser.LBRAC, blackbirdParser.LBRACE, blackbirdParser.REGREF, blackbirdParser.NAME]:
                self.state = 248
                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 ModesContext(ParserRuleContext):

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

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

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

        def getRuleIndex(self):
            return blackbirdParser.RULE_modes

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

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




    def modes(self):

        localctx = blackbirdParser.ModesContext(self, self._ctx, self.state)
        self.enterRule(localctx, 52, self.RULE_modes)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 251
            self.match(blackbirdParser.INT)
            self.state = 256
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while _la==blackbirdParser.COMMA:
                self.state = 252
                self.match(blackbirdParser.COMMA)
                self.state = 253
                self.match(blackbirdParser.INT)
                self.state = 258
                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 ExpressionContext(ParserRuleContext):

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


        def getRuleIndex(self):
            return blackbirdParser.RULE_expression

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


    class ParameterLabelContext(ExpressionContext):

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

        def LBRACE(self):
            return self.getToken(blackbirdParser.LBRACE, 0)
        def NAME(self):
            return self.getToken(blackbirdParser.NAME, 0)
        def RBRACE(self):
            return self.getToken(blackbirdParser.RBRACE, 0)

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

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


    class BracketsLabelContext(ExpressionContext):

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

        def LBRAC(self):
            return self.getToken(blackbirdParser.LBRAC, 0)
        def expression(self):
            return self.getTypedRuleContext(blackbirdParser.ExpressionContext,0)

        def RBRAC(self):
            return self.getToken(blackbirdParser.RBRAC, 0)

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

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


    class SignLabelContext(ExpressionContext):

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

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

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

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

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


    class PowerLabelContext(ExpressionContext):

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

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

        def PWR(self):
            return self.getToken(blackbirdParser.PWR, 0)

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

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


    class NumberLabelContext(ExpressionContext):

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

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


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

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


    class VariableLabelContext(ExpressionContext):

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

        def REGREF(self):
            return self.getToken(blackbirdParser.REGREF, 0)
        def NAME(self):
            return self.getToken(blackbirdParser.NAME, 0)

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

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


    class MulLabelContext(ExpressionContext):

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

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

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

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

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


    class FunctionLabelContext(ExpressionContext):

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

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

        def LBRAC(self):
            return self.getToken(blackbirdParser.LBRAC, 0)
        def expression(self):
            return self.getTypedRuleContext(blackbirdParser.ExpressionContext,0)

        def RBRAC(self):
            return self.getToken(blackbirdParser.RBRAC, 0)

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

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


    class AddLabelContext(ExpressionContext):

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

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

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

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

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



    def expression(self, _p:int=0):
        _parentctx = self._ctx
        _parentState = self.state
        localctx = blackbirdParser.ExpressionContext(self, self._ctx, _parentState)
        _prevctx = localctx
        _startState = 54
        self.enterRecursionRule(localctx, 54, self.RULE_expression, _p)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 276
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [blackbirdParser.LBRAC]:
                localctx = blackbirdParser.BracketsLabelContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx

                self.state = 260
                self.match(blackbirdParser.LBRAC)
                self.state = 261
                self.expression(0)
                self.state = 262
                self.match(blackbirdParser.RBRAC)
                pass
            elif token in [blackbirdParser.PLUS, blackbirdParser.MINUS]:
                localctx = blackbirdParser.SignLabelContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 264
                _la = self._input.LA(1)
                if not(_la==blackbirdParser.PLUS or _la==blackbirdParser.MINUS):
                    self._errHandler.recoverInline(self)
                else:
                    self._errHandler.reportMatch(self)
                    self.consume()
                self.state = 265
                self.expression(8)
                pass
            elif token in [blackbirdParser.SQRT, blackbirdParser.SIN, blackbirdParser.COS, blackbirdParser.TAN, blackbirdParser.ARCSIN, blackbirdParser.ARCCOS, blackbirdParser.ARCTAN, blackbirdParser.SINH, blackbirdParser.COSH, blackbirdParser.TANH, blackbirdParser.ARCSINH, blackbirdParser.ARCCOSH, blackbirdParser.ARCTANH, blackbirdParser.EXP, blackbirdParser.LOG]:
                localctx = blackbirdParser.FunctionLabelContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 266
                self.function()
                self.state = 267
                self.match(blackbirdParser.LBRAC)
                self.state = 268
                self.expression(0)
                self.state = 269
                self.match(blackbirdParser.RBRAC)
                pass
            elif token in [blackbirdParser.INT, blackbirdParser.FLOAT, blackbirdParser.COMPLEX, blackbirdParser.PI]:
                localctx = blackbirdParser.NumberLabelContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 271
                self.number()
                pass
            elif token in [blackbirdParser.REGREF, blackbirdParser.NAME]:
                localctx = blackbirdParser.VariableLabelContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 272
                _la = self._input.LA(1)
                if not(_la==blackbirdParser.REGREF or _la==blackbirdParser.NAME):
                    self._errHandler.recoverInline(self)
                else:
                    self._errHandler.reportMatch(self)
                    self.consume()
                pass
            elif token in [blackbirdParser.LBRACE]:
                localctx = blackbirdParser.ParameterLabelContext(self, localctx)
                self._ctx = localctx
                _prevctx = localctx
                self.state = 273
                self.match(blackbirdParser.LBRACE)
                self.state = 274
                self.match(blackbirdParser.NAME)
                self.state = 275
                self.match(blackbirdParser.RBRACE)
                pass
            else:
                raise NoViableAltException(self)

            self._ctx.stop = self._input.LT(-1)
            self.state = 289
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,32,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 = 287
                    self._errHandler.sync(self)
                    la_ = self._interp.adaptivePredict(self._input,31,self._ctx)
                    if la_ == 1:
                        localctx = blackbirdParser.PowerLabelContext(self, blackbirdParser.ExpressionContext(self, _parentctx, _parentState))
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expression)
                        self.state = 278
                        if not self.precpred(self._ctx, 7):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 7)")
                        self.state = 279
                        self.match(blackbirdParser.PWR)
                        self.state = 280
                        self.expression(7)
                        pass

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

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

             
                self.state = 291
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,32,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 NumberContext(ParserRuleContext):

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

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

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

        def COMPLEX(self):
            return self.getToken(blackbirdParser.COMPLEX, 0)

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

        def getRuleIndex(self):
            return blackbirdParser.RULE_number

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

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




    def number(self):

        localctx = blackbirdParser.NumberContext(self, self._ctx, self.state)
        self.enterRule(localctx, 56, self.RULE_number)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 292
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << blackbirdParser.INT) | (1 << blackbirdParser.FLOAT) | (1 << blackbirdParser.COMPLEX) | (1 << blackbirdParser.PI))) != 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 FunctionContext(ParserRuleContext):

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

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

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

        def TAN(self):
            return self.getToken(blackbirdParser.TAN, 0)

        def ARCSIN(self):
            return self.getToken(blackbirdParser.ARCSIN, 0)

        def ARCCOS(self):
            return self.getToken(blackbirdParser.ARCCOS, 0)

        def ARCTAN(self):
            return self.getToken(blackbirdParser.ARCTAN, 0)

        def SINH(self):
            return self.getToken(blackbirdParser.SINH, 0)

        def COSH(self):
            return self.getToken(blackbirdParser.COSH, 0)

        def TANH(self):
            return self.getToken(blackbirdParser.TANH, 0)

        def ARCSINH(self):
            return self.getToken(blackbirdParser.ARCSINH, 0)

        def ARCCOSH(self):
            return self.getToken(blackbirdParser.ARCCOSH, 0)

        def ARCTANH(self):
            return self.getToken(blackbirdParser.ARCTANH, 0)

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

        def LOG(self):
            return self.getToken(blackbirdParser.LOG, 0)

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

        def getRuleIndex(self):
            return blackbirdParser.RULE_function

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

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




    def function(self):

        localctx = blackbirdParser.FunctionContext(self, self._ctx, self.state)
        self.enterRule(localctx, 58, self.RULE_function)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 294
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << blackbirdParser.SQRT) | (1 << blackbirdParser.SIN) | (1 << blackbirdParser.COS) | (1 << blackbirdParser.TAN) | (1 << blackbirdParser.ARCSIN) | (1 << blackbirdParser.ARCCOS) | (1 << blackbirdParser.ARCTAN) | (1 << blackbirdParser.SINH) | (1 << blackbirdParser.COSH) | (1 << blackbirdParser.TANH) | (1 << blackbirdParser.ARCSINH) | (1 << blackbirdParser.ARCCOSH) | (1 << blackbirdParser.ARCTANH) | (1 << blackbirdParser.EXP) | (1 << blackbirdParser.LOG))) != 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



    def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int):
        if self._predicates == None:
            self._predicates = dict()
        self._predicates[27] = self.expression_sempred
        pred = self._predicates.get(ruleIndex, None)
        if pred is None:
            raise Exception("No predicate with index:" + str(ruleIndex))
        else:
            return pred(localctx, predIndex)

    def expression_sempred(self, localctx:ExpressionContext, predIndex:int):
            if predIndex == 0:
                return self.precpred(self._ctx, 7)
         

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

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




