OCaml解析器代码

时间:2013-01-06 21:38:16

标签: ocaml ocamlyacc

我的代码:

Term :
...
| VAR { try Hashtbl.find var_table $1
         with Not_found ->
      printf "no such variable '%s'\n" $1; 0.0 }    /*(Line:75)*/
...

当我被运行时,在 ocamlc -c parser.ml我明白了:

Error: This expression has type float but an expression was expected of type
         Syntax.term
大家可以帮我证明这个问题吗? 我理解第75行的类型与在Syntax.ml和Syntax.mll中定义的类型Syntax.term不匹配,但我想指定类型0.0到Syntax.term来证明它。我能做到吗?

-------------------- EDIT ------------------:

术语类型:

type term =
    TmTrue
  | TmFalse
  | TmIf of term * term * term
  | TmAnd of term * term
  | TmOr of term * term
  | TmXor of term * term
  | TmSum of term * term
  | TmSub of term * term
  | TmMult of term * term
  | TmPow of term * term
  | TmZero
  | TmSucc of term
  | TmPred of term
  | TmIsZero of term
  | TmNot of term

每件事情都是正确的,我想在我的代码中添加作业,我使用上面的代码将VAR添加到Term。我为它创建了哈希表和其他东西,但这部分让我感到困惑......

---------------------- / EDIT ----------------------- -

tnx;)

1 个答案:

答案 0 :(得分:3)

您没有可以代表值0.0的术语。也许你应该使用TmZero