diff options
| author | bringert <bringert@cs.chalmers.se> | 2006-04-13 14:47:37 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2006-04-13 14:47:37 +0000 |
| commit | dbfef31538e1bb96cdfe8f17884559fdf6ad680f (patch) | |
| tree | 52d8364e2f11498c25d1a4bf916aec95fdd519ef /src/GF/Speech/TransformCFG.hs | |
| parent | c5d0416996eb05fd820c569a177abaf09268ed15 (diff) | |
Removed cycles when building SRGs, to avoid getting left-recursive grammars.
Diffstat (limited to 'src/GF/Speech/TransformCFG.hs')
| -rw-r--r-- | src/GF/Speech/TransformCFG.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/GF/Speech/TransformCFG.hs b/src/GF/Speech/TransformCFG.hs index a1feaa420..acb78f82d 100644 --- a/src/GF/Speech/TransformCFG.hs +++ b/src/GF/Speech/TransformCFG.hs @@ -100,8 +100,7 @@ removeLeftRecursion rs = removeDirectLeftRecursions $ map handleProds rs [CFRule ai (beta ++ alpha) n | CFRule _ beta _ <- lookup' aj rs] handleProd r = [r] -removeDirectLeftRecursions :: [(Cat_,[CFRule_])] -- ^ All productions for a category - -> CFRules +removeDirectLeftRecursions :: CFRules -> CFRules removeDirectLeftRecursions = concat . flip evalState 0 . mapM removeDirectLeftRecursion removeDirectLeftRecursion :: (Cat_,[CFRule_]) -- ^ All productions for a category @@ -124,6 +123,9 @@ isDirectLeftRecursive :: CFRule_ -> Bool isDirectLeftRecursive (CFRule c (Cat c':_) _) = c == c' isDirectLeftRecursive _ = False +removeCycles :: CFRules -> CFRules +removeCycles = groupProds . removeCycles_ . ungroupProds + where removeCycles_ rs = [r | r@(CFRule c rhs n) <- rs, rhs /= [Cat c]] -- -- * CFG rule utilities |
