4

私の言語では、配列または構造体の要素にアクセスするためのドット演算子という 1 つの追加機能を備えた 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 に解析されます。ここで左再帰が問題になるのは、式 like(f x).yが同様に解析されるためです(access :m:y (f x))

しかし、FParsec でこの種の左再帰解析を処理する方法や、左再帰に代わる方法がわかりません。

4

0 に答える 0