summaryrefslogtreecommitdiff
path: root/examples/tutorial
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-06-25 16:54:35 +0000
committeraarne <aarne@cs.chalmers.se>2008-06-25 16:54:35 +0000
commite9e80fc389365e24d4300d7d5390c7d833a96c50 (patch)
treef0b58473adaa670bd8fc52ada419d8cad470ee03 /examples/tutorial
parentb96b36f43de3e2f8b58d5f539daa6f6d47f25870 (diff)
changed names of resource-1.3; added a note on homepage on release
Diffstat (limited to 'examples/tutorial')
-rw-r--r--examples/tutorial/embedded/LexMath.gf8
-rw-r--r--examples/tutorial/embedded/LexMathEng.gf8
-rw-r--r--examples/tutorial/embedded/LexMathFre.gf8
-rw-r--r--examples/tutorial/embedded/Makefile11
-rw-r--r--examples/tutorial/embedded/Math.gf14
-rw-r--r--examples/tutorial/embedded/MathEng.gf6
-rw-r--r--examples/tutorial/embedded/MathFre.gf6
-rw-r--r--examples/tutorial/embedded/MathI.gf23
-rw-r--r--examples/tutorial/embedded/TransferDef.hs26
-rw-r--r--examples/tutorial/embedded/TransferLoop.hs23
-rw-r--r--examples/tutorial/embedded/Translator.hs16
-rw-r--r--examples/tutorial/embedded/TranslatorLoop.hs23
-rw-r--r--examples/tutorial/embedded/haskell/GSyntax.hs100
-rw-r--r--examples/tutorial/embedded/haskell/Run.hs38
-rw-r--r--examples/tutorial/food/food.ebnf4
-rw-r--r--examples/tutorial/hello/hello.gfs2
-rw-r--r--examples/tutorial/semantics/Base.gf2
-rw-r--r--examples/tutorial/semantics/BaseI.gf12
-rw-r--r--examples/tutorial/semantics/Core.gf6
-rw-r--r--examples/tutorial/smart/SmartEng.gf2
-rw-r--r--examples/tutorial/smart/SmartFre.gf2
-rw-r--r--examples/tutorial/syntax/FoodsEng.gf5
-rw-r--r--examples/tutorial/syntax/FoodsI.gf26
-rw-r--r--examples/tutorial/syntax/FoodsIta.gf5
-rw-r--r--examples/tutorial/syntax/Syntax.gf12
25 files changed, 16 insertions, 372 deletions
diff --git a/examples/tutorial/embedded/LexMath.gf b/examples/tutorial/embedded/LexMath.gf
deleted file mode 100644
index 25bfe8846..000000000
--- a/examples/tutorial/embedded/LexMath.gf
+++ /dev/null
@@ -1,8 +0,0 @@
-interface LexMath = open Syntax in {
-
- oper
- even_A : A ;
- odd_A : A ;
- prime_A : A ;
-
-}
diff --git a/examples/tutorial/embedded/LexMathEng.gf b/examples/tutorial/embedded/LexMathEng.gf
deleted file mode 100644
index 183fa520f..000000000
--- a/examples/tutorial/embedded/LexMathEng.gf
+++ /dev/null
@@ -1,8 +0,0 @@
-instance LexMathEng of LexMath = open SyntaxEng, ParadigmsEng in {
-
- oper
- even_A = mkA "even" ;
- odd_A = mkA "odd" ;
- prime_A = mkA "prime" ;
-
-}
diff --git a/examples/tutorial/embedded/LexMathFre.gf b/examples/tutorial/embedded/LexMathFre.gf
deleted file mode 100644
index 7407b410f..000000000
--- a/examples/tutorial/embedded/LexMathFre.gf
+++ /dev/null
@@ -1,8 +0,0 @@
-instance LexMathFre of LexMath = open SyntaxFre, ParadigmsFre in {
-
- oper
- even_A = mkA "pair" ;
- odd_A = mkA "impair" ;
- prime_A = mkA "premier" ;
-
-}
diff --git a/examples/tutorial/embedded/Makefile b/examples/tutorial/embedded/Makefile
deleted file mode 100644
index 119d5d0fe..000000000
--- a/examples/tutorial/embedded/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-all:
- gfc --make -haskell MathEng.gf MathFre.gf
- ghc --make -o ./math TransferLoop.hs
- strip math
-
-clean:
- rm -f *.gfo *.o *.hi
-
-distclean:
- rm -f GSyntax.hs math Math.gfcc *.gfo *.o *.hi
-
diff --git a/examples/tutorial/embedded/Math.gf b/examples/tutorial/embedded/Math.gf
deleted file mode 100644
index 95f5d5d1c..000000000
--- a/examples/tutorial/embedded/Math.gf
+++ /dev/null
@@ -1,14 +0,0 @@
-abstract Math = {
-
- cat Answer ; Question ; Object ;
-
- fun
- Even : Object -> Question ;
- Odd : Object -> Question ;
- Prime : Object -> Question ;
- Number : Int -> Object ;
-
- Yes : Answer ;
- No : Answer ;
-
-}
diff --git a/examples/tutorial/embedded/MathEng.gf b/examples/tutorial/embedded/MathEng.gf
deleted file mode 100644
index ac332fef7..000000000
--- a/examples/tutorial/embedded/MathEng.gf
+++ /dev/null
@@ -1,6 +0,0 @@
---# -path=.:present:prelude:mathematical
-
-concrete MathEng of Math = MathI with
- (Syntax = SyntaxEng),
- (Symbol = SymbolEng),
- (LexMath = LexMathEng) ;
diff --git a/examples/tutorial/embedded/MathFre.gf b/examples/tutorial/embedded/MathFre.gf
deleted file mode 100644
index 456db8084..000000000
--- a/examples/tutorial/embedded/MathFre.gf
+++ /dev/null
@@ -1,6 +0,0 @@
---# -path=.:present:prelude:mathematical
-
-concrete MathFre of Math = MathI with
- (Syntax = SyntaxFre),
- (Symbol = SymbolFre),
- (LexMath = LexMathFre) ;
diff --git a/examples/tutorial/embedded/MathI.gf b/examples/tutorial/embedded/MathI.gf
deleted file mode 100644
index aaac7b98f..000000000
--- a/examples/tutorial/embedded/MathI.gf
+++ /dev/null
@@ -1,23 +0,0 @@
-incomplete concrete MathI of Math =
- open Syntax, Symbol, LexMath in {
-
- flags startcat = Question ; lexer = textlit ; unlexer = text ;
-
- lincat
- Answer = Text ;
- Question = Text ;
- Object = NP ;
-
- lin
- Even = questAdj even_A ;
- Odd = questAdj odd_A ;
- Prime = questAdj prime_A ;
- Number n = mkNP (IntPN n) ;
-
- Yes = mkText yes_Phr ;
- No = mkText no_Phr ;
-
- oper
- questAdj : A -> NP -> Text = \adj,x -> mkText (mkQS (mkCl x adj)) ;
-
-}
diff --git a/examples/tutorial/embedded/TransferDef.hs b/examples/tutorial/embedded/TransferDef.hs
deleted file mode 100644
index 8be39107d..000000000
--- a/examples/tutorial/embedded/TransferDef.hs
+++ /dev/null
@@ -1,26 +0,0 @@
-module TransferDef 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 [] = []
diff --git a/examples/tutorial/embedded/TransferLoop.hs b/examples/tutorial/embedded/TransferLoop.hs
deleted file mode 100644
index 708578156..000000000
--- a/examples/tutorial/embedded/TransferLoop.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module Main where
-
-import GF.GFCC.API
-import TransferDef (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"
-
diff --git a/examples/tutorial/embedded/Translator.hs b/examples/tutorial/embedded/Translator.hs
deleted file mode 100644
index c227420f6..000000000
--- a/examples/tutorial/embedded/Translator.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-module Main where
-
-import GF.Embed.EmbedAPI
-import System (getArgs)
-
-main :: IO ()
-main = do
- file:_ <- getArgs
- gr <- file2grammar file
- interact (translate gr)
-
-translate :: MultiGrammar -> String -> String
-translate gr = unlines . map transLine . lines where
- transLine s =
- let (lang,tree:_):_ = parseAllLang gr (startCat gr) s
- in unlines [linearize gr lg tree | lg <- languages gr, lg /= lang]
diff --git a/examples/tutorial/embedded/TranslatorLoop.hs b/examples/tutorial/embedded/TranslatorLoop.hs
deleted file mode 100644
index 18b20146e..000000000
--- a/examples/tutorial/embedded/TranslatorLoop.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module Main where
-
-import GF.Embed.EmbedAPI
-import System (getArgs)
-
-main :: IO ()
-main = do
- file:_ <- getArgs
- gr <- file2grammar file
- loop (translate gr)
-
-loop :: (String -> String) -> IO ()
-loop trans = do
- s <- getLine
- if s == "quit" then putStrLn "bye" else do
- putStrLn $ trans s
- loop trans
-
-translate :: MultiGrammar -> String -> String
-translate gr = unlines . map transLine . lines where
- transLine s = case parseAllLang gr (startCat gr) s of
- (lg,t:_):_ -> unlines [linearize gr l t | l <- languages gr, l /= lg]
- _ -> "NO PARSE"
diff --git a/examples/tutorial/embedded/haskell/GSyntax.hs b/examples/tutorial/embedded/haskell/GSyntax.hs
deleted file mode 100644
index 28469e7da..000000000
--- a/examples/tutorial/embedded/haskell/GSyntax.hs
+++ /dev/null
@@ -1,100 +0,0 @@
-module GSyntax where
-
-import GF.Infra.Ident
-import GF.Grammar.Grammar
-import GF.Grammar.PrGrammar
-import GF.Grammar.Macros
-import GF.Data.Operations
-----------------------------------------------------
--- automatic translation from GF to Haskell
-----------------------------------------------------
-
-class Gf a where gf :: a -> Trm
-class Fg a where fg :: Trm -> a
-
-newtype GString = GString String deriving Show
-
-instance Gf GString where
- gf (GString s) = K s
-
-instance Fg GString where
- fg t =
- case termForm t of
- Ok ([], K s ,[]) -> GString s
- _ -> error ("no GString " ++ prt t)
-
-newtype GInt = GInt Integer deriving Show
-
-instance Gf GInt where
- gf (GInt s) = EInt s
-
-instance Fg GInt where
- fg t =
- case termForm t of
- Ok ([], EInt s ,[]) -> GInt s
- _ -> error ("no GInt " ++ prt t)
-
-newtype GFloat = GFloat Double deriving Show
-
-instance Gf GFloat where
- gf (GFloat s) = EFloat s
-
-instance Fg GFloat where
- fg t =
- case termForm t of
- Ok ([], EFloat s ,[]) -> GFloat s
- _ -> error ("no GFloat " ++ prt t)
-
-----------------------------------------------------
--- below this line machine-generated
-----------------------------------------------------
-
-data GAnswer =
- GYes
- | GNo
- deriving Show
-
-data GObject = GNumber GInt
- deriving Show
-
-data GQuestion =
- GPrime GObject
- | GOdd GObject
- | GEven GObject
- deriving Show
-
-
-instance Gf GAnswer where
- gf GYes = appqc "Math" "Yes" []
- gf GNo = appqc "Math" "No" []
-
-instance Gf GObject where gf (GNumber x1) = appqc "Math" "Number" [gf x1]
-
-instance Gf GQuestion where
- gf (GPrime x1) = appqc "Math" "Prime" [gf x1]
- gf (GOdd x1) = appqc "Math" "Odd" [gf x1]
- gf (GEven x1) = appqc "Math" "Even" [gf x1]
-
-
-instance Fg GAnswer where
- fg t =
- case termForm t of
- Ok ([], Q (IC "Math") (IC "Yes"),[]) -> GYes
- Ok ([], Q (IC "Math") (IC "No"),[]) -> GNo
- _ -> error ("no Answer " ++ prt t)
-
-instance Fg GObject where
- fg t =
- case termForm t of
- Ok ([], Q (IC "Math") (IC "Number"),[x1]) -> GNumber (fg x1)
- _ -> error ("no Object " ++ prt t)
-
-instance Fg GQuestion where
- fg t =
- case termForm t of
- Ok ([], Q (IC "Math") (IC "Prime"),[x1]) -> GPrime (fg x1)
- Ok ([], Q (IC "Math") (IC "Odd"),[x1]) -> GOdd (fg x1)
- Ok ([], Q (IC "Math") (IC "Even"),[x1]) -> GEven (fg x1)
- _ -> error ("no Question " ++ prt t)
-
-
diff --git a/examples/tutorial/embedded/haskell/Run.hs b/examples/tutorial/embedded/haskell/Run.hs
deleted file mode 100644
index c3fd87466..000000000
--- a/examples/tutorial/embedded/haskell/Run.hs
+++ /dev/null
@@ -1,38 +0,0 @@
-module Main where
-
-import GSyntax
-import GF.Embed.EmbedAPI
-
-main :: IO ()
-main = do
- gr <- file2grammar "math.gfcm"
- loop gr
-
-loop :: MultiGrammar -> IO ()
-loop gr = do
- s <- getLine
- interpret gr s
- loop gr
-
-interpret :: MultiGrammar -> String -> IO ()
-interpret gr s = do
- let ltss = parseAllLang gr "Question" s
- case ltss of
- [] -> putStrLn "no parse"
- (l,t:_):_ -> putStrLn $ linearize gr l $ gf $ answer $ fg t
-
-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 = (< 8) ----
diff --git a/examples/tutorial/food/food.ebnf b/examples/tutorial/food/food.ebnf
deleted file mode 100644
index d85739dad..000000000
--- a/examples/tutorial/food/food.ebnf
+++ /dev/null
@@ -1,4 +0,0 @@
-Phrase ::=
- ("this" | "that") Quality* ("wine" | "cheese" | "fish") "is" Quality ;
-Quality ::=
- ("very"* ("fresh" | "warm" | "boring" | "Italian" | "expensive")) ;
diff --git a/examples/tutorial/hello/hello.gfs b/examples/tutorial/hello/hello.gfs
index 783919e0e..3a18fee52 100644
--- a/examples/tutorial/hello/hello.gfs
+++ b/examples/tutorial/hello/hello.gfs
@@ -1,4 +1,4 @@
import HelloEng.gf
import HelloFin.gf
import HelloIta.gf
-linearize -multi Hello World
+linearize Hello World
diff --git a/examples/tutorial/semantics/Base.gf b/examples/tutorial/semantics/Base.gf
index 4586c3106..85868d7ac 100644
--- a/examples/tutorial/semantics/Base.gf
+++ b/examples/tutorial/semantics/Base.gf
@@ -30,7 +30,7 @@ fun
-- lexicon
- UseInt : Int -> PN ;
+ UseInt : Int -> PN ;
Number : CN ;
Even, Odd, Prime : AP ;
diff --git a/examples/tutorial/semantics/BaseI.gf b/examples/tutorial/semantics/BaseI.gf
index ec967e443..b7ed86666 100644
--- a/examples/tutorial/semantics/BaseI.gf
+++ b/examples/tutorial/semantics/BaseI.gf
@@ -32,7 +32,7 @@ lin
And = and_Conj ;
Or = or_Conj ;
- UseInt i = symb i ;
+ UseInt i = symb (i ** {lock_Int = <>}) ; ---- terrible to need this
Number = mkCN number_N ;
@@ -46,15 +46,15 @@ lin
Sum = prefix sum_N2 ;
Product = prefix product_N2 ;
- GCD nps = mkNP (mkDet (mkQuantSg defQuant) (mkOrd great_A))
+ GCD nps = mkNP (mkDet DefArt (mkOrd great_A))
(mkCN common_A (mkCN divisor_N2 (mkNP and_Conj nps))) ;
WhatIs np = mkPhr (mkQS (mkQCl whatSg_IP (mkVP np))) ;
- WhichAre cn ap = mkPhr (mkQS (mkQCl (mkIP whichPl_IDet cn) (mkVP ap))) ;
+ WhichAre cn ap = mkPhr (mkQS (mkQCl (mkIP which_IQuant cn) (mkVP ap))) ;
QuestS s = mkPhr (mkQS (mkQCl s)) ;
- Yes = yes_Phr ;
- No = no_Phr ;
+ Yes = mkPhr yes_Utt ;
+ No = mkPhr no_Utt ;
Value np = mkPhr (mkUtt np) ;
Many list = mkNP and_Conj list ;
@@ -65,6 +65,6 @@ lin
oper
prefix : G.N2 -> G.ListNP -> G.NP = \n2,nps ->
- mkNP defSgDet (mkCN n2 (mkNP and_Conj nps)) ;
+ mkNP DefArt (mkCN n2 (mkNP and_Conj nps)) ;
}
diff --git a/examples/tutorial/semantics/Core.gf b/examples/tutorial/semantics/Core.gf
deleted file mode 100644
index 975cf827f..000000000
--- a/examples/tutorial/semantics/Core.gf
+++ /dev/null
@@ -1,6 +0,0 @@
-abstract Core = {
-
- cat
-
-
-}
diff --git a/examples/tutorial/smart/SmartEng.gf b/examples/tutorial/smart/SmartEng.gf
index 384e50060..eff8a000a 100644
--- a/examples/tutorial/smart/SmartEng.gf
+++ b/examples/tutorial/smart/SmartEng.gf
@@ -1,6 +1,6 @@
--# -path=.:prelude
-concrete Toy1Eng of Toy1 = open Prelude in {
+concrete SmartEng of Smart = open Prelude in {
-- grammar Toy1 from the Regulus book
diff --git a/examples/tutorial/smart/SmartFre.gf b/examples/tutorial/smart/SmartFre.gf
index c5d903519..95b219b60 100644
--- a/examples/tutorial/smart/SmartFre.gf
+++ b/examples/tutorial/smart/SmartFre.gf
@@ -1,6 +1,6 @@
--# -path=.:prelude
-concrete Toy1Fre of Toy1 = open Prelude in {
+concrete SmartFre of Smart = open Prelude in {
-- grammar Toy1 from the Regulus book
diff --git a/examples/tutorial/syntax/FoodsEng.gf b/examples/tutorial/syntax/FoodsEng.gf
deleted file mode 100644
index fb8c44610..000000000
--- a/examples/tutorial/syntax/FoodsEng.gf
+++ /dev/null
@@ -1,5 +0,0 @@
---# -path=.:../foods:prelude
-
-concrete FoodsEng of Foods = FoodsI with
- (Syntax = SyntaxEng),
- (Test = TestEng) ;
diff --git a/examples/tutorial/syntax/FoodsI.gf b/examples/tutorial/syntax/FoodsI.gf
deleted file mode 100644
index d67302235..000000000
--- a/examples/tutorial/syntax/FoodsI.gf
+++ /dev/null
@@ -1,26 +0,0 @@
-incomplete concrete FoodsI of Foods = open Syntax, Test in {
- lincat
- Phrase = S ;
- Item = NP ;
- Kind = CN ;
- Quality = AP ;
- lin
- Is = mkS ;
- This = mkNP this_Det ;
- That = mkNP that_Det ;
- These = mkNP these_Det ;
- Those = mkNP those_Det ;
- QKind = mkCN ;
- Very = mkAP very_AdA ;
-
- Wine = mkCN wine_N ;
- Pizza = mkCN pizza_N ;
- Cheese = mkCN cheese_N ;
- Fish = mkCN fish_N ;
- Fresh = mkAP fresh_A ;
- Warm = mkAP warm_A ;
- Italian = mkAP italian_A ;
- Expensive = mkAP expensive_A ;
- Delicious = mkAP delicious_A ;
- Boring = mkAP boring_A ;
-}
diff --git a/examples/tutorial/syntax/FoodsIta.gf b/examples/tutorial/syntax/FoodsIta.gf
deleted file mode 100644
index 57beab918..000000000
--- a/examples/tutorial/syntax/FoodsIta.gf
+++ /dev/null
@@ -1,5 +0,0 @@
---# -path=.:../foods:prelude
-
-concrete FoodsIta of Foods = FoodsI with
- (Syntax = SyntaxIta),
- (Test = TestIta) ;
diff --git a/examples/tutorial/syntax/Syntax.gf b/examples/tutorial/syntax/Syntax.gf
index 31f3fc127..e5b27504d 100644
--- a/examples/tutorial/syntax/Syntax.gf
+++ b/examples/tutorial/syntax/Syntax.gf
@@ -10,17 +10,17 @@ oper
mkS = overload {
mkS : Pol -> NP -> VP -> S
- = PredVP ;
+ = \p,np,vp -> UseCl p (PredVP np vp) ;
mkS : NP -> VP -> S
- = PredVP PPos ;
+ = \np,vp -> UseCl PPos (PredVP np vp) ;
mkS : Pol -> NP -> V2 -> NP -> S
- = \p,np,v,o -> PredVP p np (ComplV2 v o) ;
+ = \p,np,v,o -> UseCl p (PredVP np (ComplV2 v o)) ;
mkS : NP -> V2 -> NP -> S
- = \np,v,o -> PredVP PPos np (ComplV2 v o) ;
+ = \np,v,o -> UseCl PPos (PredVP np (ComplV2 v o)) ;
mkS : Pol -> NP -> AP -> S
- = \p,np,ap -> PredVP p np (ComplAP ap) ;
+ = \p,np,ap -> UseCl p (PredVP np (ComplAP ap)) ;
mkS : NP -> AP -> S
- = \np,ap -> PredVP PPos np (ComplAP ap) ;
+ = \np,ap -> UseCl PPos (PredVP np (ComplAP ap)) ;
} ;
mkNP : Det -> CN -> NP