Created
September 12, 2013 20:24
-
-
Save joyjding/6543240 to your computer and use it in GitHub Desktop.
This is some of the main parsing machinery that underlies Spot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse(): | |
global scope | |
scope = Scope() | |
advance() #to put the first token in | |
p = Program() | |
p.statementd() | |
return p | |
class Program: | |
def statementd(self): | |
self.children = statement_list() | |
return self | |
def eval(self, env): | |
for mini_selves in self.children: | |
mini_selves.eval(env) | |
def codegen(self): | |
code = [] | |
functions = [] | |
remainder = [] | |
for statement in self.children: | |
if isinstance(statement, DefineNewFuncTok): | |
functions.append(statement) | |
else: | |
remainder.append(statement) | |
# code.extend(statement.codegen()) | |
for f in functions: | |
code.extend(f.codegen()) | |
code.append("mystart:") | |
for line in remainder: | |
code.extend(line.codegen()) | |
return code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment