Constructori:
* listagoala -> ListofExpval
* adauga : expVal x ListofExpval -> ListofExpval
Observatori:
* primul : ListofExpval -> expVal
* restul : ListofExpval -> ListofExpval
* e_goala : ListofExpval -> Bool
> lang.scm___________________________________________________
;;; in the grammar
(expression
("lista-goala")
gol-exp)
(expression
("adauga" expression "la" expression)
add-exp)
(expression
("primul" "din" expression)
car-exp)
(expression
("restul" "din" expression)
cdr-exp)
(expression
("e-goala" "(" expression ")")
isempty-exp)
> interp.scm__________________________________________________
;; in value-of
(gol-exp ()
'()
)
(add-exp (exp1 exp2)
(cons (value-of exp1 env) (value-of exp2 env)))
(car-exp (exp1)
(car (value-of exp1 env)))
(cdr-exp (exp1)
(cdr (value-of exp1 env)))
(isempty-exp (exp1)
(bool-val (null? (value-of exp1 env))))
> tests.scm____________________________________________________
(lista-test1 "adauga 5 la adauga 6 la lista-goala" (5 6))
(lista-test2 "lista-goala" ())
(lista-test3 "let x=1 in adauga x la lista-goala" (1))
(lista-test4 "adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (#f 5 1))
(lista-test5 "e-goala(lista-goala)" #t)
(lista-test6 "e-goala(adauga 3 la lista-goala)" #f)
(lista-test7 "primul din let x=1 in adauga x la lista-goala" 1)
(lista-test8 "restul din adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (5 1))
> top.scm______________________________________________________
;;; in sloppy->expval (for tests.scm)
((list? sloppy-val) (map sloppy->expval sloppy-val))
* listagoala -> ListofExpval
* adauga : expVal x ListofExpval -> ListofExpval
Observatori:
* primul : ListofExpval -> expVal
* restul : ListofExpval -> ListofExpval
* e_goala : ListofExpval -> Bool
> lang.scm___________________________________________________
;;; in the grammar
(expression
("lista-goala")
gol-exp)
(expression
("adauga" expression "la" expression)
add-exp)
(expression
("primul" "din" expression)
car-exp)
(expression
("restul" "din" expression)
cdr-exp)
(expression
("e-goala" "(" expression ")")
isempty-exp)
> interp.scm__________________________________________________
;; in value-of
(gol-exp ()
'()
)
(add-exp (exp1 exp2)
(cons (value-of exp1 env) (value-of exp2 env)))
(car-exp (exp1)
(car (value-of exp1 env)))
(cdr-exp (exp1)
(cdr (value-of exp1 env)))
(isempty-exp (exp1)
(bool-val (null? (value-of exp1 env))))
> tests.scm____________________________________________________
(lista-test1 "adauga 5 la adauga 6 la lista-goala" (5 6))
(lista-test2 "lista-goala" ())
(lista-test3 "let x=1 in adauga x la lista-goala" (1))
(lista-test4 "adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (#f 5 1))
(lista-test5 "e-goala(lista-goala)" #t)
(lista-test6 "e-goala(adauga 3 la lista-goala)" #f)
(lista-test7 "primul din let x=1 in adauga x la lista-goala" 1)
(lista-test8 "restul din adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (5 1))
> top.scm______________________________________________________
;;; in sloppy->expval (for tests.scm)
((list? sloppy-val) (map sloppy->expval sloppy-val))
Niciun comentariu:
Trimiteți un comentariu