Beispiel #1
0
 def _eval_definition(self, expr, env):
     define_variable(
         definition.definition_variable(expr),
         self._eval(definition.definition_value(expr), env),
         env
         )
     return Symbol('ok')
Beispiel #2
0
    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))
Beispiel #3
0
    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
Beispiel #4
0
def is_cond_else_clause(clause):
    return cond_predicate(clause) == Symbol('else')
Beispiel #5
0
def is_cond(expr):
    return is_tagged_list(expr, Symbol('cond'))
Beispiel #6
0
def make_begin(seq):
    return cons(Symbol('begin'), seq)
Beispiel #7
0
def is_assignment(expr):
    return is_tagged_list(expr, Symbol('set!'))
Beispiel #8
0
def is_primitive_procedure(expr):
    return is_tagged_list(expr, Symbol('primitive'))
Beispiel #9
0
def primitive_procedure_values():
    return [Pair(Symbol('primitive'), Pair(proc, EmptyList))
            for _, proc in BUILTIN_PROCEDURES]
Beispiel #10
0
def make_procedure(params, body, env):
    """Create a list"""
    return cons(Symbol('procedure'),
                cons(params, cons(body, cons(env, EmptyList))))
Beispiel #11
0
def is_compound_procedure(expr):
    return is_tagged_list(expr, Symbol('procedure'))
Beispiel #12
0
def is_definition(expr):
    return is_tagged_list(expr, Symbol('define'))
Beispiel #13
0
def is_let_binding(expr):
    return is_tagged_list(expr, Symbol('let'))
Beispiel #14
0
def is_quoted(expr):
    return is_tagged_list(expr, Symbol('quote'))
Beispiel #15
0
def is_lambda(expr):
    return is_tagged_list(expr, Symbol('lambda'))
Beispiel #16
0
def is_if(expr):
    return is_tagged_list(expr, Symbol('if'))
Beispiel #17
0
def make_lambda(params, body):
    return cons(Symbol('lambda'), cons(params, body))
Beispiel #18
0
def make_if(predicate, consequent, alternative):
    return tolist(Symbol('if'), predicate, consequent, alternative)
Beispiel #19
0
def is_load(expr):
    return is_tagged_list(expr, Symbol('load'))
Beispiel #20
0
def is_or(expr):
    return is_tagged_list(expr, Symbol('or'))
Beispiel #21
0
 def _eval_assignment(self, expr, env):
     env.set_variable_value(
         assignment.assignment_variable(expr),
         self._eval(assignment.assignment_value(expr), env)
         )
     return Symbol('ok')
Beispiel #22
0
def is_begin(expr):
    return is_tagged_list(expr, Symbol('begin'))