Fparsec recursive grammatics throw StackOverflowException

假装没事ソ 提交于 2019-12-19 11:04:15

问题


I've got this code

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

When it evaluated it throws StackoverflowExcpetion. So the question is how can i write it without infinitie recursion?

来源:https://stackoverflow.com/questions/37077358/fparsec-recursive-grammatics-throw-stackoverflowexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!