Skip to content

Commit

Permalink
hw6: add w5.py
Browse files Browse the repository at this point in the history
twyair committed Jan 25, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent be19fb0 commit 252d7a4
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions HW/6/w5.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
from eval_def import *

def make_a_list() -> A_List:
raise NotImplementedError
return []


def lookup(a_list: A_List, ast: str) -> S_Expression:
for s, val in reversed(a_list):
if s == ast:
return val
raise Undefined


def normalize(ast: AST) -> AST:
raise NotImplementedError
if isinstance(ast, Atom):
ast = ast.upper()
if set(ast) - ALLOWED_CHARS:
raise IllegalSymbol
return ast
else:
return [normalize(x) for x in ast]

def lookup(a_list: A_List, name: str) -> S_Expression:
raise NotImplementedError

def eval_cond(a_list: A_List, args: List[AST]) -> S_Expression:
def eval_set(a_list: A_List, args: List[AST]) -> S_Expression:
from eval import eval_rec
raise NotImplementedError
if len(args) != 2:
raise WrongNumberOfArguments
name = eval_rec(a_list, args[0])
if isinstance(name, S_Atom):
value = eval_rec(a_list, args[1])
a_list.append((name.value, value))
return value
else:
raise NotASymbol

def eval_set(a_list: A_List, args: List[AST]) -> S_Expression:

def eval_cond(a_list: A_List, args: List[AST]) -> S_Expression:
from eval import eval_rec
raise NotImplementedError
for t, v, *_ in args:
if eval_rec(a_list, t) != NIL:
return eval_rec(a_list, v)
return NIL

0 comments on commit 252d7a4

Please sign in to comment.