我正在尝试安排 ocamllex 和 ocamlyacc 代码来扫描和解析一种简单的语言。我已经定义了相同的抽象语法,但发现难以扫描复杂的规则。这是我的代码
{
type exp = B of bool | Const of float | Iszero of exp | Diff of exp*exp |
If of exp * exp * exp
}
rule scanparse = parse
|"true"| "false" as boolean {B boolean}
|['0'-'9']+ "." ['0'-'9']* as num {Const num}
|"iszero" space+ ['a'-'z']+ {??}
|'-' space+ '(' space* ['a'-'z']+ space* ',' space* ['a'-'z']+ space* ')' {??}
但我无法访问匹配字符串的某些部分。由于表达式声明是递归的,嵌套函数也无济于事(?)。请帮忙。