diff options
| author | aarne <aarne@cs.chalmers.se> | 2007-10-20 09:51:26 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2007-10-20 09:51:26 +0000 |
| commit | 192f55e2f579d5f736f442287cc237da353a6991 (patch) | |
| tree | 42368c7ca4f716e997e140685b4e63273b0bc399 /examples/tutorial/semantics/GSyntax.hs | |
| parent | e86db4d8c8287790a90955fefec10b7a64988ff8 (diff) | |
semantics extended to questions
Diffstat (limited to 'examples/tutorial/semantics/GSyntax.hs')
| -rw-r--r-- | examples/tutorial/semantics/GSyntax.hs | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/examples/tutorial/semantics/GSyntax.hs b/examples/tutorial/semantics/GSyntax.hs index c16a0b97c..48634d2e9 100644 --- a/examples/tutorial/semantics/GSyntax.hs +++ b/examples/tutorial/semantics/GSyntax.hs @@ -61,6 +61,12 @@ data GAP = | GPrime deriving Show +data GAnswer = + GNo + | GValue GNP + | GYes + deriving Show + data GCN = GModCN GAP GCN | GNumber @@ -71,13 +77,30 @@ data GConj = | GOr deriving Show +newtype GListPN = GListPN [GPN] deriving Show + data GNP = GConjNP GConj GNP GNP | GEvery GCN + | GMany GListPN + | GNone GCN | GSome GCN + | GUsePN GPN + deriving Show + +data GPN = + GGCD GListPN + | GProduct GListPN + | GSum GListPN | GUseInt GInt deriving Show +data GQuestion = + GQuestS GS + | GWhatIs GPN + | GWhichAre GCN GAP + deriving Show + data GS = GConjS GConj GS GS | GPredAP GNP GAP @@ -97,6 +120,11 @@ instance Gf GAP where gf GOdd = DTr [] (AC (CId "Odd")) [] gf GPrime = DTr [] (AC (CId "Prime")) [] +instance Gf GAnswer where + gf GNo = DTr [] (AC (CId "No")) [] + gf (GValue x1) = DTr [] (AC (CId "Value")) [gf x1] + gf GYes = DTr [] (AC (CId "Yes")) [] + instance Gf GCN where gf (GModCN x1 x2) = DTr [] (AC (CId "ModCN")) [gf x1, gf x2] gf GNumber = DTr [] (AC (CId "Number")) [] @@ -105,12 +133,29 @@ instance Gf GConj where gf GAnd = DTr [] (AC (CId "And")) [] gf GOr = DTr [] (AC (CId "Or")) [] +instance Gf GListPN where + gf (GListPN [x1,x2]) = DTr [] (AC (CId "BasePN")) [gf x1, gf x2] + gf (GListPN (x:xs)) = DTr [] (AC (CId "ConsPN")) [gf x, gf (GListPN xs)] + instance Gf GNP where gf (GConjNP x1 x2 x3) = DTr [] (AC (CId "ConjNP")) [gf x1, gf x2, gf x3] gf (GEvery x1) = DTr [] (AC (CId "Every")) [gf x1] + gf (GMany x1) = DTr [] (AC (CId "Many")) [gf x1] + gf (GNone x1) = DTr [] (AC (CId "None")) [gf x1] gf (GSome x1) = DTr [] (AC (CId "Some")) [gf x1] + gf (GUsePN x1) = DTr [] (AC (CId "UsePN")) [gf x1] + +instance Gf GPN where + gf (GGCD x1) = DTr [] (AC (CId "GCD")) [gf x1] + gf (GProduct x1) = DTr [] (AC (CId "Product")) [gf x1] + gf (GSum x1) = DTr [] (AC (CId "Sum")) [gf x1] gf (GUseInt x1) = DTr [] (AC (CId "UseInt")) [gf x1] +instance Gf GQuestion where + gf (GQuestS x1) = DTr [] (AC (CId "QuestS")) [gf x1] + gf (GWhatIs x1) = DTr [] (AC (CId "WhatIs")) [gf x1] + gf (GWhichAre x1 x2) = DTr [] (AC (CId "WhichAre")) [gf x1, gf x2] + instance Gf GS where gf (GConjS x1 x2 x3) = DTr [] (AC (CId "ConjS")) [gf x1, gf x2, gf x3] gf (GPredAP x1 x2) = DTr [] (AC (CId "PredAP")) [gf x1, gf x2] @@ -135,6 +180,14 @@ instance Fg GAP where DTr [] (AC (CId "Prime")) [] -> GPrime _ -> error ("no AP " ++ show t) +instance Fg GAnswer where + fg t = + case t of + DTr [] (AC (CId "No")) [] -> GNo + DTr [] (AC (CId "Value")) [x1] -> GValue (fg x1) + DTr [] (AC (CId "Yes")) [] -> GYes + _ -> error ("no Answer " ++ show t) + instance Fg GCN where fg t = case t of @@ -149,15 +202,41 @@ instance Fg GConj where DTr [] (AC (CId "Or")) [] -> GOr _ -> error ("no Conj " ++ show t) +instance Fg GListPN where + fg t = + case t of + DTr [] (AC (CId "BasePN")) [x1,x2] -> GListPN [fg x1, fg x2] + DTr [] (AC (CId "ConsPN")) [x1,x2] -> let GListPN xs = fg x2 in GListPN (fg x1:xs) + _ -> error ("no ListPN " ++ show t) + instance Fg GNP where fg t = case t of DTr [] (AC (CId "ConjNP")) [x1,x2,x3] -> GConjNP (fg x1) (fg x2) (fg x3) DTr [] (AC (CId "Every")) [x1] -> GEvery (fg x1) + DTr [] (AC (CId "Many")) [x1] -> GMany (fg x1) + DTr [] (AC (CId "None")) [x1] -> GNone (fg x1) DTr [] (AC (CId "Some")) [x1] -> GSome (fg x1) - DTr [] (AC (CId "UseInt")) [x1] -> GUseInt (fg x1) + DTr [] (AC (CId "UsePN")) [x1] -> GUsePN (fg x1) _ -> error ("no NP " ++ show t) +instance Fg GPN where + fg t = + case t of + DTr [] (AC (CId "GCD")) [x1] -> GGCD (fg x1) + DTr [] (AC (CId "Product")) [x1] -> GProduct (fg x1) + DTr [] (AC (CId "Sum")) [x1] -> GSum (fg x1) + DTr [] (AC (CId "UseInt")) [x1] -> GUseInt (fg x1) + _ -> error ("no PN " ++ show t) + +instance Fg GQuestion where + fg t = + case t of + DTr [] (AC (CId "QuestS")) [x1] -> GQuestS (fg x1) + DTr [] (AC (CId "WhatIs")) [x1] -> GWhatIs (fg x1) + DTr [] (AC (CId "WhichAre")) [x1,x2] -> GWhichAre (fg x1) (fg x2) + _ -> error ("no Question " ++ show t) + instance Fg GS where fg t = case t of |
