summaryrefslogtreecommitdiff
path: root/src-3.0/GF/Formalism/GCFG.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-05-21 09:26:44 +0000
committeraarne <aarne@cs.chalmers.se>2008-05-21 09:26:44 +0000
commit055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f (patch)
tree0e63fb68c69c8f6ad0f78893c63420f0a3600e1c /src-3.0/GF/Formalism/GCFG.hs
parent915a1de71783ab8446b1af9e72c7ba7dfbc12d3f (diff)
GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3
Diffstat (limited to 'src-3.0/GF/Formalism/GCFG.hs')
-rw-r--r--src-3.0/GF/Formalism/GCFG.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src-3.0/GF/Formalism/GCFG.hs b/src-3.0/GF/Formalism/GCFG.hs
new file mode 100644
index 000000000..5242081c7
--- /dev/null
+++ b/src-3.0/GF/Formalism/GCFG.hs
@@ -0,0 +1,47 @@
+----------------------------------------------------------------------
+-- |
+-- Maintainer : PL
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/05/09 09:28:44 $
+-- > CVS $Author: peb $
+-- > CVS $Revision: 1.3 $
+--
+-- Basic GCFG formalism (derived from Pollard 1984)
+-----------------------------------------------------------------------------
+
+module GF.Formalism.GCFG where
+
+import GF.Formalism.Utilities (SyntaxChart)
+import GF.Data.Assoc (assocMap, accumAssoc)
+import GF.Data.SortedList (nubsort, groupPairs)
+import GF.Infra.PrintClass
+
+----------------------------------------------------------------------
+
+type Grammar c n l t = [Rule c n l t]
+data Rule c n l t = Rule (Abstract c n) (Concrete l t)
+ deriving (Eq, Ord, Show)
+
+data Abstract cat name = Abs cat [cat] name
+ deriving (Eq, Ord, Show)
+data Concrete lin term = Cnc lin [lin] term
+ deriving (Eq, Ord, Show)
+
+----------------------------------------------------------------------
+
+instance (Print c, Print n, Print l, Print t) => Print (Rule n c l t) where
+ prt (Rule abs cnc) = prt abs ++ " := " ++ prt cnc
+ prtList = prtSep "\n"
+
+instance (Print c, Print n) => Print (Abstract c n) where
+ prt (Abs cat args name) = prt name ++ ". " ++ prt cat ++
+ ( if null args then ""
+ else " --> " ++ prtSep " " args )
+
+instance (Print l, Print t) => Print (Concrete l t) where
+ prt (Cnc lcat args term) = prt term
+ ++ " : " ++ prt lcat ++
+ ( if null args then ""
+ else " / " ++ prtSep " " args)