let..in中的OCaml语法错误

时间:2018-02-14 21:17:07

标签: syntax syntax-error ocaml

我是Ocaml的新手,我正在尝试打印出一个AST树,但是我在in函数的mon_to_string处收到语法错误。 注意:定义了所有使用的功能。

let rec print exp =
  let rec the_exp tree out = match tree with
    [] -> out

  and exp_to_string tree = match tree with
    | Ast.Expression.Identifier(x) -> print_identifier x
    | Ast.Expression.Literal(x) -> print_literal x
    | Ast.Expression.BinaryExp(x) -> print_bin_exp x
    | Ast.Expression.UnaryExp(x) -> print_unary_exp x
  in "<Expression>\n" ^ exp_to_string exp ^ "</Expression>\n"

  and mon_to_string tree = match tree with
    | Ast.Monitor.ExpressionGuard(x) -> print_exp_guard x
    | Ast.Monitor.QuantifiedGuard(x) -> print_quant_guard x
    | Ast.Monitor.Conditional(x) -> print_conditional x
    | Ast.Monitor.Evaluate(x) -> print_eval x
    | Ast.Monitor.Choice(x) -> print_choice x
  in "<Monitor>" ^ "\n" ^ mon_to_string exp ^ "</Monitor>\n"

1 个答案:

答案 0 :(得分:3)

上一个let没有in

正确的语法如下:

let rec v1 = exp1
and v2 = exp2
and v3 = exp3
in exp4

你有:

let rec v1 = exp1
and v2 = exp2
in exp3
and v3 = exp4
in exp5