我不断收到一个“经营者预计”上线183,字符4-7 (指这里的代码:http://pastebin.com/VxCM5cAV)OCAML:运营商预计将在功能
这些都是我最近添加的行:
let rec sem ((e: exp), (r: eval env)) =
[...]
| Apply(Pipe tup, eArg) -> unrollPipe tup sem(eArg, r) r
[...]
and rec unrollPipe tup evarg r = match tup with
| Seq(Den f, ttup) ->
let fclosure= sem(Den f, r) in
match fclosure with
| Funval(arg, fbody, fDecEnv) ->
let fres = sem(fbody, bind(fDecEnv, arg, evarg)) in
unrollPipe Pipe(ttup) fres r
| RecFunVal(f, arg, fbody, fDecEnv) ->
let rEnv= bind(fDecEnv, f, fclosure) in
let aEnv= bind(rEnv, arg, evarg) in
let fres = sem(fbody, aEnv) in
unrollPipe Pipe(ttup) fres r
| Seq(Pipe(ftup), ttup) ->
let fres = unrollPipe Pipe(ftup) evarg r in
unrollPipe Pipe(ttup) fres r
| Nil -> evarg
| _ -> failwith("bad Pipe")
;;
SEM应该是((EXP * EVAL ENV) - > EVAL)功能
这段代码的目的是为了实现一个解释器,它可以让您应用的功能的序列组成的管(Funval, RecFunVal都作为“Ide f”或其他P给出ipe)转换为表示参数的给定表达式(我只考虑一元函数)
要做到这一点,我将每次出现的Apply(Pipe(tup),eArg)并评估参数为一个eval,然后继续使用UnrollPipe(这是一个有趣的:tuple * eval - > eval)将管道中的第一个函数应用到我之前评估的参数,然后使用管道的尾部和前一个函数的结果递归调用自身,作为参数,从而导致计算管道中每个函数的组成。
我在此代码中使用的类型有以下几种:
EXP:
type ide = string
type exp =
| Eint of int
| Ebool of bool
| Den of ide
| Sum of exp * exp
| Diff of exp * exp
| Prod of exp * exp
| Eq of exp * exp
| Minus of exp
| Iszero of exp
| Or of exp * exp
| And of exp * exp
| Not of exp
| Ifthenelse of exp * exp * exp
| Let of ide * exp * exp(* Dichiarazione di ide: modifica ambiente*)
| Fun of ide * exp(* Astrazione di funzione*)
| Apply of exp * exp (* Applicazione di funzione*)
| Letrec of ide(*nome fun*)*ide(*par.formale*)*exp(*body fun*)*exp(*body let*)
| Etup of tuple (*Tupla come espressione*)
| Pipe of tuple (*Concatenazione di funzioni*)
| ManyTimes of int * exp (*Esecuzione iterata di una funzione*)
and tuple =
| Nil (*Tupla vuota*)
| Seq of exp * tuple (*Tupla di espressioni*)
;;
和eval:
type eval=
| Int of int
| Bool of bool
| Unbound
| RecFunVal of ide * ide * exp * eval env
| Funval of efun
| ValTup of evtuple
and efun = ide* exp * eval env
and evtuple =
| Nil
| Seq of eval * evtuple
;;
编辑:我命名以大写字母的功能,固定现在它给了我一个新的“语法错误”在线183,字符4-7 更新了pastebin,(http://pastebin.com/VxCM5cAV)
这是解决方案,随着几个更正在这里和那里,每当我递归调用unrollPipe我给管(tup)作为参数而不是tup – NokiStrawby