OCaml解析器代码

OCaml解析器代码,ocaml,ocamlyacc,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 e

我的代码:

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来证明这一点。我能做吗

--------------------编辑----------------------------:

术语类型:

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。我为它创建了哈希表和其他东西,但这一部分让我感到困惑

----------------------/编辑------------------------


tnx;)

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

来获得一个好的答案,您需要显示类型
语法.term
的样子。我希望有一个表示浮点值的构造函数。您可以使用它来构造结果。值
0.0
本身属于
float
类型。我的术语类型:type term=TmTrue | TmFalse | TmIf of term*term*term | TmAnd of term*term | TmOr of term*term | TmXor of term*term | tmum of term*term | TmMult of term*term | TmPow of term*term | TmZero | tmucc of term | TmPred |TmIsZero属于术语| Tmsnot属于术语我只想打印“没有这样的变量…”,0.0是我的类型的一个额外元素,与单位不同。。。所以第75行可能会改变,如果你说。。感谢您的帮助:)请更新您的问题以包含该信息。感谢您“Jeffrey”,我们对其进行了测试,并在您的帮助下解决了此错误;)我想是的,但我没有测试这个解决方案,我在StackOverFlow中的第一次提问体验非常好;)又是tnx。。。