From 05b5ffe5bf03a870f6fe0728ace6c0d8de69b89e Mon Sep 17 00:00:00 2001 From: bringert Date: Fri, 17 Jun 2005 11:46:04 +0000 Subject: Added beginnings of ATK SLF generation. --- src/GF/Speech/TransformCFG.hs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/GF/Speech/TransformCFG.hs') diff --git a/src/GF/Speech/TransformCFG.hs b/src/GF/Speech/TransformCFG.hs index 71b3ca296..db9b009a6 100644 --- a/src/GF/Speech/TransformCFG.hs +++ b/src/GF/Speech/TransformCFG.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/04/21 16:23:33 $ +-- > CVS $Date: 2005/06/17 12:46:05 $ -- > CVS $Author: bringert $ --- > CVS $Revision: 1.12 $ +-- > CVS $Revision: 1.13 $ -- -- This module does some useful transformations on CFGs. -- @@ -16,7 +16,7 @@ -- peb thinks: most of this module should be moved to GF.Conversion... ----------------------------------------------------------------------------- -module GF.Speech.TransformCFG (makeNice, CFRule_) where +module GF.Speech.TransformCFG (makeNice, CFRule_, makeRegular) where import GF.Infra.Ident import GF.Formalism.CFG @@ -37,6 +37,8 @@ type Cat_ = String type CFRules = FiniteMap Cat_ [CFRule_] +-- | Remove left-recursion and categories with no productions +-- from a context-free grammar. makeNice :: CGrammar -> [CFRule_] makeNice = concat . eltsFM . makeNice' . groupProds . cfgToCFRules where makeNice' = removeLeftRecursion . removeEmptyCats @@ -94,6 +96,27 @@ isDirectLeftRecursive (CFRule c (Cat c':_) _) = c == c' isDirectLeftRecursive _ = False +-- Use the transformation algorithm from \"Regular Approximation of Context-free +-- Grammars through Approximation\", Mohri and Nederhof, 2000 +-- to create an over-generating regular frammar for a context-free +-- grammar +makeRegular :: [CFRule_] -> [CFRule_] +makeRegular = undefined + +{- +isRightLinear :: [Cat_] -- ^ The categories to consider + -> CFRule_ + -> Bool +isRightLinear _ (CFRule _ ss _) | all isTerminal ss = True +isRightLinear cs +-} + +-- Use the strongly regular grammar to finite automaton +-- compilation algorithm from \"Regular Approximation of Context-free +-- Grammars through Approximation\", Mohri and Nederhof, 2000 +-- compileAutomaton :: + + fix :: Eq a => (a -> a) -> a -> a fix f x = let x' = f x in if x' == x then x else fix f x' -- cgit v1.2.3