From d9ffc2f3f679bf6e87cf12dc1ed9809badf673da Mon Sep 17 00:00:00 2001 From: Erik Oosting Date: Tue, 12 Dec 2023 15:20:56 +0100 Subject: start working on actual visitor --- gen/ANFParser.py | 207 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 140 insertions(+), 67 deletions(-) (limited to 'gen/ANFParser.py') diff --git a/gen/ANFParser.py b/gen/ANFParser.py index b26614b..2b7df41 100644 --- a/gen/ANFParser.py +++ b/gen/ANFParser.py @@ -10,44 +10,49 @@ else: def serializedATN(): return [ - 4,1,24,116,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, + 4,1,28,130,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, - 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,3,0,89,8,0,1,1,1,1,1,1, - 1,1,1,1,5,1,96,8,1,10,1,12,1,99,9,1,1,1,1,1,1,1,3,1,104,8,1,1,2, - 1,2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,114,8,2,1,2,0,0,3,0,2,4,0,0,131, - 0,88,1,0,0,0,2,103,1,0,0,0,4,113,1,0,0,0,6,89,5,1,0,0,7,89,5,2,0, - 0,8,89,5,22,0,0,9,89,5,23,0,0,10,11,5,3,0,0,11,12,3,0,0,0,12,13, - 5,4,0,0,13,14,3,0,0,0,14,15,5,5,0,0,15,89,1,0,0,0,16,17,5,3,0,0, - 17,18,3,0,0,0,18,19,5,6,0,0,19,20,3,0,0,0,20,21,5,5,0,0,21,89,1, + 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,5,0,87,8,0,10,0,12,0,90,9,0,1, + 0,1,0,1,0,1,0,3,0,96,8,0,1,1,1,1,1,1,1,1,1,1,5,1,103,8,1,10,1,12, + 1,106,9,1,1,1,1,1,1,1,3,1,111,8,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,128,8,2,1,2,0,0,3,0,2,4,0,0,147, + 0,95,1,0,0,0,2,110,1,0,0,0,4,127,1,0,0,0,6,96,5,1,0,0,7,96,5,2,0, + 0,8,96,5,25,0,0,9,96,5,26,0,0,10,11,5,3,0,0,11,12,3,0,0,0,12,13, + 5,4,0,0,13,14,3,0,0,0,14,15,5,5,0,0,15,96,1,0,0,0,16,17,5,3,0,0, + 17,18,3,0,0,0,18,19,5,6,0,0,19,20,3,0,0,0,20,21,5,5,0,0,21,96,1, 0,0,0,22,23,5,3,0,0,23,24,3,0,0,0,24,25,5,7,0,0,25,26,3,0,0,0,26, - 27,5,5,0,0,27,89,1,0,0,0,28,29,5,3,0,0,29,30,3,0,0,0,30,31,5,8,0, - 0,31,32,3,0,0,0,32,33,5,5,0,0,33,89,1,0,0,0,34,35,5,3,0,0,35,36, - 3,0,0,0,36,37,5,9,0,0,37,38,3,0,0,0,38,39,5,5,0,0,39,89,1,0,0,0, + 27,5,5,0,0,27,96,1,0,0,0,28,29,5,3,0,0,29,30,3,0,0,0,30,31,5,8,0, + 0,31,32,3,0,0,0,32,33,5,5,0,0,33,96,1,0,0,0,34,35,5,3,0,0,35,36, + 3,0,0,0,36,37,5,9,0,0,37,38,3,0,0,0,38,39,5,5,0,0,39,96,1,0,0,0, 40,41,5,3,0,0,41,42,3,0,0,0,42,43,5,10,0,0,43,44,3,0,0,0,44,45,5, - 5,0,0,45,89,1,0,0,0,46,47,5,3,0,0,47,48,3,0,0,0,48,49,5,11,0,0,49, - 50,3,0,0,0,50,51,5,5,0,0,51,89,1,0,0,0,52,53,5,3,0,0,53,54,3,0,0, - 0,54,55,5,12,0,0,55,56,3,0,0,0,56,57,5,5,0,0,57,89,1,0,0,0,58,59, + 5,0,0,45,96,1,0,0,0,46,47,5,3,0,0,47,48,3,0,0,0,48,49,5,11,0,0,49, + 50,3,0,0,0,50,51,5,5,0,0,51,96,1,0,0,0,52,53,5,3,0,0,53,54,3,0,0, + 0,54,55,5,12,0,0,55,56,3,0,0,0,56,57,5,5,0,0,57,96,1,0,0,0,58,59, 5,3,0,0,59,60,3,0,0,0,60,61,5,13,0,0,61,62,3,0,0,0,62,63,5,5,0,0, - 63,89,1,0,0,0,64,65,5,3,0,0,65,66,3,0,0,0,66,67,5,14,0,0,67,68,3, - 0,0,0,68,69,5,5,0,0,69,89,1,0,0,0,70,71,5,3,0,0,71,72,3,0,0,0,72, - 73,5,15,0,0,73,74,3,0,0,0,74,75,5,5,0,0,75,89,1,0,0,0,76,77,5,3, + 63,96,1,0,0,0,64,65,5,3,0,0,65,66,3,0,0,0,66,67,5,14,0,0,67,68,3, + 0,0,0,68,69,5,5,0,0,69,96,1,0,0,0,70,71,5,3,0,0,71,72,3,0,0,0,72, + 73,5,15,0,0,73,74,3,0,0,0,74,75,5,5,0,0,75,96,1,0,0,0,76,77,5,3, 0,0,77,78,3,0,0,0,78,79,5,16,0,0,79,80,3,0,0,0,80,81,5,5,0,0,81, - 89,1,0,0,0,82,83,5,3,0,0,83,84,5,22,0,0,84,85,5,17,0,0,85,86,3,4, - 2,0,86,87,5,5,0,0,87,89,1,0,0,0,88,6,1,0,0,0,88,7,1,0,0,0,88,8,1, - 0,0,0,88,9,1,0,0,0,88,10,1,0,0,0,88,16,1,0,0,0,88,22,1,0,0,0,88, - 28,1,0,0,0,88,34,1,0,0,0,88,40,1,0,0,0,88,46,1,0,0,0,88,52,1,0,0, - 0,88,58,1,0,0,0,88,64,1,0,0,0,88,70,1,0,0,0,88,76,1,0,0,0,88,82, - 1,0,0,0,89,1,1,0,0,0,90,91,5,22,0,0,91,92,5,3,0,0,92,97,3,0,0,0, - 93,94,5,18,0,0,94,96,3,0,0,0,95,93,1,0,0,0,96,99,1,0,0,0,97,95,1, - 0,0,0,97,98,1,0,0,0,98,100,1,0,0,0,99,97,1,0,0,0,100,101,5,5,0,0, - 101,104,1,0,0,0,102,104,3,0,0,0,103,90,1,0,0,0,103,102,1,0,0,0,104, - 3,1,0,0,0,105,106,5,19,0,0,106,107,5,22,0,0,107,108,5,20,0,0,108, - 109,3,2,1,0,109,110,5,21,0,0,110,111,3,4,2,0,111,114,1,0,0,0,112, - 114,3,2,1,0,113,105,1,0,0,0,113,112,1,0,0,0,114,5,1,0,0,0,4,88,97, - 103,113 + 96,1,0,0,0,82,83,5,3,0,0,83,88,5,25,0,0,84,85,5,17,0,0,85,87,5,25, + 0,0,86,84,1,0,0,0,87,90,1,0,0,0,88,86,1,0,0,0,88,89,1,0,0,0,89,91, + 1,0,0,0,90,88,1,0,0,0,91,92,5,18,0,0,92,93,3,4,2,0,93,94,5,5,0,0, + 94,96,1,0,0,0,95,6,1,0,0,0,95,7,1,0,0,0,95,8,1,0,0,0,95,9,1,0,0, + 0,95,10,1,0,0,0,95,16,1,0,0,0,95,22,1,0,0,0,95,28,1,0,0,0,95,34, + 1,0,0,0,95,40,1,0,0,0,95,46,1,0,0,0,95,52,1,0,0,0,95,58,1,0,0,0, + 95,64,1,0,0,0,95,70,1,0,0,0,95,76,1,0,0,0,95,82,1,0,0,0,96,1,1,0, + 0,0,97,98,5,25,0,0,98,99,5,3,0,0,99,104,3,0,0,0,100,101,5,17,0,0, + 101,103,3,0,0,0,102,100,1,0,0,0,103,106,1,0,0,0,104,102,1,0,0,0, + 104,105,1,0,0,0,105,107,1,0,0,0,106,104,1,0,0,0,107,108,5,5,0,0, + 108,111,1,0,0,0,109,111,3,0,0,0,110,97,1,0,0,0,110,109,1,0,0,0,111, + 3,1,0,0,0,112,113,5,19,0,0,113,114,5,25,0,0,114,115,5,20,0,0,115, + 116,3,2,1,0,116,117,5,21,0,0,117,118,3,4,2,0,118,128,1,0,0,0,119, + 120,5,22,0,0,120,121,3,0,0,0,121,122,5,23,0,0,122,123,3,4,2,0,123, + 124,5,24,0,0,124,125,3,4,2,0,125,128,1,0,0,0,126,128,3,2,1,0,127, + 112,1,0,0,0,127,119,1,0,0,0,127,126,1,0,0,0,128,5,1,0,0,0,5,88,95, + 104,110,127 ] class ANFParser ( Parser ): @@ -62,15 +67,16 @@ class ANFParser ( Parser ): literalNames = [ "", "'true'", "'false'", "'('", "'+'", "')'", "'-'", "'*'", "'/'", "'>'", "'<'", "'=='", "'<<'", - "'>>'", "'&&'", "'||'", "'^^'", "':'", "','", "'let'", - "'='", "'in'" ] + "'>>'", "'&&'", "'||'", "'^^'", "','", "':'", "'let'", + "'='", "'in'", "'if'", "'then'", "'else'" ] symbolicNames = [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "IDENT", "NUMBER", "WS" ] + "", "", "", "", + "", "IDENT", "NUMBER", "STRING", "WS" ] RULE_aexp = 0 RULE_funcall = 1 @@ -100,9 +106,13 @@ class ANFParser ( Parser ): T__18=19 T__19=20 T__20=21 - IDENT=22 - NUMBER=23 - WS=24 + T__21=22 + T__22=23 + T__23=24 + IDENT=25 + NUMBER=26 + STRING=27 + WS=28 def __init__(self, input:TokenStream, output:TextIO = sys.stdout): super().__init__(input, output) @@ -508,8 +518,11 @@ class ANFParser ( Parser ): super().__init__(parser) self.copyFrom(ctx) - def IDENT(self): - return self.getToken(ANFParser.IDENT, 0) + def IDENT(self, i:int=None): + if i is None: + return self.getTokens(ANFParser.IDENT) + else: + return self.getToken(ANFParser.IDENT, i) def cexp(self): return self.getTypedRuleContext(ANFParser.CexpContext,0) @@ -590,10 +603,11 @@ class ANFParser ( Parser ): localctx = ANFParser.AexpContext(self, self._ctx, self.state) self.enterRule(localctx, 0, self.RULE_aexp) + self._la = 0 # Token type try: - self.state = 88 + self.state = 95 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,0,self._ctx) + la_ = self._interp.adaptivePredict(self._input,1,self._ctx) if la_ == 1: localctx = ANFParser.TrueContext(self, localctx) self.enterOuterAlt(localctx, 1) @@ -809,11 +823,23 @@ class ANFParser ( Parser ): self.match(ANFParser.T__2) self.state = 83 self.match(ANFParser.IDENT) - self.state = 84 - self.match(ANFParser.T__16) - self.state = 85 + self.state = 88 + self._errHandler.sync(self) + _la = self._input.LA(1) + while _la==17: + self.state = 84 + self.match(ANFParser.T__16) + self.state = 85 + self.match(ANFParser.IDENT) + self.state = 90 + self._errHandler.sync(self) + _la = self._input.LA(1) + + self.state = 91 + self.match(ANFParser.T__17) + self.state = 92 self.cexp() - self.state = 86 + self.state = 93 self.match(ANFParser.T__4) pass @@ -906,38 +932,38 @@ class ANFParser ( Parser ): self.enterRule(localctx, 2, self.RULE_funcall) self._la = 0 # Token type try: - self.state = 103 + self.state = 110 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,2,self._ctx) + la_ = self._interp.adaptivePredict(self._input,3,self._ctx) if la_ == 1: localctx = ANFParser.CallContext(self, localctx) self.enterOuterAlt(localctx, 1) - self.state = 90 + self.state = 97 self.match(ANFParser.IDENT) - self.state = 91 + self.state = 98 self.match(ANFParser.T__2) - self.state = 92 + self.state = 99 self.aexp() - self.state = 97 + self.state = 104 self._errHandler.sync(self) _la = self._input.LA(1) - while _la==18: - self.state = 93 - self.match(ANFParser.T__17) - self.state = 94 + while _la==17: + self.state = 100 + self.match(ANFParser.T__16) + self.state = 101 self.aexp() - self.state = 99 + self.state = 106 self._errHandler.sync(self) _la = self._input.LA(1) - self.state = 100 + self.state = 107 self.match(ANFParser.T__4) pass elif la_ == 2: localctx = ANFParser.AtomContext(self, localctx) self.enterOuterAlt(localctx, 2) - self.state = 102 + self.state = 109 self.aexp() pass @@ -998,6 +1024,37 @@ class ANFParser ( Parser ): return visitor.visitChildren(self) + class IfContext(CexpContext): + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.CexpContext + super().__init__(parser) + self.copyFrom(ctx) + + def aexp(self): + return self.getTypedRuleContext(ANFParser.AexpContext,0) + + def cexp(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(ANFParser.CexpContext) + else: + return self.getTypedRuleContext(ANFParser.CexpContext,i) + + + def enterRule(self, listener:ParseTreeListener): + if hasattr( listener, "enterIf" ): + listener.enterIf(self) + + def exitRule(self, listener:ParseTreeListener): + if hasattr( listener, "exitIf" ): + listener.exitIf(self) + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitIf" ): + return visitor.visitIf(self) + else: + return visitor.visitChildren(self) + + class FcContext(CexpContext): def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.CexpContext @@ -1029,29 +1086,45 @@ class ANFParser ( Parser ): localctx = ANFParser.CexpContext(self, self._ctx, self.state) self.enterRule(localctx, 4, self.RULE_cexp) try: - self.state = 113 + self.state = 127 self._errHandler.sync(self) token = self._input.LA(1) if token in [19]: localctx = ANFParser.LetContext(self, localctx) self.enterOuterAlt(localctx, 1) - self.state = 105 + self.state = 112 self.match(ANFParser.T__18) - self.state = 106 + self.state = 113 self.match(ANFParser.IDENT) - self.state = 107 + self.state = 114 self.match(ANFParser.T__19) - self.state = 108 + self.state = 115 self.funcall() - self.state = 109 + self.state = 116 self.match(ANFParser.T__20) - self.state = 110 + self.state = 117 self.cexp() pass - elif token in [1, 2, 3, 22, 23]: - localctx = ANFParser.FcContext(self, localctx) + elif token in [22]: + localctx = ANFParser.IfContext(self, localctx) self.enterOuterAlt(localctx, 2) - self.state = 112 + self.state = 119 + self.match(ANFParser.T__21) + self.state = 120 + self.aexp() + self.state = 121 + self.match(ANFParser.T__22) + self.state = 122 + self.cexp() + self.state = 123 + self.match(ANFParser.T__23) + self.state = 124 + self.cexp() + pass + elif token in [1, 2, 3, 25, 26]: + localctx = ANFParser.FcContext(self, localctx) + self.enterOuterAlt(localctx, 3) + self.state = 126 self.funcall() pass else: -- cgit 1.4.1-2-gfad0