Vandermond
Vandermond

Reputation: 23

OCaml parser code

My code:

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

and when I was run it, under ocamlc -c parser.ml I see:

Error: This expression has type float but an expression was expected of type
         Syntax.term

can everybody help me to prove this problem?? I understand that type of line 75 doesn't match with type Syntax.term that define in Syntax.ml and Syntax.mll, but I want to specify type of 0.0 to Syntax.term to prove it. can I do it??

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

term type :

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

every thing is work correct, where I want to add assignment to my code, I add VAR to Term with above code. I create hashtable and other things for it, but this section make me confuse...

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

tnx ;)

Upvotes: 2

Views: 221

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66808

You don't have a term that can represent the value 0.0. Maybe you should use TmZero?

Upvotes: 3

Related Questions