Parsing 使用OperatorReceidenceParser使用FParsec解析函数应用程序?

Parsing 使用OperatorReceidenceParser使用FParsec解析函数应用程序?,parsing,f#,fparsec,Parsing,F#,Fparsec,问题类似于,但我想使用FParsec中的operatorreceidenceparser解析一个带有函数应用程序的表达式 这是我的简历: type Expression = | Float of float | Variable of VarIdentifier | BinaryOperation of Operator * Expression * Expression | FunctionCall of VarIdentifier (*fun name*) * Express

问题类似于,但我想使用
FParsec
中的
operatorreceidenceparser
解析一个带有函数应用程序的表达式

这是我的简历:

type Expression =
  | Float of float
  | Variable of VarIdentifier
  | BinaryOperation of Operator * Expression * Expression
  | FunctionCall of VarIdentifier (*fun name*) * Expression list (*arguments*)
我有以下意见:

board→create_obstacle(4, 4, 450, 0, fric)
下面是解析器代码:

let expr = (number |>> Float) <|> (ident |>> Variable)
let parenexpr = between (str_ws "(") (str_ws ")") expr

let opp = new OperatorPrecedenceParser<_,_,_>()

opp.TermParser <- expr <|> parenexpr

opp.AddOperator(InfixOperator("→", ws, 
  10, Associativity.Right, 
  fun left right -> BinaryOperation(Arrow, left, right)))
我的解析器当前有以下输出:

Success: Expression (BinaryOperation 
     (Arrow,Variable "board",Variable "create_obstacle"))
我想要的是得到以下信息:

 Success: Expression 
      (BinaryOperation 
            (Arrow,
                Variable "board",
                Function (VarIdentifier "create_obstacle",
                          [Float 4, Float 4, Float 450, Float 0, Variable "fric"]))

您可以将参数列表解析为标识符的可选后缀表达式

let argListInParens = between (str_ws "(") (str_ws ")") argList
let identWithOptArgs = 
    pipe2 ident (opt argListInParens) 
          (fun id optArgs -> match optArgs with
                             | Some args -> FunctionCall(id, args)
                             | None -> Variable(id))
然后定义
expr
like

let expr = (number |>> Float) <|> identWithOptArgs
let expr=(数字|>>Float)identWithOptArgs
let expr = (number |>> Float) <|> identWithOptArgs