Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Parsing 如何在FParsec中处理左递归_Parsing_F#_Fparsec_Left Recursion - Fatal编程技术网

Parsing 如何在FParsec中处理左递归

Parsing 如何在FParsec中处理左递归,parsing,f#,fparsec,left-recursion,Parsing,F#,Fparsec,Left Recursion,我的语言使用s表达式,它还有一个额外的特性——点运算符,用于访问数组或结构中的元素 目前,我的解析器使用access操作符处理这段代码- ; Parition a sequence into a pair of sequences. ; NOTE: currently not tail-recursive. [defRec partition [pred seq] (if (isDone seq) (pair (list) (list)) (let (value (p

我的语言使用s表达式,它还有一个额外的特性——点运算符,用于访问数组或结构中的元素

目前,我的解析器使用
access
操作符处理这段代码-

; Parition a sequence into a pair of sequences.
; NOTE: currently not tail-recursive.
[defRec partition [pred seq]
  (if (isDone seq)
      (pair (list) (list))
      (let (value (peek seq))
           (nextSeq (next seq))
           (nextResult (partition pred nextSeq))
           (nextResultFirst (access :m:first nextResult))
           (nextResultSecond (access :m:second nextResult))
           (if (pred value)
               (pair (cons value nextResultFirst) nextResultSecond)
               (pair nextResultFirst (cons value nextResultSecond)))))]
但是,我想使用点运算符添加备用解析,如下所示-

; Parition a sequence into a pair of sequences.
; NOTE: currently not tail-recursive.
[defRec partition [pred seq]
  (if (isDone seq)
      (pair (list) (list))
      (let (value (peek seq))
           (nextSeq (next seq))
           (nextResult (partition pred nextSeq))
           (nextResultFirst nextResult.first)
           (nextResultSecond nextResult.second)
           (if (pred value)
               (pair (cons value nextResultFirst) nextResultSecond)
               (pair nextResultFirst (cons value nextResultSecond)))))]
它们都将解析为等效的AST。左递归在这里很重要,因为像
(fx).y这样的表达式应该像
(access:m:y(fx))一样解析出来


然而,我不知道如何让FParsec处理这种类型的左递归解析,或者我有什么替代左递归的方法。

您可以解析像
exp1这样的复合表达式。exp2
作为一个由点分隔的表达式序列,例如使用
sebby
组合器,如果您给出正式的语法定义,或者提供最小和具体的示例输入以及预期的AST表示,那么回答这些问题会更容易。就像我尝试过的其他事情一样,Sebby将我发送到堆栈溢出中。一旦有时间,我必须提供更多的细节。