scanl (\exp y -> scanl (\x -> if (isLetter x) then update exp (Literal x) "" else
if x=='+' then update exp Epsilon "+" else
if x=='*' then update exp Epsilon "*" else
update exp Epsilon "|") y) Epsilon q
我的数据类型是:
data Reg = Epsilon | Literal Char | Or Reg Reg | Then Reg Reg | Star Reg deriving Eq
和
update:: Reg -> Reg -> [Char] -> Reg
update a b "" = (a `Then` b)
update a b "|"= (a `Or` b)
update a b "*" = (Star a)
update a b "+" = (plus a)
update a b "?" = (opt a)
我正在尝试使用上面的函数将这样的 ["a|","bc"] 转换为 (Then a (Or bc)) ,但我不能使用 ParSec 。