0

在以下代码部分中,我收到错误,尽管我使用了所有资源来研究它们,但我不确定为什么会得到它们。这是 SMLNJ 编码。

compComm (DeallocComm(var, exp), env, ip, codes, contIP)=
 let val loc = lookupEnv var env;
  val codes1 = emitByte(LDC, ip, codes);
  val codes2 = emitByte(Arg loc, ip + 1, codes1);
  val (ip', codes3) = compExp(exp, env, ip+2, codes2);
  val codes4 = emitByte(ADEALLOC, ip', codes3);
   in(ip'+1, codes4, nil, contIP)
  end;

hw4.sml:339.5-433.6 错误:非构造函数应用于模式中的参数:DeallocComm hw4.sml:427.26-427.29 错误:未绑定的变量或构造函数:var

hw4.sml:430.31-430.34 错误:未绑定的变量或构造函数:exp

ADEALLOC => let val (n, stack') = popStack stack
 val (loc, stack'') = popStack stack';
 fun loop'(n, loc, store) =
  val store' = updateTable (loc, defaultIntValue, store);
  in loop'(n-1, loc+1, store) =
   val store'' = loop'(n, loc, store) end;
 in loop(ip+1, store'', stack'') end;

hw4.sml:612.14 错误:语法错误:插入 EQUALOP

hw4.sml:615.8-615.11 错误:语法错误:将 VAL 替换为 END

任何有关这些的帮助将不胜感激。

4

2 回答 2

1

You can call a function as an argument to be passed to another function, but you're doing so incorrectly. The correct syntax is to call the function name with no arguments or perentheses, then to use the function passed as an argument within the body of the function to which it is passed.

So you would want your function declaration to be:

compComm (DeallocComm, env, ip, codes, contIP)=

and then use DeallocComm in the body. As it stands, you're creating an environment variable which has a value but no name -- DeallocComm(var, exp) evaluates before being passed into the function.

于 2013-02-01T05:28:29.460 回答
0

所以对于第一个,我认为它找不到构造函数DeallocComm。(这是从哪里声明的?)

对于第二个,这没有任何意义。我不知道你在做什么。store'and是store''loop'函数内部还是在函数外部?如果是前者,那为什么不在 a 内let?如果是后者,那么loop';的主体在哪里?又怎么能用store''在函数外的表达式中呢?此外,没有称为 的值loop。似乎您缺少很多fun,let和其他东西。

于 2010-11-19T19:48:59.887 回答