forked from GitHub/gf-core
examples/test is moved to testsuite
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
abstract City = {
|
||||
|
||||
cat S ; City ; Country ; Adj ;
|
||||
|
||||
data
|
||||
PredIn : City -> Country -> S ;
|
||||
fun
|
||||
PredAdj : City -> Adj -> S ;
|
||||
Capital : Country -> City ;
|
||||
CountryAdj : Adj -> Country ;
|
||||
data
|
||||
Stockholm, Helsinki : City ;
|
||||
Sweden, Finland : Country ;
|
||||
Swedish, Finnish : Adj ;
|
||||
|
||||
def
|
||||
PredAdj city x = PredIn city (CountryAdj x) ;
|
||||
|
||||
Capital Finland = Helsinki ;
|
||||
Capital Sweden = Stockholm ;
|
||||
|
||||
CountryAdj Finnish = Finland ;
|
||||
CountryAdj Swedish = Sweden ;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
concrete CityEng of City = {
|
||||
|
||||
lincat S, City, Country, Adj = Str ;
|
||||
|
||||
lin
|
||||
PredIn ci co = ci ++ "is in" ++ co ;
|
||||
PredAdj ci ad = ci ++ "is" ++ ad ;
|
||||
Capital co = "the capital of" ++ co ;
|
||||
CountryAdj ad = "the" ++ ad ++ "country" ;
|
||||
Stockholm = "Stockholm" ;
|
||||
Helsinki = "Helsinki" ;
|
||||
Sweden = "Sweden" ;
|
||||
Finland = "Finland" ;
|
||||
Swedish = "Swedish" ;
|
||||
Finnish = "Finnish" ;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
abstract Nat = {
|
||||
|
||||
cat Nat ;
|
||||
|
||||
data
|
||||
Zero : Nat ;
|
||||
Succ : Nat -> Nat ;
|
||||
|
||||
fun one : Nat ;
|
||||
def one = Succ Zero ;
|
||||
|
||||
fun plus : Nat -> Nat -> Nat ;
|
||||
def plus x Zero = x ;
|
||||
def plus x (Succ y) = Succ (plus x y) ;
|
||||
|
||||
fun twice : Nat -> Nat ;
|
||||
def twice x = plus x x ;
|
||||
|
||||
fun times : Nat -> Nat -> Nat ;
|
||||
def times x Zero = Zero ;
|
||||
def times x (Succ y) = plus (times x y) x ;
|
||||
|
||||
fun four : Nat ;
|
||||
def four = twice (twice one) ;
|
||||
|
||||
fun exp : Nat -> Nat ;
|
||||
def exp Zero = one ;
|
||||
def exp (Succ x) = twice (exp x) ;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import PGF
|
||||
import Data.Maybe
|
||||
import System.IO
|
||||
import System.CPUTime
|
||||
import Control.Monad
|
||||
|
||||
main = do
|
||||
pgf <- readPGF "grammar.pgf"
|
||||
ts <- fmap (map (fromJust . readTree) . lines) $ readFile "trees.txt"
|
||||
ss <- foldM (doTest pgf (mkCId "LangGer") (fromJust (readType "Phr"))) [] ts
|
||||
mapM_ (hPutStrLn stderr . show) [(fromIntegral s / fromIntegral n)/1000000000 | (s,n) <- ss]
|
||||
putStrLn "Done."
|
||||
|
||||
doTest pgf lang cat ss t = do
|
||||
let s = linearize pgf lang t
|
||||
putStr (s ++ " ... ")
|
||||
let st = initState pgf lang cat
|
||||
t1 <- getCPUTime
|
||||
res <- doParse st t1 [] (words s)
|
||||
case res of
|
||||
Just (st,ts) -> putStrLn "Ok" >> return (accum ts ss)
|
||||
Nothing -> putStrLn "Fail" >> return ss
|
||||
|
||||
|
||||
doParse st t1 ts [] = return (Just (st,reverse ts))
|
||||
doParse st t1 ts (tk:tks) = do
|
||||
case nextState st tk of
|
||||
Nothing -> return Nothing
|
||||
Just st -> do t2 <- getCPUTime
|
||||
doParse st t1 ((t2-t1):ts) tks
|
||||
|
||||
accum [] ss = ss
|
||||
accum (t:ts) [] = (t,1) : accum ts []
|
||||
accum (t:ts) ((s,n):ss) = (s+t,n+1) : accum ts ss
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
cat S;
|
||||
|
||||
fun f : S -> S ;
|
||||
fun g : S ;
|
||||
|
||||
lin f s = { s = s.s } ;
|
||||
lin g = { s = "g" } ;
|
||||
@@ -1,9 +0,0 @@
|
||||
cat S; E;
|
||||
|
||||
fun s : S ;
|
||||
fun es : E -> S -> S ;
|
||||
fun e : E ;
|
||||
|
||||
lin s = { s = "s" } ;
|
||||
lin es e s = { s = e.s ++ s.s } ;
|
||||
lin e = { s = [] } ;
|
||||
@@ -1,11 +0,0 @@
|
||||
-- a grammar with an indirect cycle
|
||||
|
||||
cat S; G;
|
||||
|
||||
fun f : S ;
|
||||
fun fg : G -> S ;
|
||||
fun gf : S -> G ;
|
||||
|
||||
lin f = { s = "f" } ;
|
||||
lin fg x = x;
|
||||
lin gf x = x;
|
||||
@@ -1,9 +0,0 @@
|
||||
cat S; E;
|
||||
|
||||
fun f : E -> S ;
|
||||
fun g : S -> S ;
|
||||
fun e : E ;
|
||||
|
||||
lin f e = { s = e.s } ;
|
||||
lin g s = { s = s.s ++ "x" } ;
|
||||
lin e = { s = "e" } ;
|
||||
@@ -1,7 +0,0 @@
|
||||
cat S;
|
||||
|
||||
fun f : S -> S ;
|
||||
g : S ;
|
||||
|
||||
lin f x = { s = x.s ++ "f" } ;
|
||||
g = { s = "s" } ;
|
||||
@@ -1,4 +0,0 @@
|
||||
cat S;
|
||||
fun f : S;
|
||||
|
||||
lin f = { s = variants {"a"; "b"} ++ variants {"c"; "d"} ++ variants {"e"; "f"} ++ variants { "g";"h";} } ;
|
||||
@@ -1,14 +0,0 @@
|
||||
abstract Check = {
|
||||
|
||||
cat Typ ; Exp Typ ;
|
||||
|
||||
fun plus : (t : Typ) -> (_,_ : Exp t) -> Exp t ;
|
||||
|
||||
fun TInt, TFloat : Typ ;
|
||||
|
||||
fun Zero : Exp TInt ;
|
||||
fun Pi : Exp TFloat ;
|
||||
|
||||
fun sqrt : Exp TFloat -> Exp TFloat ;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user