# Generated from BenLang.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("\u009a\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\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2")
        buf.write("\5\2)\n\2\3\3\7\3,\n\3\f\3\16\3/\13\3\3\4\3\4\3\5\3\5")
        buf.write("\3\6\3\6\3\6\3\6\3\6\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3")
        buf.write("\b\3\b\3\b\3\b\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t")
        buf.write("\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\3\13\3\13")
        buf.write("\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13")
        buf.write("\3\13\3\13\3\13\5\13k\n\13\3\13\3\13\3\13\3\13\3\13\3")
        buf.write("\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13")
        buf.write("\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\7\13\u0085\n")
        buf.write("\13\f\13\16\13\u0088\13\13\3\f\3\f\3\f\3\r\3\r\5\r\u008f")
        buf.write("\n\r\3\r\3\r\3\16\3\16\3\16\3\16\3\16\5\16\u0098\n\16")
        buf.write("\3\16\2\3\24\17\2\4\6\b\n\f\16\20\22\24\26\30\32\2\3\3")
        buf.write("\2\b\n\2\u00a5\2(\3\2\2\2\4-\3\2\2\2\6\60\3\2\2\2\b\62")
        buf.write("\3\2\2\2\n\64\3\2\2\2\f9\3\2\2\2\16=\3\2\2\2\20E\3\2\2")
        buf.write("\2\22Q\3\2\2\2\24j\3\2\2\2\26\u0089\3\2\2\2\30\u008c\3")
        buf.write("\2\2\2\32\u0097\3\2\2\2\34\35\5\24\13\2\35\36\7 \2\2\36")
        buf.write(")\3\2\2\2\37)\5\22\n\2 )\5\20\t\2!)\5\16\b\2\"#\5\n\6")
        buf.write("\2#$\7 \2\2$)\3\2\2\2%&\5\f\7\2&\'\7 \2\2\')\3\2\2\2(")
        buf.write("\34\3\2\2\2(\37\3\2\2\2( \3\2\2\2(!\3\2\2\2(\"\3\2\2\2")
        buf.write("(%\3\2\2\2)\3\3\2\2\2*,\5\2\2\2+*\3\2\2\2,/\3\2\2\2-+")
        buf.write("\3\2\2\2-.\3\2\2\2.\5\3\2\2\2/-\3\2\2\2\60\61\5\4\3\2")
        buf.write("\61\7\3\2\2\2\62\63\t\2\2\2\63\t\3\2\2\2\64\65\5\b\5\2")
        buf.write("\65\66\7\27\2\2\66\67\7\3\2\2\678\5\24\13\28\13\3\2\2")
        buf.write("\29:\7\27\2\2:;\7\3\2\2;<\5\24\13\2<\r\3\2\2\2=>\7\13")
        buf.write("\2\2>?\7\30\2\2?@\5\24\13\2@A\7\31\2\2AB\7\r\2\2BC\5\4")
        buf.write("\3\2CD\7\f\2\2D\17\3\2\2\2EF\7\17\2\2FG\7\30\2\2GH\5\24")
        buf.write("\13\2HI\7\31\2\2IJ\7\r\2\2JK\5\4\3\2KL\7\f\2\2LM\7\16")
        buf.write("\2\2MN\7\r\2\2NO\5\4\3\2OP\7\f\2\2P\21\3\2\2\2QR\7\17")
        buf.write("\2\2RS\7\30\2\2ST\5\24\13\2TU\7\31\2\2UV\7\r\2\2VW\5\4")
        buf.write("\3\2WX\7\f\2\2X\23\3\2\2\2YZ\b\13\1\2Zk\7\26\2\2[k\7\25")
        buf.write("\2\2\\k\7\27\2\2]k\5\26\f\2^k\7\32\2\2_k\7\4\2\2`a\7\22")
        buf.write("\2\2ak\5\24\13\16bc\7\33\2\2ck\5\24\13\rde\7\34\2\2ek")
        buf.write("\5\24\13\ffg\7\30\2\2gh\5\24\13\2hi\7\31\2\2ik\3\2\2\2")
        buf.write("jY\3\2\2\2j[\3\2\2\2j\\\3\2\2\2j]\3\2\2\2j^\3\2\2\2j_")
        buf.write("\3\2\2\2j`\3\2\2\2jb\3\2\2\2jd\3\2\2\2jf\3\2\2\2k\u0086")
        buf.write("\3\2\2\2lm\f\n\2\2mn\7\36\2\2n\u0085\5\24\13\13op\f\t")
        buf.write("\2\2pq\7\35\2\2q\u0085\5\24\13\nrs\f\b\2\2st\7\33\2\2")
        buf.write("t\u0085\5\24\13\tuv\f\7\2\2vw\7\34\2\2w\u0085\5\24\13")
        buf.write("\bxy\f\6\2\2yz\7\20\2\2z\u0085\5\24\13\7{|\f\5\2\2|}\7")
        buf.write("\21\2\2}\u0085\5\24\13\6~\177\f\4\2\2\177\u0080\7\24\2")
        buf.write("\2\u0080\u0085\5\24\13\5\u0081\u0082\f\3\2\2\u0082\u0083")
        buf.write("\7\23\2\2\u0083\u0085\5\24\13\4\u0084l\3\2\2\2\u0084o")
        buf.write("\3\2\2\2\u0084r\3\2\2\2\u0084u\3\2\2\2\u0084x\3\2\2\2")
        buf.write("\u0084{\3\2\2\2\u0084~\3\2\2\2\u0084\u0081\3\2\2\2\u0085")
        buf.write("\u0088\3\2\2\2\u0086\u0084\3\2\2\2\u0086\u0087\3\2\2\2")
        buf.write("\u0087\25\3\2\2\2\u0088\u0086\3\2\2\2\u0089\u008a\7\27")
        buf.write("\2\2\u008a\u008b\5\30\r\2\u008b\27\3\2\2\2\u008c\u008e")
        buf.write("\7\30\2\2\u008d\u008f\5\24\13\2\u008e\u008d\3\2\2\2\u008e")
        buf.write("\u008f\3\2\2\2\u008f\u0090\3\2\2\2\u0090\u0091\5\32\16")
        buf.write("\2\u0091\31\3\2\2\2\u0092\u0093\7\37\2\2\u0093\u0094\5")
        buf.write("\24\13\2\u0094\u0095\5\32\16\2\u0095\u0098\3\2\2\2\u0096")
        buf.write("\u0098\7\31\2\2\u0097\u0092\3\2\2\2\u0097\u0096\3\2\2")
        buf.write("\2\u0098\33\3\2\2\2\t(-j\u0084\u0086\u008e\u0097")
        return buf.getvalue()


class BenLangParser ( Parser ):

    grammarFileName = "BenLang.g4"

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

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

    sharedContextCache = PredictionContextCache()

    literalNames = [ "<INVALID>", "'='", "<INVALID>", "<INVALID>", "'\"'", 
                     "'\\'", "'bool'", "'int'", "'string'", "'while'", "'}'", 
                     "'{'", "'else'", "'if'", "'<'", "'=='", "'!'", "'||'", 
                     "'&&'", "'false'", "'true'", "<INVALID>", "'('", "')'", 
                     "<INVALID>", "'+'", "'-'", "'/'", "'*'", "','", "';'" ]

    symbolicNames = [ "<INVALID>", "EQUALS", "STRING", "ESCAPE_CHAR", "QUOT", 
                      "BACKSLASH", "BOOL_TYPE", "INT_TYPE", "STRING_TYPE", 
                      "WHILE", "RMOUSTACHE", "LMOUSTACHE", "ELSE", "IF", 
                      "OP_LT", "OP_EQ", "OP_NOT", "OP_OR", "OP_AND", "FALSE", 
                      "TRUE", "IDENTIFIER", "LBRACKET", "RBRACKET", "INTEGER", 
                      "PLUS", "MINUS", "DIV", "MULT", "COMMA", "SEMICOLON", 
                      "PLUSMINUS", "WS", "STRING_CHAR", "UNICODE", "ESCAPE" ]

    RULE_statement = 0
    RULE_statementBlock = 1
    RULE_prog = 2
    RULE_aType = 3
    RULE_declaration = 4
    RULE_assignment = 5
    RULE_whileLoop = 6
    RULE_ifElse = 7
    RULE_ifOnly = 8
    RULE_expr = 9
    RULE_application = 10
    RULE_params = 11
    RULE_paramsRest = 12

    ruleNames =  [ "statement", "statementBlock", "prog", "aType", "declaration", 
                   "assignment", "whileLoop", "ifElse", "ifOnly", "expr", 
                   "application", "params", "paramsRest" ]

    EOF = Token.EOF
    EQUALS=1
    STRING=2
    ESCAPE_CHAR=3
    QUOT=4
    BACKSLASH=5
    BOOL_TYPE=6
    INT_TYPE=7
    STRING_TYPE=8
    WHILE=9
    RMOUSTACHE=10
    LMOUSTACHE=11
    ELSE=12
    IF=13
    OP_LT=14
    OP_EQ=15
    OP_NOT=16
    OP_OR=17
    OP_AND=18
    FALSE=19
    TRUE=20
    IDENTIFIER=21
    LBRACKET=22
    RBRACKET=23
    INTEGER=24
    PLUS=25
    MINUS=26
    DIV=27
    MULT=28
    COMMA=29
    SEMICOLON=30
    PLUSMINUS=31
    WS=32
    STRING_CHAR=33
    UNICODE=34
    ESCAPE=35

    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 StatementContext(ParserRuleContext):

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

        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


        def SEMICOLON(self):
            return self.getToken(BenLangParser.SEMICOLON, 0)

        def ifOnly(self):
            return self.getTypedRuleContext(BenLangParser.IfOnlyContext,0)


        def ifElse(self):
            return self.getTypedRuleContext(BenLangParser.IfElseContext,0)


        def whileLoop(self):
            return self.getTypedRuleContext(BenLangParser.WhileLoopContext,0)


        def declaration(self):
            return self.getTypedRuleContext(BenLangParser.DeclarationContext,0)


        def assignment(self):
            return self.getTypedRuleContext(BenLangParser.AssignmentContext,0)


        def getRuleIndex(self):
            return BenLangParser.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 accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitStatement" ):
                return visitor.visitStatement(self)
            else:
                return visitor.visitChildren(self)




    def statement(self):

        localctx = BenLangParser.StatementContext(self, self._ctx, self.state)
        self.enterRule(localctx, 0, self.RULE_statement)
        try:
            self.state = 38
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,0,self._ctx)
            if la_ == 1:
                self.enterOuterAlt(localctx, 1)
                self.state = 26
                self.expr(0)
                self.state = 27
                self.match(BenLangParser.SEMICOLON)
                pass

            elif la_ == 2:
                self.enterOuterAlt(localctx, 2)
                self.state = 29
                self.ifOnly()
                pass

            elif la_ == 3:
                self.enterOuterAlt(localctx, 3)
                self.state = 30
                self.ifElse()
                pass

            elif la_ == 4:
                self.enterOuterAlt(localctx, 4)
                self.state = 31
                self.whileLoop()
                pass

            elif la_ == 5:
                self.enterOuterAlt(localctx, 5)
                self.state = 32
                self.declaration()
                self.state = 33
                self.match(BenLangParser.SEMICOLON)
                pass

            elif la_ == 6:
                self.enterOuterAlt(localctx, 6)
                self.state = 35
                self.assignment()
                self.state = 36
                self.match(BenLangParser.SEMICOLON)
                pass


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

    class StatementBlockContext(ParserRuleContext):

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

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


        def getRuleIndex(self):
            return BenLangParser.RULE_statementBlock

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitStatementBlock" ):
                return visitor.visitStatementBlock(self)
            else:
                return visitor.visitChildren(self)




    def statementBlock(self):

        localctx = BenLangParser.StatementBlockContext(self, self._ctx, self.state)
        self.enterRule(localctx, 2, self.RULE_statementBlock)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 43
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            while (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << BenLangParser.STRING) | (1 << BenLangParser.BOOL_TYPE) | (1 << BenLangParser.INT_TYPE) | (1 << BenLangParser.STRING_TYPE) | (1 << BenLangParser.WHILE) | (1 << BenLangParser.IF) | (1 << BenLangParser.OP_NOT) | (1 << BenLangParser.FALSE) | (1 << BenLangParser.TRUE) | (1 << BenLangParser.IDENTIFIER) | (1 << BenLangParser.LBRACKET) | (1 << BenLangParser.INTEGER) | (1 << BenLangParser.PLUS) | (1 << BenLangParser.MINUS))) != 0):
                self.state = 40
                self.statement()
                self.state = 45
                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 ProgContext(ParserRuleContext):

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

        def statementBlock(self):
            return self.getTypedRuleContext(BenLangParser.StatementBlockContext,0)


        def getRuleIndex(self):
            return BenLangParser.RULE_prog

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitProg" ):
                return visitor.visitProg(self)
            else:
                return visitor.visitChildren(self)




    def prog(self):

        localctx = BenLangParser.ProgContext(self, self._ctx, self.state)
        self.enterRule(localctx, 4, self.RULE_prog)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 46
            self.statementBlock()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ATypeContext(ParserRuleContext):

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

        def BOOL_TYPE(self):
            return self.getToken(BenLangParser.BOOL_TYPE, 0)

        def STRING_TYPE(self):
            return self.getToken(BenLangParser.STRING_TYPE, 0)

        def INT_TYPE(self):
            return self.getToken(BenLangParser.INT_TYPE, 0)

        def getRuleIndex(self):
            return BenLangParser.RULE_aType

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitAType" ):
                return visitor.visitAType(self)
            else:
                return visitor.visitChildren(self)




    def aType(self):

        localctx = BenLangParser.ATypeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 6, self.RULE_aType)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 48
            _la = self._input.LA(1)
            if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << BenLangParser.BOOL_TYPE) | (1 << BenLangParser.INT_TYPE) | (1 << BenLangParser.STRING_TYPE))) != 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 DeclarationContext(ParserRuleContext):

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

        def aType(self):
            return self.getTypedRuleContext(BenLangParser.ATypeContext,0)


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

        def EQUALS(self):
            return self.getToken(BenLangParser.EQUALS, 0)

        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


        def getRuleIndex(self):
            return BenLangParser.RULE_declaration

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitDeclaration" ):
                return visitor.visitDeclaration(self)
            else:
                return visitor.visitChildren(self)




    def declaration(self):

        localctx = BenLangParser.DeclarationContext(self, self._ctx, self.state)
        self.enterRule(localctx, 8, self.RULE_declaration)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 50
            self.aType()
            self.state = 51
            self.match(BenLangParser.IDENTIFIER)
            self.state = 52
            self.match(BenLangParser.EQUALS)
            self.state = 53
            self.expr(0)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class AssignmentContext(ParserRuleContext):

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

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

        def EQUALS(self):
            return self.getToken(BenLangParser.EQUALS, 0)

        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


        def getRuleIndex(self):
            return BenLangParser.RULE_assignment

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitAssignment" ):
                return visitor.visitAssignment(self)
            else:
                return visitor.visitChildren(self)




    def assignment(self):

        localctx = BenLangParser.AssignmentContext(self, self._ctx, self.state)
        self.enterRule(localctx, 10, self.RULE_assignment)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 55
            self.match(BenLangParser.IDENTIFIER)
            self.state = 56
            self.match(BenLangParser.EQUALS)
            self.state = 57
            self.expr(0)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class WhileLoopContext(ParserRuleContext):

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

        def WHILE(self):
            return self.getToken(BenLangParser.WHILE, 0)

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

        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


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

        def LMOUSTACHE(self):
            return self.getToken(BenLangParser.LMOUSTACHE, 0)

        def statementBlock(self):
            return self.getTypedRuleContext(BenLangParser.StatementBlockContext,0)


        def RMOUSTACHE(self):
            return self.getToken(BenLangParser.RMOUSTACHE, 0)

        def getRuleIndex(self):
            return BenLangParser.RULE_whileLoop

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitWhileLoop" ):
                return visitor.visitWhileLoop(self)
            else:
                return visitor.visitChildren(self)




    def whileLoop(self):

        localctx = BenLangParser.WhileLoopContext(self, self._ctx, self.state)
        self.enterRule(localctx, 12, self.RULE_whileLoop)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 59
            self.match(BenLangParser.WHILE)
            self.state = 60
            self.match(BenLangParser.LBRACKET)
            self.state = 61
            self.expr(0)
            self.state = 62
            self.match(BenLangParser.RBRACKET)
            self.state = 63
            self.match(BenLangParser.LMOUSTACHE)
            self.state = 64
            self.statementBlock()
            self.state = 65
            self.match(BenLangParser.RMOUSTACHE)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class IfElseContext(ParserRuleContext):

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

        def IF(self):
            return self.getToken(BenLangParser.IF, 0)

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

        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


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

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

        def statementBlock(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(BenLangParser.StatementBlockContext)
            else:
                return self.getTypedRuleContext(BenLangParser.StatementBlockContext,i)


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

        def ELSE(self):
            return self.getToken(BenLangParser.ELSE, 0)

        def getRuleIndex(self):
            return BenLangParser.RULE_ifElse

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitIfElse" ):
                return visitor.visitIfElse(self)
            else:
                return visitor.visitChildren(self)




    def ifElse(self):

        localctx = BenLangParser.IfElseContext(self, self._ctx, self.state)
        self.enterRule(localctx, 14, self.RULE_ifElse)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 67
            self.match(BenLangParser.IF)
            self.state = 68
            self.match(BenLangParser.LBRACKET)
            self.state = 69
            self.expr(0)
            self.state = 70
            self.match(BenLangParser.RBRACKET)
            self.state = 71
            self.match(BenLangParser.LMOUSTACHE)
            self.state = 72
            self.statementBlock()
            self.state = 73
            self.match(BenLangParser.RMOUSTACHE)
            self.state = 74
            self.match(BenLangParser.ELSE)
            self.state = 75
            self.match(BenLangParser.LMOUSTACHE)
            self.state = 76
            self.statementBlock()
            self.state = 77
            self.match(BenLangParser.RMOUSTACHE)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class IfOnlyContext(ParserRuleContext):

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

        def IF(self):
            return self.getToken(BenLangParser.IF, 0)

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

        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


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

        def LMOUSTACHE(self):
            return self.getToken(BenLangParser.LMOUSTACHE, 0)

        def statementBlock(self):
            return self.getTypedRuleContext(BenLangParser.StatementBlockContext,0)


        def RMOUSTACHE(self):
            return self.getToken(BenLangParser.RMOUSTACHE, 0)

        def getRuleIndex(self):
            return BenLangParser.RULE_ifOnly

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitIfOnly" ):
                return visitor.visitIfOnly(self)
            else:
                return visitor.visitChildren(self)




    def ifOnly(self):

        localctx = BenLangParser.IfOnlyContext(self, self._ctx, self.state)
        self.enterRule(localctx, 16, self.RULE_ifOnly)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 79
            self.match(BenLangParser.IF)
            self.state = 80
            self.match(BenLangParser.LBRACKET)
            self.state = 81
            self.expr(0)
            self.state = 82
            self.match(BenLangParser.RBRACKET)
            self.state = 83
            self.match(BenLangParser.LMOUSTACHE)
            self.state = 84
            self.statementBlock()
            self.state = 85
            self.match(BenLangParser.RMOUSTACHE)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ExprContext(ParserRuleContext):

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

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

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

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

        def application(self):
            return self.getTypedRuleContext(BenLangParser.ApplicationContext,0)


        def INTEGER(self):
            return self.getToken(BenLangParser.INTEGER, 0)

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

        def OP_NOT(self):
            return self.getToken(BenLangParser.OP_NOT, 0)

        def expr(self, i:int=None):
            if i is None:
                return self.getTypedRuleContexts(BenLangParser.ExprContext)
            else:
                return self.getTypedRuleContext(BenLangParser.ExprContext,i)


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

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

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

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

        def OP_LT(self):
            return self.getToken(BenLangParser.OP_LT, 0)

        def OP_EQ(self):
            return self.getToken(BenLangParser.OP_EQ, 0)

        def OP_AND(self):
            return self.getToken(BenLangParser.OP_AND, 0)

        def OP_OR(self):
            return self.getToken(BenLangParser.OP_OR, 0)

        def getRuleIndex(self):
            return BenLangParser.RULE_expr

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitExpr" ):
                return visitor.visitExpr(self)
            else:
                return visitor.visitChildren(self)



    def expr(self, _p:int=0):
        _parentctx = self._ctx
        _parentState = self.state
        localctx = BenLangParser.ExprContext(self, self._ctx, _parentState)
        _prevctx = localctx
        _startState = 18
        self.enterRecursionRule(localctx, 18, self.RULE_expr, _p)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 104
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,2,self._ctx)
            if la_ == 1:
                self.state = 88
                self.match(BenLangParser.TRUE)
                pass

            elif la_ == 2:
                self.state = 89
                self.match(BenLangParser.FALSE)
                pass

            elif la_ == 3:
                self.state = 90
                self.match(BenLangParser.IDENTIFIER)
                pass

            elif la_ == 4:
                self.state = 91
                self.application()
                pass

            elif la_ == 5:
                self.state = 92
                self.match(BenLangParser.INTEGER)
                pass

            elif la_ == 6:
                self.state = 93
                self.match(BenLangParser.STRING)
                pass

            elif la_ == 7:
                self.state = 94
                self.match(BenLangParser.OP_NOT)
                self.state = 95
                self.expr(12)
                pass

            elif la_ == 8:
                self.state = 96
                self.match(BenLangParser.PLUS)
                self.state = 97
                self.expr(11)
                pass

            elif la_ == 9:
                self.state = 98
                self.match(BenLangParser.MINUS)
                self.state = 99
                self.expr(10)
                pass

            elif la_ == 10:
                self.state = 100
                self.match(BenLangParser.LBRACKET)
                self.state = 101
                self.expr(0)
                self.state = 102
                self.match(BenLangParser.RBRACKET)
                pass


            self._ctx.stop = self._input.LT(-1)
            self.state = 132
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,4,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 = 130
                    self._errHandler.sync(self)
                    la_ = self._interp.adaptivePredict(self._input,3,self._ctx)
                    if la_ == 1:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 106
                        if not self.precpred(self._ctx, 8):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 8)")
                        self.state = 107
                        self.match(BenLangParser.MULT)
                        self.state = 108
                        self.expr(9)
                        pass

                    elif la_ == 2:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 109
                        if not self.precpred(self._ctx, 7):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 7)")
                        self.state = 110
                        self.match(BenLangParser.DIV)
                        self.state = 111
                        self.expr(8)
                        pass

                    elif la_ == 3:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 112
                        if not self.precpred(self._ctx, 6):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 6)")
                        self.state = 113
                        self.match(BenLangParser.PLUS)
                        self.state = 114
                        self.expr(7)
                        pass

                    elif la_ == 4:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 115
                        if not self.precpred(self._ctx, 5):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 5)")
                        self.state = 116
                        self.match(BenLangParser.MINUS)
                        self.state = 117
                        self.expr(6)
                        pass

                    elif la_ == 5:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 118
                        if not self.precpred(self._ctx, 4):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 4)")
                        self.state = 119
                        self.match(BenLangParser.OP_LT)
                        self.state = 120
                        self.expr(5)
                        pass

                    elif la_ == 6:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 121
                        if not self.precpred(self._ctx, 3):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 3)")
                        self.state = 122
                        self.match(BenLangParser.OP_EQ)
                        self.state = 123
                        self.expr(4)
                        pass

                    elif la_ == 7:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 124
                        if not self.precpred(self._ctx, 2):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 2)")
                        self.state = 125
                        self.match(BenLangParser.OP_AND)
                        self.state = 126
                        self.expr(3)
                        pass

                    elif la_ == 8:
                        localctx = BenLangParser.ExprContext(self, _parentctx, _parentState)
                        self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
                        self.state = 127
                        if not self.precpred(self._ctx, 1):
                            from antlr4.error.Errors import FailedPredicateException
                            raise FailedPredicateException(self, "self.precpred(self._ctx, 1)")
                        self.state = 128
                        self.match(BenLangParser.OP_OR)
                        self.state = 129
                        self.expr(2)
                        pass

             
                self.state = 134
                self._errHandler.sync(self)
                _alt = self._interp.adaptivePredict(self._input,4,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 ApplicationContext(ParserRuleContext):

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

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

        def params(self):
            return self.getTypedRuleContext(BenLangParser.ParamsContext,0)


        def getRuleIndex(self):
            return BenLangParser.RULE_application

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitApplication" ):
                return visitor.visitApplication(self)
            else:
                return visitor.visitChildren(self)




    def application(self):

        localctx = BenLangParser.ApplicationContext(self, self._ctx, self.state)
        self.enterRule(localctx, 20, self.RULE_application)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 135
            self.match(BenLangParser.IDENTIFIER)
            self.state = 136
            self.params()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class ParamsContext(ParserRuleContext):

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

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

        def paramsRest(self):
            return self.getTypedRuleContext(BenLangParser.ParamsRestContext,0)


        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


        def getRuleIndex(self):
            return BenLangParser.RULE_params

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitParams" ):
                return visitor.visitParams(self)
            else:
                return visitor.visitChildren(self)




    def params(self):

        localctx = BenLangParser.ParamsContext(self, self._ctx, self.state)
        self.enterRule(localctx, 22, self.RULE_params)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 138
            self.match(BenLangParser.LBRACKET)
            self.state = 140
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << BenLangParser.STRING) | (1 << BenLangParser.OP_NOT) | (1 << BenLangParser.FALSE) | (1 << BenLangParser.TRUE) | (1 << BenLangParser.IDENTIFIER) | (1 << BenLangParser.LBRACKET) | (1 << BenLangParser.INTEGER) | (1 << BenLangParser.PLUS) | (1 << BenLangParser.MINUS))) != 0):
                self.state = 139
                self.expr(0)


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

    class ParamsRestContext(ParserRuleContext):

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

        def COMMA(self):
            return self.getToken(BenLangParser.COMMA, 0)

        def expr(self):
            return self.getTypedRuleContext(BenLangParser.ExprContext,0)


        def paramsRest(self):
            return self.getTypedRuleContext(BenLangParser.ParamsRestContext,0)


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

        def getRuleIndex(self):
            return BenLangParser.RULE_paramsRest

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

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

        def accept(self, visitor:ParseTreeVisitor):
            if hasattr( visitor, "visitParamsRest" ):
                return visitor.visitParamsRest(self)
            else:
                return visitor.visitChildren(self)




    def paramsRest(self):

        localctx = BenLangParser.ParamsRestContext(self, self._ctx, self.state)
        self.enterRule(localctx, 24, self.RULE_paramsRest)
        try:
            self.state = 149
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [BenLangParser.COMMA]:
                self.enterOuterAlt(localctx, 1)
                self.state = 144
                self.match(BenLangParser.COMMA)
                self.state = 145
                self.expr(0)
                self.state = 146
                self.paramsRest()
                pass
            elif token in [BenLangParser.RBRACKET]:
                self.enterOuterAlt(localctx, 2)
                self.state = 148
                self.match(BenLangParser.RBRACKET)
                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



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

    def expr_sempred(self, localctx:ExprContext, predIndex:int):
            if predIndex == 0:
                return self.precpred(self._ctx, 8)
         

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

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

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

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

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

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

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




