Fparsec递归语法抛出StackOverflowException

时间:2016-05-06 16:34:15

标签: parsing f# fparsec

我已获得此代码

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

0 个答案:

没有答案