merged Gf and Fg classes in generated Haskell

This commit is contained in:
aarne
2007-12-20 15:11:18 +00:00
parent d88071c37c
commit d46f4c49e1
9 changed files with 42 additions and 104 deletions

View File

@@ -1,18 +1,11 @@
all: gf hs run
gf:
echo "pm | wf math.gfcm" | gf MathEng.gf MathFre.gf
hs: gf
echo "pg -printer=haskell | wf GSyntax.hs" | gf math.gfcm
run: hs
all:
gfc --make -haskell MathEng.gf MathFre.gf
ghc --make -o ./math TransferLoop.hs
strip math
clean:
rm -f *.gfc *.gfr *.o *.hi
rm -f *.gfo *.o *.hi
distclean:
rm -f GSyntax.hs math math.gfcm *.gfc *.gfr *.o *.hi
rm -f GSyntax.hs math Math.gfcc *.gfo *.o *.hi

View File

@@ -1,18 +0,0 @@
all: gf hs run
gf:
echo "pm -printer=gfcc | wf math.gfcc" | gf MathEng.gf MathFre.gf
hs: gf
echo "pg -printer=gfcc_haskell | wf GSyntax.hs" | gf MathEng.gf MathFre.gf
run: hs
ghc --make -o ./mathc TransferLoopGFCC.hs
strip mathc
clean:
rm -f *.gfc *.gfr *.o *.hi
distclean:
rm -f GSyntax.hs math math.gfcc *.gfc *.gfr *.o *.hi

View File

@@ -1,6 +1,6 @@
module TransferDef where
import GF.Embed.EmbedAPI (Tree)
import GF.GFCC.API (Tree)
import GSyntax
transfer :: Tree -> Tree

View File

@@ -1,26 +0,0 @@
module TransferDefGFCC where
import GF.GFCC.API (Tree)
import GSyntax
transfer :: Tree -> Tree
transfer = gf . answer . fg
answer :: GQuestion -> GAnswer
answer p = case p of
GOdd x -> test odd x
GEven x -> test even x
GPrime x -> test prime x
value :: GObject -> Int
value e = case e of
GNumber (GInt i) -> fromInteger i
test :: (Int -> Bool) -> GObject -> GAnswer
test f x = if f (value x) then GYes else GNo
prime :: Int -> Bool
prime x = elem x primes where
primes = sieve [2 .. x]
sieve (p:xs) = p : sieve [ n | n <- xs, n `mod` p > 0 ]
sieve [] = []

View File

@@ -1,11 +1,11 @@
module Main where
import GF.Embed.EmbedAPI
import GF.GFCC.API
import TransferDef (transfer)
main :: IO ()
main = do
gr <- file2grammar "math.gfcm"
gr <- file2grammar "Math.gfcc"
loop (translate transfer gr)
loop :: (String -> String) -> IO ()
@@ -17,7 +17,7 @@ loop trans = do
translate :: (Tree -> Tree) -> MultiGrammar -> String -> String
translate tr gr = unlines . map transLine . lines where
transLine s = case parseAllLang gr (startCat gr) s of
transLine s = case parseAllLang gr "Question" s of
(lg,t:_):_ -> linearize gr lg (tr t)
_ -> "NO PARSE"

View File

@@ -1,23 +0,0 @@
module Main where
import GF.GFCC.API
import TransferDefGFCC (transfer)
main :: IO ()
main = do
gr <- file2grammar "math.gfcc"
loop (translate transfer gr)
loop :: (String -> String) -> IO ()
loop trans = do
s <- getLine
if s == "quit" then putStrLn "bye" else do
putStrLn $ trans s
loop trans
translate :: (Tree -> Tree) -> MultiGrammar -> String -> String
translate tr gr = unlines . map transLine . lines where
transLine s = case parseAllLang gr "Question" s of
(lg,t:_):_ -> linearize gr lg (tr t)
_ -> "NO PARSE"