mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-19 01:39:32 -06:00
merged Gf and Fg classes in generated Haskell
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module TransferDef where
|
||||
|
||||
import GF.Embed.EmbedAPI (Tree)
|
||||
import GF.GFCC.API (Tree)
|
||||
import GSyntax
|
||||
|
||||
transfer :: Tree -> Tree
|
||||
|
||||
@@ -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 [] = []
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user