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