More.
This commit is contained in:
+10
-5
@@ -272,9 +272,13 @@ CFG for the BARF language:
|
||||
(if (string=? name fname) (f) (#f))])))]))
|
||||
(if (not foundfun) (error 'findfun "Function not found.") foundfun))
|
||||
|
||||
(: eval : PROGRAM -> Primitive)
|
||||
;; evaluates PROGRAM expressions by reducing them to numbers
|
||||
(define (eval expr)
|
||||
(: eval : PROGRAM BARF -> Primitive)
|
||||
; Evaluates a BARF in the context of a PROGRAM.
|
||||
(define (eval prog expr)
|
||||
(let ([eval (lambda ([e : BARF]) (eval prog e))]
|
||||
[eval-number (eval prog e)]
|
||||
[eval-boolean (eval prog e)])
|
||||
|
||||
(cases expr
|
||||
[(Num n) n]
|
||||
[(Bool p) p]
|
||||
@@ -298,9 +302,10 @@ CFG for the BARF language:
|
||||
(error 'eval "Can't create parameter binding to reserved name '~s'." par)
|
||||
(list (Par par) (Body body)))]
|
||||
[(Call f arg) (eval-call (value->barf (eval f)) arg)]
|
||||
[(Id name) (error 'eval "free identifier: ~s" name)]))
|
||||
[(Id name) (error 'eval "free identifier: ~s" name)])))
|
||||
|
||||
(: run : String -> Primitive)
|
||||
;; evaluate an BARF program contained in a string
|
||||
(define (run str)
|
||||
(eval (parse str)))
|
||||
(eval (parse str) (Call2 'main (Num 4))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user