我已获得此代码
type Exprs =
| Val of float
| Mult of Exprs * Exprs
| Plus of Exprs * Exprs
let pexpr, exprRef = createParserForwardedToRef<Exprs, unit>()
let pval = pfloat |>> Val
let binaryOp s = (ws >>. pexpr.>> ws) .>>. (ws >>. str s >>. ws >>. pexpr)
let pplus = binaryOp "+" |>> Plus
let pmuil = binaryOp "*" |>> Mult
do exprRef := choice [ attempt pmuil
pplus
pval ]
let expression = ws >>. pexpr .>> ws
评估时会抛出StackoverflowExcpetion。所以问题是如何在没有无限递归的情况下编写它?