My languages uses s-expressions with one additional feature - a dot operator for accessing elements from an array or struct.
Currently, my parser works on this code using the access
operator -
; 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)))))]
However, I want to add alternate parsing using a dot operator like so -
; 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)))))]
They will both parse out to an equivalent AST. Left recursion matters here because an expression like (f x).y
should parse out just like (access :m:y (f x))
However, I don't know how to make FParsec deal with this type of left-recursive parsing, or what alternatives I have to left-recursion.