Skip to content

Instantly share code, notes, and snippets.

@joyjding
Created September 12, 2013 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyjding/6543240 to your computer and use it in GitHub Desktop.
Save joyjding/6543240 to your computer and use it in GitHub Desktop.
This is some of the main parsing machinery that underlies Spot.
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