Strip down format. More early work on compiler. Add testsuite (doesn't work yet).

This commit is contained in:
John J. Camilleri
2021-01-25 12:10:30 +01:00
parent cd5881d83a
commit f24c50339b
9 changed files with 245 additions and 92 deletions

12
testsuite/lpgf/Zero.gf Normal file
View File

@@ -0,0 +1,12 @@
-- From Angelov, Bringert, Ranta (2009)
abstract Zero = {
flags startcat = S ;
cat
S; NP; VP;
fun
And : S -> S -> S ;
Pred : NP -> VP -> S ;
John : NP ;
We : NP ;
Walk : VP ;
}

19
testsuite/lpgf/ZeroEng.gf Normal file
View File

@@ -0,0 +1,19 @@
-- From Angelov, Bringert, Ranta (2009)
concrete ZeroEng of Zero = {
lincat
S = Str ;
NP = {s : Str; n : Number} ;
VP = {s : Number => Str} ;
lin
And s1 s2 = s1 ++ "and" ++ s2 ;
Pred np vp = np.s ++ vp.s ! np.n ;
John = {s = "John"; n = Sg} ;
We = {s = "we"; n = Pl} ;
Walk = {s = table {
Sg => "walks";
Pl => "walk"
}
} ;
param
Number = Sg | Pl ;
}

28
testsuite/lpgf/ZeroGer.gf Normal file
View File

@@ -0,0 +1,28 @@
-- From Angelov, Bringert, Ranta (2009)
concrete ZeroGer of Zero = {
lincat
S = Str ;
NP = {s : Str; n : Number; p : Person} ;
VP = {s : Number => Person => Str} ;
lin
And s1 s2 = s1 ++ "und" ++ s2 ;
Pred np vp = np.s ++ vp.s ! np.n ! np.p ;
John = {s = "John"; n = Sg ; p = P3} ;
We = {s = "wir"; n = Pl; p = P1} ;
Walk = {s = table {
Sg => table {
P1 => "gehe" ;
P2 => "gehst" ;
P3 => "geht"
} ;
Pl => table {
P1 => "gehen" ;
P2 => "geht" ;
P3 => "gehen"
}
}
} ;
param
Number = Sg | Pl ;
Person = P1 | P2 | P3 ;
}

76
testsuite/lpgf/run.hs Normal file
View File

@@ -0,0 +1,76 @@
import LPGF
import PGF (Tree, mkCId, mkApp, readLanguage, showLanguage, showExpr)
import Control.Monad (forM_)
import qualified Data.Map as Map
import Text.Printf (printf)
main :: IO ()
main = do
lpgf <- readLPGF "Zero.lpgf"
forM_ [tree1, tree2, tree3] $ \tree -> do
putStrLn (showExpr [] tree)
forM_ (Map.toList (concretes lpgf)) $ \(lang,concr) ->
printf "%s: %s\n" (showLanguage lang) (linearizeConcr concr tree)
-- Pred John Walk
tree1 :: Tree
tree1 = mkApp (mkCId "Pred") [mkApp (mkCId "John") [], mkApp (mkCId "Walk") []]
-- Pred We Walk
tree2 :: Tree
tree2 = mkApp (mkCId "Pred") [mkApp (mkCId "We") [], mkApp (mkCId "Walk") []]
-- And (Pred John Walk) (Pred We Walk)
tree3 :: Tree
tree3 = mkApp (mkCId "And") [tree1, tree2]
-- Initial LPGF, Figures 6 & 7
zero :: LPGF
zero = LPGF {
absname = mkCId "Zero",
abstract = Abstr {
-- cats = Map.fromList [
-- (mkCId "S", ()),
-- (mkCId "NP", ()),
-- (mkCId "VP", ())
-- ],
-- funs = Map.fromList [
-- (mkCId "And", Type [mkCId "S", mkCId "S"] (mkCId "S")),
-- (mkCId "Pred", Type [mkCId "NP", mkCId "VP"] (mkCId "S")),
-- (mkCId "John", Type [] (mkCId "NP")),
-- (mkCId "We", Type [] (mkCId "NP")),
-- (mkCId "Walk", Type [] (mkCId "VP"))
-- ]
},
concretes = Map.fromList [
(mkCId "ZeroEng", Concr {
-- lincats = Map.fromList [
-- (mkCId "S", LTStr),
-- (mkCId "NP", LTProduct [LTStr, LTInt 2]),
-- (mkCId "VP", LTProduct [LTStr, LTStr])
-- ],
lins = Map.fromList [
(mkCId "And", mkConcat [LFArgument 1, LFToken "and", LFArgument 2]),
(mkCId "Pred", mkConcat [LFProjection (LFArgument 1) (LFInt 1), LFProjection (LFArgument 2) (LFProjection (LFArgument 1) (LFInt 2))]),
(mkCId "John", LFTuple [LFToken "John", LFInt 1]),
(mkCId "We", LFTuple [LFToken "we", LFInt 2]),
(mkCId "Walk", LFTuple [LFToken "walks", LFToken "walk"])
]
}),
(mkCId "ZeroGer", Concr {
-- lincats = Map.fromList [
-- (mkCId "S", LTStr),
-- (mkCId "NP", LTProduct [LTStr, LTInt 2, LTInt 3]),
-- (mkCId "VP", LTProduct [LTProduct [LTStr, LTStr, LTStr], LTProduct [LTStr, LTStr, LTStr]])
-- ],
lins = Map.fromList [
(mkCId "And", mkConcat [LFArgument 1, LFToken "und", LFArgument 2]),
(mkCId "Pred", mkConcat [LFProjection (LFArgument 1) (LFInt 1), LFProjection (LFProjection (LFArgument 2) (LFProjection (LFArgument 1) (LFInt 2))) (LFProjection (LFArgument 1) (LFInt 3))]),
(mkCId "John", LFTuple [LFToken "John", LFInt 1, LFInt 3]),
(mkCId "We", LFTuple [LFToken "wir", LFInt 2, LFInt 1]),
(mkCId "Walk", LFTuple [LFTuple [LFToken "gehe", LFToken "gehst", LFToken "geht"], LFTuple [LFToken "gehen", LFToken "geht", LFToken "gehen"]])
]
})
]
}