def _eval_definition(self, expr, env): define_variable( definition.definition_variable(expr), self._eval(definition.definition_value(expr), env), env ) return Symbol('ok')
def _abbreviation(self): self._match(tokens.QUOTE) if self._lookahead_type(0) == tokens.LPAREN: expr = self._list() else: expr = self._simple_datum() return Pair(Symbol('quote'), Pair(expr, EmptyList))
def _simple_datum(self): token = self._lookahead_token(0) if token.type == tokens.NUMBER: expr = Number(int(token.text)) elif token.type == tokens.BOOLEAN: expr = Boolean(True if token.text == '#t' else False) elif token.type == tokens.CHARACTER: expr = Character(token.text[2:]) elif token.type == tokens.STRING: expr = String(token.text.strip('"')) elif token.type == tokens.ID: expr = Symbol(token.text) else: raise ParserException('No viable alternative') self._match(token.type) return expr
def is_cond_else_clause(clause): return cond_predicate(clause) == Symbol('else')
def is_cond(expr): return is_tagged_list(expr, Symbol('cond'))
def make_begin(seq): return cons(Symbol('begin'), seq)
def is_assignment(expr): return is_tagged_list(expr, Symbol('set!'))
def is_primitive_procedure(expr): return is_tagged_list(expr, Symbol('primitive'))
def primitive_procedure_values(): return [Pair(Symbol('primitive'), Pair(proc, EmptyList)) for _, proc in BUILTIN_PROCEDURES]
def make_procedure(params, body, env): """Create a list""" return cons(Symbol('procedure'), cons(params, cons(body, cons(env, EmptyList))))
def is_compound_procedure(expr): return is_tagged_list(expr, Symbol('procedure'))
def is_definition(expr): return is_tagged_list(expr, Symbol('define'))
def is_let_binding(expr): return is_tagged_list(expr, Symbol('let'))
def is_quoted(expr): return is_tagged_list(expr, Symbol('quote'))
def is_lambda(expr): return is_tagged_list(expr, Symbol('lambda'))
def is_if(expr): return is_tagged_list(expr, Symbol('if'))
def make_lambda(params, body): return cons(Symbol('lambda'), cons(params, body))
def make_if(predicate, consequent, alternative): return tolist(Symbol('if'), predicate, consequent, alternative)
def is_load(expr): return is_tagged_list(expr, Symbol('load'))
def is_or(expr): return is_tagged_list(expr, Symbol('or'))
def _eval_assignment(self, expr, env): env.set_variable_value( assignment.assignment_variable(expr), self._eval(assignment.assignment_value(expr), env) ) return Symbol('ok')
def is_begin(expr): return is_tagged_list(expr, Symbol('begin'))