Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Context free grammars, where each production is a regular-expression.
Context-free grammars
Conversion to recursive regular expressions
cfgToRE :: (SNatI n, Ord a) => Vec (S n) Name -> CFG (S n) a -> RE a Source #
Convert CFG
(with names for productions) into RE
.
Note: the start symbol have to be last equation.
>>>
let a = Eps \/ ch_ 'a' <> Var (Left FZ)
>>>
let b = Eps \/ ch_ 'b' <> Var (Left (FS FZ))
>>>
let cfg = b ::: a ::: VNil
[ begin{aligned} {mathit{b}} &= {varepsilon}cupmathtt{b}{mathit{a}} -- {mathit{a}} &= {varepsilon}cupmathtt{a}{mathit{b}} -- end{aligned}