1

我有这个代码

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。所以问题是我如何在没有无限递归的情况下编写它?

4

0 回答 0