summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--book/examples/chapter2/Copy.gf7
-rw-r--r--book/examples/chapter2/CopyAbs.gf6
-rw-r--r--book/examples/chapter2/Food.gf13
-rw-r--r--book/examples/chapter2/FoodEng.gf19
-rw-r--r--book/examples/chapter2/FoodHin.gf24
-rw-r--r--book/examples/chapter2/FoodIta.gf19
-rw-r--r--book/examples/chapter2/Letters.gf8
-rw-r--r--book/examples/chapter2/LettersCnc.gf31
-rw-r--r--book/examples/chapter2/Strings.gf7
-rw-r--r--book/examples/chapter2/StringsBW.gf5
-rw-r--r--book/examples/chapter2/StringsFW.gf5
-rw-r--r--book/examples/chapter2/Ticket.gf10
-rw-r--r--book/examples/chapter2/TicketEng.gf19
-rw-r--r--book/examples/chapter3/Arabic.gf118
-rw-r--r--book/examples/chapter3/Discont.gf11
-rw-r--r--book/examples/chapter3/DiscontEng.gf21
-rw-r--r--book/examples/chapter3/Foods.gf13
-rw-r--r--book/examples/chapter3/FoodsEng.gf40
-rw-r--r--book/examples/chapter3/FoodsIta.gf32
-rw-r--r--book/examples/chapter3/ResIta.gf36
-rw-r--r--book/examples/chapter4/Clothes.gf5
-rw-r--r--book/examples/chapter4/ClothesEng.gf10
-rw-r--r--book/examples/chapter4/ClothesIta.gf8
-rw-r--r--book/examples/chapter4/Comment.gf13
-rw-r--r--book/examples/chapter4/Comments.gf10
-rw-r--r--book/examples/chapter4/CommentsEng.gf4
-rw-r--r--book/examples/chapter4/CommentsI.gf15
-rw-r--r--book/examples/chapter4/CommentsIta.gf4
-rw-r--r--book/examples/chapter4/Computers.gf5
-rw-r--r--book/examples/chapter4/ComputersEng.gf10
-rw-r--r--book/examples/chapter4/ComputersIta.gf9
-rw-r--r--book/examples/chapter4/Exx.gf16
-rw-r--r--book/examples/chapter4/Foods.gf6
-rw-r--r--book/examples/chapter4/FoodsEng.gf16
-rw-r--r--book/examples/chapter4/FoodsIta.gf16
-rw-r--r--book/examples/chapter4/Shopping.gf2
-rw-r--r--book/examples/chapter4/ShoppingEng.gf4
-rw-r--r--book/examples/chapter4/ShoppingIta.gf4
-rw-r--r--book/examples/chapter4/SmallShopping.gf3
-rw-r--r--book/examples/chapter5/Foods.gf15
-rw-r--r--book/examples/chapter5/FoodsCat.gf7
-rw-r--r--book/examples/chapter5/FoodsEng.gf27
-rw-r--r--book/examples/chapter5/FoodsFin.gf7
-rw-r--r--book/examples/chapter5/FoodsGer.gf7
-rw-r--r--book/examples/chapter5/FoodsI.gf29
-rw-r--r--book/examples/chapter5/FoodsIta.gf8
-rw-r--r--book/examples/chapter5/FoodsSwe.gf7
-rw-r--r--book/examples/chapter5/LexFoods.gf15
-rw-r--r--book/examples/chapter5/LexFoodsCat.gf18
-rw-r--r--book/examples/chapter5/LexFoodsEng.gf20
-rw-r--r--book/examples/chapter5/LexFoodsFin.gf20
-rw-r--r--book/examples/chapter5/LexFoodsGer.gf16
-rw-r--r--book/examples/chapter5/LexFoodsIta.gf16
-rw-r--r--book/examples/chapter5/LexFoodsSwe.gf16
-rw-r--r--book/examples/chapter6/Aggregation.gf33
-rw-r--r--book/examples/chapter6/AggregationEng.gf17
-rw-r--r--book/examples/chapter6/Bin.gf50
-rw-r--r--book/examples/chapter6/Classes.gf28
-rw-r--r--book/examples/chapter6/ClassesEng.gf29
-rw-r--r--book/examples/chapter6/DShopping.gf24
-rw-r--r--book/examples/chapter6/DShoppingEng.gf33
-rw-r--r--book/examples/chapter6/Nat.gf22
-rw-r--r--book/examples/chapter6/Verbs.gf22
-rw-r--r--book/examples/chapter6/VerbsEng.gf22
-rw-r--r--book/examples/chapter7/Query.gf12
-rw-r--r--book/examples/chapter7/QueryEng.gf13
-rw-r--r--book/examples/chapter7/QueryFin.gf13
-rw-r--r--book/examples/chapter8/Calculator.gf7
-rw-r--r--book/examples/chapter8/CalculatorC.gf10
-rw-r--r--book/examples/chapter8/CalculatorJ.gf13
-rw-r--r--book/examples/chapter8/CalculatorP.gf14
-rw-r--r--book/examples/chapter8/CalculatorS.gf11
-rw-r--r--book/examples/chapter8/Geometry.gf7
-rw-r--r--book/examples/chapter8/GeometryEng.gf13
-rw-r--r--book/examples/chapter8/GeometryEngb.gf11
-rw-r--r--book/examples/chapter8/Geometryb.gf7
-rw-r--r--book/examples/chapter8/Logic.gf21
-rw-r--r--book/examples/chapter8/LogicBEng.gf38
-rw-r--r--book/examples/chapter8/LogicEng.gf39
-rw-r--r--book/examples/chapter8/Logicb.gf11
-rw-r--r--book/examples/chapter9/Anaphora.gf17
-rw-r--r--book/examples/chapter9/AnaphoraIta.gf17
-rw-r--r--book/examples/chapter9/Grammar.gf39
-rw-r--r--book/examples/chapter9/GrammarIta.gf141
-rw-r--r--book/examples/chapter9/Logic.gf9
-rw-r--r--book/examples/chapter9/LogicIta.gf54
-rw-r--r--book/examples/chapter9/LogicSymb.gf13
-rw-r--r--book/examples/chapter9/ParadigmsIta.gf47
-rw-r--r--book/examples/chapter9/ResIta.gf178
-rw-r--r--book/examples/chapter9/Semantics.gf39
-rw-r--r--book/examples/chapter9/SemanticsIta.gf42
-rw-r--r--book/examples/chapter9/Syntax.gf47
-rw-r--r--book/examples/chapter9/SyntaxIta.gf3
-rw-r--r--book/examples/chapter9/Test.gf9
-rw-r--r--book/examples/chapter9/TestIta.gf17
-rw-r--r--book/examples/chapter9/TestSemantics.gf1
-rw-r--r--book/examples/chapter9/TestSemanticsIta.gf1
97 files changed, 2026 insertions, 0 deletions
diff --git a/book/examples/chapter2/Copy.gf b/book/examples/chapter2/Copy.gf
new file mode 100644
index 000000000..58d74861c
--- /dev/null
+++ b/book/examples/chapter2/Copy.gf
@@ -0,0 +1,7 @@
+concrete Copy of CopyAbs = {
+ lincat S, AB = Str ;
+ lin s x = x ++ x ;
+ end = [] ;
+ a x = "a" ++ x ;
+ b x = "b" ++ x ;
+}
diff --git a/book/examples/chapter2/CopyAbs.gf b/book/examples/chapter2/CopyAbs.gf
new file mode 100644
index 000000000..9a915568b
--- /dev/null
+++ b/book/examples/chapter2/CopyAbs.gf
@@ -0,0 +1,6 @@
+abstract CopyAbs = {
+ cat S ; AB ;
+ fun s : AB -> S ;
+ end : AB ;
+ a,b : AB -> AB ;
+}
diff --git a/book/examples/chapter2/Food.gf b/book/examples/chapter2/Food.gf
new file mode 100644
index 000000000..7cf779b4c
--- /dev/null
+++ b/book/examples/chapter2/Food.gf
@@ -0,0 +1,13 @@
+abstract Food = {
+ flags startcat = Comment ;
+ cat
+ Comment ; Item ; Kind ; Quality ;
+ fun
+ Pred : Item -> Quality -> Comment ;
+ This, That : Kind -> Item ;
+ Mod : Quality -> Kind -> Kind ;
+ Wine, Cheese, Fish : Kind ;
+ Very : Quality -> Quality ;
+ Fresh, Warm, Italian,
+ Expensive, Delicious, Boring : Quality ;
+}
diff --git a/book/examples/chapter2/FoodEng.gf b/book/examples/chapter2/FoodEng.gf
new file mode 100644
index 000000000..f2ed510fe
--- /dev/null
+++ b/book/examples/chapter2/FoodEng.gf
@@ -0,0 +1,19 @@
+concrete FoodEng of Food = {
+ lincat
+ Comment, Item, Kind, Quality = Str ;
+ lin
+ Pred item quality = item ++ "is" ++ quality ;
+ This kind = "this" ++ kind ;
+ That kind = "that" ++ kind ;
+ Mod quality kind = quality ++ kind ;
+ Wine = "wine" ;
+ Cheese = "cheese" ;
+ Fish = "fish" ;
+ Very quality = "very" ++ quality ;
+ Fresh = "fresh" ;
+ Warm = "warm" ;
+ Italian = "Italian" ;
+ Expensive = "expensive" ;
+ Delicious = "delicious" ;
+ Boring = "boring" ;
+}
diff --git a/book/examples/chapter2/FoodHin.gf b/book/examples/chapter2/FoodHin.gf
new file mode 100644
index 000000000..0f6f25c5e
--- /dev/null
+++ b/book/examples/chapter2/FoodHin.gf
@@ -0,0 +1,24 @@
+
+ concrete FoodHin of Food = {
+ flags coding = utf8 ;
+ lincat Comment, Item, Kind, Quality = Str ;
+ lin
+ Pred item quality = item ++ quality ++ "है" ;
+ This kind = "यह" ++ kind ;
+ That kind = "वह" ++ kind ;
+ Mod quality kind = quality ++ kind ;
+ Wine = "मदिरा" ;
+ Cheese = "पनीर" ;
+ Fish = "मछली" ;
+ Very quality = "अति" ++ quality ;
+ Fresh = "ताज़ा" ;
+ Warm = "गरम" ;
+ Italian = "इटली" ;
+ Expensive = "बहुमूल्य" ;
+ Delicious = "स्वादिष्ट" ;
+ Boring = "अरुचिकर" ;
+ }
+
+
+
+
diff --git a/book/examples/chapter2/FoodIta.gf b/book/examples/chapter2/FoodIta.gf
new file mode 100644
index 000000000..466104432
--- /dev/null
+++ b/book/examples/chapter2/FoodIta.gf
@@ -0,0 +1,19 @@
+concrete FoodIta of Food = {
+ lincat
+ Comment, Item, Kind, Quality = Str ;
+ lin
+ Pred item quality = item ++ "" ++ quality ;
+ This kind = "questo" ++ kind ;
+ That kind = "quel" ++ kind ;
+ Mod quality kind = kind ++ quality ;
+ Wine = "vino" ;
+ Cheese = "formaggio" ;
+ Fish = "pesce" ;
+ Very quality = "molto" ++ quality ;
+ Fresh = "fresco" ;
+ Warm = "caldo" ;
+ Italian = "italiano" ;
+ Expensive = "caro" ;
+ Delicious = "delizioso" ;
+ Boring = "noioso" ;
+}
diff --git a/book/examples/chapter2/Letters.gf b/book/examples/chapter2/Letters.gf
new file mode 100644
index 000000000..2b5a62d2d
--- /dev/null
+++ b/book/examples/chapter2/Letters.gf
@@ -0,0 +1,8 @@
+abstract Letters = {
+
+cat L ;
+fun
+ a, b, c, d, e, f, g, h, i, j, k, l, m,
+ n, o, p, q, r, s, t, u, v, w, x, y, z : L ;
+
+}
diff --git a/book/examples/chapter2/LettersCnc.gf b/book/examples/chapter2/LettersCnc.gf
new file mode 100644
index 000000000..3301f5465
--- /dev/null
+++ b/book/examples/chapter2/LettersCnc.gf
@@ -0,0 +1,31 @@
+concrete LettersCnc of Letters = {
+
+ lincat L = Str ;
+ lin
+ a = "a" ;
+ b = "b" ;
+ c = "c" ;
+ d = "d" ;
+ e = "e" ;
+ f = "f" ;
+ g = "g" ;
+ h = "h" ;
+ i = "i" ;
+ j = "j" ;
+ k = "k" ;
+ l = "l" ;
+ m = "m" ;
+ n = "n" ;
+ o = "o" ;
+ p = "p" ;
+ q = "q" ;
+ r = "r" ;
+ s = "s" ;
+ t = "t" ;
+ u = "u" ;
+ v = "v" ;
+ w = "w" ;
+ x = "x" ;
+ y = "y" ;
+ z = "z" ;
+}
diff --git a/book/examples/chapter2/Strings.gf b/book/examples/chapter2/Strings.gf
new file mode 100644
index 000000000..411ceed53
--- /dev/null
+++ b/book/examples/chapter2/Strings.gf
@@ -0,0 +1,7 @@
+abstract Strings = Letters ** {
+
+cat S ;
+fun
+ E : S ;
+ C : L -> S -> S ;
+}
diff --git a/book/examples/chapter2/StringsBW.gf b/book/examples/chapter2/StringsBW.gf
new file mode 100644
index 000000000..8e558d953
--- /dev/null
+++ b/book/examples/chapter2/StringsBW.gf
@@ -0,0 +1,5 @@
+concrete StringsBW of Strings = LettersCnc ** {
+ lincat S = Str ;
+ lin E = [] ;
+ lin C head tail = tail ++ head ;
+}
diff --git a/book/examples/chapter2/StringsFW.gf b/book/examples/chapter2/StringsFW.gf
new file mode 100644
index 000000000..c0f80c313
--- /dev/null
+++ b/book/examples/chapter2/StringsFW.gf
@@ -0,0 +1,5 @@
+concrete StringsFW of Strings = LettersCnc ** {
+ lincat S = Str ;
+ lin E = [] ;
+ lin C head tail = head ++ tail ;
+}
diff --git a/book/examples/chapter2/Ticket.gf b/book/examples/chapter2/Ticket.gf
new file mode 100644
index 000000000..f3f2dd851
--- /dev/null
+++ b/book/examples/chapter2/Ticket.gf
@@ -0,0 +1,10 @@
+abstract Ticket = {
+
+flags startcat = Request ;
+cat
+ Request ; Station ;
+fun
+ Ticket : Station -> Station -> Request ;
+ Hamburg, Paris : Station ;
+
+}
diff --git a/book/examples/chapter2/TicketEng.gf b/book/examples/chapter2/TicketEng.gf
new file mode 100644
index 000000000..54e44741d
--- /dev/null
+++ b/book/examples/chapter2/TicketEng.gf
@@ -0,0 +1,19 @@
+concrete TicketEng of Ticket = {
+
+lincat
+ Request, Station = Str ;
+lin
+ Ticket X Y =
+ ((("I" ++ ("would like" | "want") ++ "to get" |
+ ("may" | "can") ++ "I get" |
+ "can you give me" |
+ []) ++
+ "a ticket") |
+ []) ++
+ "from" ++ X ++ "to" ++ Y ++
+ ("please" | []) ;
+
+ Hamburg = "Hamburg" ;
+ Paris = "Paris" ;
+
+}
diff --git a/book/examples/chapter3/Arabic.gf b/book/examples/chapter3/Arabic.gf
new file mode 100644
index 000000000..e00d02c23
--- /dev/null
+++ b/book/examples/chapter3/Arabic.gf
@@ -0,0 +1,118 @@
+resource Arabic = {
+oper
+ Root : Type = {F,C,L : Str} ;
+ Pattern : Type = Root -> Str ;
+
+ Filling : Type = {F,FC,CL,L : Str} ;
+
+ fill : Filling -> Root -> Str = \p,r ->
+ p.F + r.F + p.FC + r.C + p.CL + r.L + p.L ;
+
+ dfill : Filling -> Root -> Str = \p,r ->
+ p.F + r.F + p.FC + r.C + r.C + p.CL + r.L + p.L ;
+
+ getRoot : Str -> Root = \s -> case s of {
+ F@? + C@? + L@? => {F = F ; C = C ; L = L} ;
+ _ => Predef.error ("cannot get root from" ++ s)
+ } ;
+
+ getPattern : Str -> Pattern = \s -> case s of {
+ F + "F" + FC + "CC" + CL + "L" + L =>
+ dfill {F = F ; FC = FC ; CL = CL ; L = L} ;
+ F + "F" + FC + "C" + CL + "L" + L =>
+ fill {F = F ; FC = FC ; CL = CL ; L = L} ;
+ _ => Predef.error ("cannot get pattern from" ++ s)
+ } ;
+
+ word : Str -> Str -> Str = \p,r ->
+ getPattern p (getRoot r) ;
+
+param
+ Number = Sg | Dl | Pl ;
+ Gender = Masc | Fem ;
+ Tense = Perf | Impf ;
+
+ VPer = Vp3 Number Gender | Vp2Sg Gender | Vp2Dl | Vp2Pl Gender | Vp1Sg | Vp1Pl ;
+
+oper
+ Verb : Type = {s : Tense => VPer => Str} ;
+
+ pattV_u : Tense -> VPer -> Pattern = \t,v -> getPattern (case t of {
+ Perf => case v of {
+ Vp3 Sg Masc => "FaCaLa" ;
+ Vp3 Sg Fem => "FaCaLat" ;
+ Vp3 Dl Masc => "FaCaLaA" ;
+ Vp3 Dl Fem => "FaCaLataA" ;
+ Vp3 Pl Masc => "FaCaLuwA" ;
+ Vp3 Pl Fem => "FaCaLona" ;
+
+ Vp2Sg Masc => "FaCaLota" ;
+ Vp2Sg Fem => "FaCaLoti" ;
+ Vp2Dl => "FaCaLotumaA" ;
+ Vp2Pl Masc => "FaCaLotum" ;
+ Vp2Pl Fem => "FaCaLotunv2a" ;
+
+ Vp1Sg => "FaCaLotu" ;
+ Vp1Pl => "FaCaLonaA"
+ } ;
+ Impf => case v of {
+ Vp3 Sg Masc => "yaFoCuLu" ;
+ Vp3 Sg Fem => "taFoCuLu" ;
+ Vp3 Dl Masc => "yaFoCuLaAni" ;
+ Vp3 Dl Fem => "taFoCuLaAni" ;
+ Vp3 Pl Masc => "yaFoCuLuwna" ;
+ Vp3 Pl Fem => "yaFoCuLna" ;
+
+ Vp2Sg Masc => "taFoCuLu" ;
+ Vp2Sg Fem => "taFoCuLiyna" ;
+ Vp2Dl => "taFoCuLaAni" ;
+ Vp2Pl Masc => "taFoCuLuwna" ;
+ Vp2Pl Fem => "taFoCuLona" ;
+
+ Vp1Sg => "A?aFoCuLu" ;
+ Vp1Pl => "naFoCuLu"
+ }
+ }) ;
+
+ u_Verb : Str -> Verb = \s -> {
+ s = \\t,p => pattV_u t p (getRoot s) ;
+ } ;
+
+-- for html
+
+ tag : Str -> Str = \t -> "<" + t + ">" ;
+ etag : Str -> Str = \t -> "</" + t + ">" ;
+ atag : Str -> Str -> Str = \t,a -> "<" + t ++ a + ">" ;
+
+ intag : Str -> Str -> Str = \t,s -> tag t ++ s ++ etag t ;
+ intagAttr : Str -> Str -> Str -> Str = \t,a,s -> atag t a ++ s ++ etag t ;
+
+ verbTable : Verb -> Str = \v ->
+ let
+ vsp = v.s ! Perf ;
+ vsi = v.s ! Impf ;
+ tr : Str -> Str = intag "tr" ;
+ td : Str -> Str = intag "td" ;
+ ts : Str -> Str = \s -> td ("\"" ++ s ++ "\"") ;
+ trs : Str -> Str -> VPer -> Str = \s,n,v ->
+ tr (td s ++ td n ++ ts (vsp ! v) ++ ts (vsi ! v))
+ in
+ intagAttr "table" "border=1" (
+ tr ((td "Persona") ++ (td "Numerus") ++ (td "Perfectum") ++ (td "Imperfectum")) ++
+ trs "3. masc." "sing." (Vp3 Sg Masc) ++
+ trs "3. fem." "sing." (Vp3 Sg Fem) ++
+ trs "2. masc." "sing." (Vp2Sg Masc) ++
+ trs "2. fem." "sing." (Vp2Sg Fem) ++
+ trs "1." "sing." (Vp1Sg) ++
+ trs "3. masc." "dual." (Vp3 Dl Masc) ++
+ trs "3. fem." "dual." (Vp3 Dl Fem) ++
+ trs "2." "dual." (Vp2Dl) ++
+ trs "3. masc." "plur." (Vp3 Pl Masc) ++
+ trs "3. fem." "plur." (Vp3 Pl Fem) ++
+ trs "2. masc." "plur." (Vp2Pl Masc) ++
+ trs "2. fem." "plur." (Vp2Pl Fem) ++
+ trs "1." "plur." (Vp1Pl)
+ ) ;
+
+
+}
diff --git a/book/examples/chapter3/Discont.gf b/book/examples/chapter3/Discont.gf
new file mode 100644
index 000000000..879bedc4c
--- /dev/null
+++ b/book/examples/chapter3/Discont.gf
@@ -0,0 +1,11 @@
+abstract Discont = {
+ cat
+ S ; Cl ; NP ; VP ; AP ;
+ fun
+ DeclCl : Cl -> S ;
+ QuestCl : Cl -> S ;
+ PredVP : NP -> VP -> Cl ;
+ CompAP : AP -> VP ;
+ John : NP ;
+ Old : AP ;
+}
diff --git a/book/examples/chapter3/DiscontEng.gf b/book/examples/chapter3/DiscontEng.gf
new file mode 100644
index 000000000..93d70a02c
--- /dev/null
+++ b/book/examples/chapter3/DiscontEng.gf
@@ -0,0 +1,21 @@
+concrete DiscontEng of Discont = {
+ param
+ SForm = SDecl | SQuest ;
+ lincat
+ S, NP, AP = Str ;
+ Cl = SForm => Str ;
+ VP = {verb,comp : Str} ;
+ lin
+ DeclCl cl = cl ! SDecl ;
+ QuestCl cl = cl ! SQuest ;
+ PredVP np vp = table {
+ SDecl => np ++ vp.verb ++ vp.comp ;
+ SQuest => vp.verb ++ np ++ vp.comp
+ } ;
+ CompAP ap = {
+ verb = "is" ;
+ comp = ap
+ } ;
+ John = "John" ;
+ Old = "old" ;
+}
diff --git a/book/examples/chapter3/Foods.gf b/book/examples/chapter3/Foods.gf
new file mode 100644
index 000000000..e60f0ea09
--- /dev/null
+++ b/book/examples/chapter3/Foods.gf
@@ -0,0 +1,13 @@
+abstract Foods = {
+ flags startcat = Comment ;
+ cat
+ Comment ; Item ; Kind ; Quality ;
+ fun
+ Pred : Item -> Quality -> Comment ;
+ This, That, These, Those : Kind -> Item ;
+ Mod : Quality -> Kind -> Kind ;
+ Wine, Cheese, Fish, Pizza : Kind ;
+ Very : Quality -> Quality ;
+ Fresh, Warm, Italian,
+ Expensive, Delicious, Boring : Quality ;
+}
diff --git a/book/examples/chapter3/FoodsEng.gf b/book/examples/chapter3/FoodsEng.gf
new file mode 100644
index 000000000..82bae2148
--- /dev/null
+++ b/book/examples/chapter3/FoodsEng.gf
@@ -0,0 +1,40 @@
+concrete FoodsEng of Foods = {
+ lincat
+ Comment, Quality = {s : Str} ;
+ Kind = {s : Number => Str} ;
+ Item = {s : Str ; n : Number} ;
+ lin
+ Pred item quality =
+ {s = item.s ++ copula ! item.n ++ quality.s} ;
+ This = det Sg "this" ;
+ That = det Sg "that" ;
+ These = det Pl "these" ;
+ Those = det Pl "those" ;
+ Mod quality kind =
+ {s = \\n => quality.s ++ kind.s ! n} ;
+ Wine = regNoun "wine" ;
+ Cheese = regNoun "cheese" ;
+ Fish = noun "fish" "fish" ;
+ Pizza = regNoun "pizza" ;
+ Very a = {s = "very" ++ a.s} ;
+ Fresh = adj "fresh" ;
+ Warm = adj "warm" ;
+ Italian = adj "Italian" ;
+ Expensive = adj "expensive" ;
+ Delicious = adj "delicious" ;
+ Boring = adj "boring" ;
+ param
+ Number = Sg | Pl ;
+ oper
+ det : Number -> Str ->
+ {s : Number => Str} -> {s : Str ; n : Number} =
+ \n,det,noun -> {s = det ++ noun.s ! n ; n = n} ;
+ noun : Str -> Str -> {s : Number => Str} =
+ \man,men -> {s = table {Sg => man ; Pl => men}} ;
+ regNoun : Str -> {s : Number => Str} =
+ \car -> noun car (car + "s") ;
+ adj : Str -> {s : Str} =
+ \cold -> {s = cold} ;
+ copula : Number => Str =
+ table {Sg => "is" ; Pl => "are"} ;
+}
diff --git a/book/examples/chapter3/FoodsIta.gf b/book/examples/chapter3/FoodsIta.gf
new file mode 100644
index 000000000..6f7015694
--- /dev/null
+++ b/book/examples/chapter3/FoodsIta.gf
@@ -0,0 +1,32 @@
+concrete FoodsIta of Foods = open ResIta in {
+ lincat
+ Comment = {s : Str} ;
+ Quality = Adjective ;
+ Kind = Noun ;
+ Item = NounPhrase ;
+ lin
+ Pred item quality =
+ {s = item.s ++ copula ! item.n ++
+ quality.s ! item.g ! item.n} ;
+ This = det Sg "questo" "questa" ;
+ That = det Sg "quel" "quella" ;
+ These = det Pl "questi" "queste" ;
+ Those = det Pl "quei" "quelle" ;
+ Mod quality kind = {
+ s = \\n => kind.s ! n ++ quality.s ! kind.g ! n ;
+ g = kind.g
+ } ;
+ Wine = noun "vino" "vini" Masc ;
+ Cheese = noun "formaggio" "formaggi" Masc ;
+ Fish = noun "pesce" "pesci" Masc ;
+ Pizza = noun "pizza" "pizze" Fem ;
+ Very qual = {s = \\g,n => "molto" ++ qual.s ! g ! n} ;
+ Fresh =
+ adjective "fresco" "fresca" "freschi" "fresche" ;
+ Warm = regAdj "caldo" ;
+ Italian = regAdj "italiano" ;
+ Expensive = regAdj "caro" ;
+ Delicious = regAdj "delizioso" ;
+ Boring = regAdj "noioso" ;
+}
+
diff --git a/book/examples/chapter3/ResIta.gf b/book/examples/chapter3/ResIta.gf
new file mode 100644
index 000000000..17809c498
--- /dev/null
+++ b/book/examples/chapter3/ResIta.gf
@@ -0,0 +1,36 @@
+resource ResIta = open Prelude in {
+ param
+ Number = Sg | Pl ;
+ Gender = Masc | Fem ;
+ oper
+ NounPhrase : Type =
+ {s : Str ; g : Gender ; n : Number} ;
+ Noun : Type = {s : Number => Str ; g : Gender} ;
+ Adjective : Type = {s : Gender => Number => Str} ;
+
+ det : Number -> Str -> Str -> Noun -> NounPhrase =
+ \n,m,f,cn -> {
+ s = table {Masc => m ; Fem => f} ! cn.g ++
+ cn.s ! n ;
+ g = cn.g ;
+ n = n
+ } ;
+ noun : Str -> Str -> Gender -> Noun =
+ \vino,vini,g -> {
+ s = table {Sg => vino ; Pl => vini} ;
+ g = g
+ } ;
+ adjective : (nero,nera,neri,nere : Str) -> Adjective =
+ \nero,nera,neri,nere -> {
+ s = table {
+ Masc => table {Sg => nero ; Pl => neri} ;
+ Fem => table {Sg => nera ; Pl => nere}
+ }
+ } ;
+ regAdj : Str -> Adjective = \nero ->
+ let ner : Str = init nero
+ in
+ adjective nero (ner+"a") (ner+"i") (ner+"e") ;
+ copula : Number => Str =
+ table {Sg => "" ; Pl => "sono"} ;
+}
diff --git a/book/examples/chapter4/Clothes.gf b/book/examples/chapter4/Clothes.gf
new file mode 100644
index 000000000..e17400a27
--- /dev/null
+++ b/book/examples/chapter4/Clothes.gf
@@ -0,0 +1,5 @@
+abstract Clothes = Comments ** {
+ fun
+ Shirt, Jacket : Kind ;
+ Comfortable, Elegant : Quality ;
+}
diff --git a/book/examples/chapter4/ClothesEng.gf b/book/examples/chapter4/ClothesEng.gf
new file mode 100644
index 000000000..d45a8ce30
--- /dev/null
+++ b/book/examples/chapter4/ClothesEng.gf
@@ -0,0 +1,10 @@
+--# -path=.:present
+
+concrete ClothesEng of Clothes = CommentsEng **
+ open SyntaxEng, ParadigmsEng in {
+ lin
+ Shirt = mkCN (mkN "shirt") ;
+ Jacket = mkCN (mkN "jacket") ;
+ Comfortable = mkAP (mkA "comfortable") ;
+ Elegant = mkAP (mkA "elega") ;
+}
diff --git a/book/examples/chapter4/ClothesIta.gf b/book/examples/chapter4/ClothesIta.gf
new file mode 100644
index 000000000..fc4415b07
--- /dev/null
+++ b/book/examples/chapter4/ClothesIta.gf
@@ -0,0 +1,8 @@
+concrete ClothesIta of Clothes = CommentsIta **
+ open SyntaxIta, ParadigmsIta in {
+ lin
+ Shirt = mkCN (mkN "camicia") ;
+ Jacket = mkCN (mkN "giacca") ;
+ Comfortable = mkAP (mkA "comodo") ;
+ Elegant = mkAP (mkA "elegante") ;
+}
diff --git a/book/examples/chapter4/Comment.gf b/book/examples/chapter4/Comment.gf
new file mode 100644
index 000000000..0a812c6ef
--- /dev/null
+++ b/book/examples/chapter4/Comment.gf
@@ -0,0 +1,13 @@
+abstract Comment = {
+ flags startcat = Comment ;
+ cat
+ Comment ; Item ; Kind ; Quality ;
+ fun
+ Pred : Item -> Quality -> Comment ;
+ This, That, These, Those : Kind -> Item ;
+ Mod : Quality -> Kind -> Kind ;
+ Wine, Cheese, Fish, Pizza : Kind ;
+ Very : Quality -> Quality ;
+ Fresh, Warm, Italian,
+ Expensive, Delicious, Boring : Quality ;
+}
diff --git a/book/examples/chapter4/Comments.gf b/book/examples/chapter4/Comments.gf
new file mode 100644
index 000000000..ba36024f3
--- /dev/null
+++ b/book/examples/chapter4/Comments.gf
@@ -0,0 +1,10 @@
+abstract Comments = {
+ flags startcat = Comment ;
+ cat
+ Comment ; Item ; Kind ; Quality ;
+ fun
+ Pred : Item -> Quality -> Comment ;
+ This, That, These, Those : Kind -> Item ;
+ Mod : Quality -> Kind -> Kind ;
+ Very : Quality -> Quality ;
+}
diff --git a/book/examples/chapter4/CommentsEng.gf b/book/examples/chapter4/CommentsEng.gf
new file mode 100644
index 000000000..8fe3ed965
--- /dev/null
+++ b/book/examples/chapter4/CommentsEng.gf
@@ -0,0 +1,4 @@
+--# -path=.:present
+
+concrete CommentsEng of Comments = CommentsI with
+ (Syntax = SyntaxEng) ;
diff --git a/book/examples/chapter4/CommentsI.gf b/book/examples/chapter4/CommentsI.gf
new file mode 100644
index 000000000..b7cf0e8f7
--- /dev/null
+++ b/book/examples/chapter4/CommentsI.gf
@@ -0,0 +1,15 @@
+incomplete concrete CommentsI of Comments = open Syntax in {
+ lincat
+ Comment = Cl ;
+ Item = NP ;
+ Kind = CN ;
+ Quality = AP ;
+ lin
+ Pred item quality = mkCl item quality ;
+ This kind = mkNP this_QuantSg kind ;
+ That kind = mkNP that_QuantSg kind ;
+ These kind = mkNP these_QuantPl kind ;
+ Those kind = mkNP those_QuantPl kind ;
+ Mod quality kind = mkCN quality kind ;
+ Very quality = mkAP very_AdA quality ;
+}
diff --git a/book/examples/chapter4/CommentsIta.gf b/book/examples/chapter4/CommentsIta.gf
new file mode 100644
index 000000000..c9010c939
--- /dev/null
+++ b/book/examples/chapter4/CommentsIta.gf
@@ -0,0 +1,4 @@
+--# -path=.:present
+
+concrete CommentsIta of Comments = CommentsI with
+ (Syntax = SyntaxIta) ;
diff --git a/book/examples/chapter4/Computers.gf b/book/examples/chapter4/Computers.gf
new file mode 100644
index 000000000..6bbafd215
--- /dev/null
+++ b/book/examples/chapter4/Computers.gf
@@ -0,0 +1,5 @@
+abstract Computers = Comments ** {
+ fun
+ Computer, HardDisk : Kind ;
+ Efficient, Slow : Quality ;
+}
diff --git a/book/examples/chapter4/ComputersEng.gf b/book/examples/chapter4/ComputersEng.gf
new file mode 100644
index 000000000..c902be7a7
--- /dev/null
+++ b/book/examples/chapter4/ComputersEng.gf
@@ -0,0 +1,10 @@
+--# -path=.:present
+
+concrete ComputersEng of Computers = CommentsEng **
+ open SyntaxEng, ParadigmsEng in {
+ lin
+ Computer = mkCN (mkN "computer") ;
+ HardDisk = mkCN (mkA "hard") (mkN "disk") ;
+ Efficient = mkAP (mkA "efficient") ;
+ Slow = mkAP (mkA "slow") ;
+}
diff --git a/book/examples/chapter4/ComputersIta.gf b/book/examples/chapter4/ComputersIta.gf
new file mode 100644
index 000000000..274bf6089
--- /dev/null
+++ b/book/examples/chapter4/ComputersIta.gf
@@ -0,0 +1,9 @@
+concrete ComputersIta of Computers =
+ CommentsIta ** open ResIta in {
+ lin
+ Computer = noun "computer" "computer" Masc ;
+ HardDisk = noun "disco rigido" "dischi rigidi" Masc ;
+ Efficient = adjective "efficiente" "efficiente"
+ "efficienti" "efficienti" ;
+ Slow = regAdj "lento" ;
+}
diff --git a/book/examples/chapter4/Exx.gf b/book/examples/chapter4/Exx.gf
new file mode 100644
index 000000000..e7df70595
--- /dev/null
+++ b/book/examples/chapter4/Exx.gf
@@ -0,0 +1,16 @@
+resource Exx = {
+
+ param DetForm = DSg Gender Case | DPl Case ;
+ param Gender = Masc | Fem | Neutr ;
+ param Case = Nom | Acc | Dat | Gen ;
+
+ oper artDef : DetForm => Str = table {
+ DSg Masc Acc | DPl Dat => "den" ;
+ DSg (Masc | Neutr) Dat => "dem" ;
+ DSg (Masc | Neutr) Gen => "des" ;
+ DSg Neutr _ => "das" ;
+ DSg Fem (Nom | Acc) | DPl (Nom | Acc) => "die" ;
+ _ => "der"
+ } ;
+
+}
diff --git a/book/examples/chapter4/Foods.gf b/book/examples/chapter4/Foods.gf
new file mode 100644
index 000000000..d09135421
--- /dev/null
+++ b/book/examples/chapter4/Foods.gf
@@ -0,0 +1,6 @@
+abstract Foods = Comments ** {
+ fun
+ Wine, Cheese, Fish, Pizza : Kind ;
+ Fresh, Warm, Italian,
+ Expensive, Delicious, Boring : Quality ;
+}
diff --git a/book/examples/chapter4/FoodsEng.gf b/book/examples/chapter4/FoodsEng.gf
new file mode 100644
index 000000000..39711d908
--- /dev/null
+++ b/book/examples/chapter4/FoodsEng.gf
@@ -0,0 +1,16 @@
+--# -path=.:present
+
+concrete FoodsEng of Foods = CommentsEng **
+ open SyntaxEng, ParadigmsEng in {
+ lin
+ Wine = mkCN (mkN "wine") ;
+ Pizza = mkCN (mkN "pizza") ;
+ Cheese = mkCN (mkN "cheese") ;
+ Fish = mkCN (mkN "fish" "fish") ;
+ Fresh = mkAP (mkA "fresh") ;
+ Warm = mkAP (mkA "warm") ;
+ Italian = mkAP (mkA "Italian") ;
+ Expensive = mkAP (mkA "expensive") ;
+ Delicious = mkAP (mkA "delicious") ;
+ Boring = mkAP (mkA "boring") ;
+}
diff --git a/book/examples/chapter4/FoodsIta.gf b/book/examples/chapter4/FoodsIta.gf
new file mode 100644
index 000000000..502a29cc2
--- /dev/null
+++ b/book/examples/chapter4/FoodsIta.gf
@@ -0,0 +1,16 @@
+--# -path=.:present
+
+concrete FoodsIta of Foods = CommentsIta **
+ open SyntaxIta, ParadigmsIta in {
+ lin
+ Wine = mkCN (mkN "vino") ;
+ Pizza = mkCN (mkN "pizza") ;
+ Cheese = mkCN (mkN "formaggio") ;
+ Fish = mkCN (mkN "pesce") ;
+ Fresh = mkAP (mkA "fresco") ;
+ Warm = mkAP (mkA "caldo") ;
+ Italian = mkAP (mkA "italiano") ;
+ Expensive = mkAP (mkA "caro") ;
+ Delicious = mkAP (mkA "delizioso") ;
+ Boring = mkAP (mkA "noioso") ;
+}
diff --git a/book/examples/chapter4/Shopping.gf b/book/examples/chapter4/Shopping.gf
new file mode 100644
index 000000000..99deb46d9
--- /dev/null
+++ b/book/examples/chapter4/Shopping.gf
@@ -0,0 +1,2 @@
+abstract Shopping = Foods, Clothes ;
+
diff --git a/book/examples/chapter4/ShoppingEng.gf b/book/examples/chapter4/ShoppingEng.gf
new file mode 100644
index 000000000..9233a00af
--- /dev/null
+++ b/book/examples/chapter4/ShoppingEng.gf
@@ -0,0 +1,4 @@
+--# -path=.:present
+
+concrete ShoppingEng of Shopping = FoodsEng, ClothesEng ;
+
diff --git a/book/examples/chapter4/ShoppingIta.gf b/book/examples/chapter4/ShoppingIta.gf
new file mode 100644
index 000000000..5abae2674
--- /dev/null
+++ b/book/examples/chapter4/ShoppingIta.gf
@@ -0,0 +1,4 @@
+--# -path=.:present
+
+concrete ShoppingIta of Shopping = FoodsIta, ClothesIta ;
+
diff --git a/book/examples/chapter4/SmallShopping.gf b/book/examples/chapter4/SmallShopping.gf
new file mode 100644
index 000000000..10c7c1a17
--- /dev/null
+++ b/book/examples/chapter4/SmallShopping.gf
@@ -0,0 +1,3 @@
+abstract SmallShopping =
+ Foods - [Wine],
+ Clothes [Kind,Quality,Shirt,Elegant] ;
diff --git a/book/examples/chapter5/Foods.gf b/book/examples/chapter5/Foods.gf
new file mode 100644
index 000000000..8ea02f39d
--- /dev/null
+++ b/book/examples/chapter5/Foods.gf
@@ -0,0 +1,15 @@
+-- (c) 2009 Aarne Ranta under LGPL
+
+abstract Foods = {
+ flags startcat = Comment ;
+ cat
+ Comment ; Item ; Kind ; Quality ;
+ fun
+ Pred : Item -> Quality -> Comment ;
+ This, That, These, Those : Kind -> Item ;
+ Mod : Quality -> Kind -> Kind ;
+ Wine, Cheese, Fish, Pizza : Kind ;
+ Very : Quality -> Quality ;
+ Fresh, Warm, Italian,
+ Expensive, Delicious, Boring : Quality ;
+}
diff --git a/book/examples/chapter5/FoodsCat.gf b/book/examples/chapter5/FoodsCat.gf
new file mode 100644
index 000000000..5ad38d0dc
--- /dev/null
+++ b/book/examples/chapter5/FoodsCat.gf
@@ -0,0 +1,7 @@
+--# -path=.:present
+
+-- (c) 2009 Jordi Saludes under LGPL
+
+concrete FoodsCat of Foods = FoodsI with
+ (Syntax = SyntaxCat),
+ (LexFoods = LexFoodsCat) ;
diff --git a/book/examples/chapter5/FoodsEng.gf b/book/examples/chapter5/FoodsEng.gf
new file mode 100644
index 000000000..5c2158ce2
--- /dev/null
+++ b/book/examples/chapter5/FoodsEng.gf
@@ -0,0 +1,27 @@
+--# -path=.:../foods:minimal:present
+
+concrete FoodsEng of Foods = open SyntaxEng,ParadigmsEng in {
+ lincat
+ Phrase = Cl ;
+ Item = NP ;
+ Kind = CN ;
+ Quality = AP ;
+ lin
+ Is item quality = mkCl item quality ;
+ This kind = mkNP this_Quant kind ;
+ That kind = mkNP that_Quant kind ;
+ These kind = mkNP this_Quant plNum kind ;
+ Those kind = mkNP that_Quant plNum kind ;
+ QKind quality kind = mkCN quality kind ;
+ Wine = mkCN (mkN "wine") ;
+ Pizza = mkCN (mkN "pizza") ;
+ Cheese = mkCN (mkN "cheese") ;
+ Fish = mkCN (mkN "fish" "fish") ;
+ Very quality = mkAP very_AdA quality ;
+ Fresh = mkAP (mkA "fresh") ;
+ Warm = mkAP (mkA "warm") ;
+ Italian = mkAP (mkA "Italian") ;
+ Expensive = mkAP (mkA "expensive") ;
+ Delicious = mkAP (mkA "delicious") ;
+ Boring = mkAP (mkA "boring") ;
+}
diff --git a/book/examples/chapter5/FoodsFin.gf b/book/examples/chapter5/FoodsFin.gf
new file mode 100644
index 000000000..34da5764b
--- /dev/null
+++ b/book/examples/chapter5/FoodsFin.gf
@@ -0,0 +1,7 @@
+--# -path=.:present
+
+-- (c) 2009 Aarne Ranta under LGPL
+
+concrete FoodsFin of Foods = FoodsI with
+ (Syntax = SyntaxFin),
+ (LexFoods = LexFoodsFin) ;
diff --git a/book/examples/chapter5/FoodsGer.gf b/book/examples/chapter5/FoodsGer.gf
new file mode 100644
index 000000000..934cefb9c
--- /dev/null
+++ b/book/examples/chapter5/FoodsGer.gf
@@ -0,0 +1,7 @@
+--# -path=.:present
+
+-- (c) 2009 Aarne Ranta under LGPL
+
+concrete FoodsGer of Foods = FoodsI with
+ (Syntax = SyntaxGer),
+ (LexFoods = LexFoodsGer) ;
diff --git a/book/examples/chapter5/FoodsI.gf b/book/examples/chapter5/FoodsI.gf
new file mode 100644
index 000000000..f4113b724
--- /dev/null
+++ b/book/examples/chapter5/FoodsI.gf
@@ -0,0 +1,29 @@
+-- (c) 2009 Aarne Ranta under LGPL
+
+incomplete concrete FoodsI of Foods =
+ open Syntax, LexFoods in {
+ lincat
+ Comment = Utt ;
+ Item = NP ;
+ Kind = CN ;
+ Quality = AP ;
+ lin
+ Pred item quality = mkUtt (mkCl item quality) ;
+ This kind = mkNP this_Det kind ;
+ That kind = mkNP that_Det kind ;
+ These kind = mkNP these_Det kind ;
+ Those kind = mkNP those_Det kind ;
+ Mod quality kind = mkCN quality kind ;
+ Very quality = mkAP very_AdA quality ;
+
+ 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/book/examples/chapter5/FoodsIta.gf b/book/examples/chapter5/FoodsIta.gf
new file mode 100644
index 000000000..51baf9d70
--- /dev/null
+++ b/book/examples/chapter5/FoodsIta.gf
@@ -0,0 +1,8 @@
+--# -path=.:present
+
+-- (c) 2009 Aarne Ranta under LGPL
+
+concrete FoodsIta of Foods = FoodsI with
+ (Syntax = SyntaxIta),
+ (LexFoods = LexFoodsIta) ;
+
diff --git a/book/examples/chapter5/FoodsSwe.gf b/book/examples/chapter5/FoodsSwe.gf
new file mode 100644
index 000000000..cbb35fb98
--- /dev/null
+++ b/book/examples/chapter5/FoodsSwe.gf
@@ -0,0 +1,7 @@
+--# -path=.:present
+
+-- (c) 2009 Aarne Ranta under LGPL
+
+concrete FoodsSwe of Foods = FoodsI with
+ (Syntax = SyntaxSwe),
+ (LexFoods = LexFoodsSwe) ** {flags language = sv_SE;} ;
diff --git a/book/examples/chapter5/LexFoods.gf b/book/examples/chapter5/LexFoods.gf
new file mode 100644
index 000000000..12ace208c
--- /dev/null
+++ b/book/examples/chapter5/LexFoods.gf
@@ -0,0 +1,15 @@
+-- (c) 2009 Aarne Ranta under LGPL
+
+interface LexFoods = open Syntax in {
+ oper
+ wine_N : N ;
+ pizza_N : N ;
+ cheese_N : N ;
+ fish_N : N ;
+ fresh_A : A ;
+ warm_A : A ;
+ italian_A : A ;
+ expensive_A : A ;
+ delicious_A : A ;
+ boring_A : A ;
+}
diff --git a/book/examples/chapter5/LexFoodsCat.gf b/book/examples/chapter5/LexFoodsCat.gf
new file mode 100644
index 000000000..624fc98c8
--- /dev/null
+++ b/book/examples/chapter5/LexFoodsCat.gf
@@ -0,0 +1,18 @@
+-- (c) 2009 Jordi Saludes under LGPL
+
+instance LexFoodsCat of LexFoods =
+ open SyntaxCat, ParadigmsCat, (M = MorphoCat) in {
+ flags
+ coding = utf8 ;
+ oper
+ wine_N = mkN "vi" "vins" M.Masc ;
+ pizza_N = mkN "pizza" ;
+ cheese_N = mkN "formatge" ;
+ fish_N = mkN "peix" "peixos" M.Masc;
+ fresh_A = mkA "fresc" "fresca" "frescos" "fresques" "frescament";
+ warm_A = mkA "calent" ;
+ italian_A = mkA "italià" "italiana" "italians" "italianes" "italianament" ;
+ expensive_A = mkA "car" ;
+ delicious_A = mkA "deliciós" "deliciosa" "deliciosos" "delicioses" "deliciosament";
+ boring_A = mkA "aburrit" "aburrida" "aburrits" "aburrides" "aburridament" ;
+}
diff --git a/book/examples/chapter5/LexFoodsEng.gf b/book/examples/chapter5/LexFoodsEng.gf
new file mode 100644
index 000000000..01024b356
--- /dev/null
+++ b/book/examples/chapter5/LexFoodsEng.gf
@@ -0,0 +1,20 @@
+instance LexFoodsEng of LexFoods = open SyntaxEng, ParadigmsEng, IrregEng in {
+ oper
+ wine_N = mkN "wine" ;
+ pizza_N = mkN "pizza" ;
+ cheese_N = mkN "cheese" ;
+ fish_N = mkN "fish" "fish" ;
+ fresh_A = mkA "fresh" ;
+ warm_A = mkA "warm" ;
+ italian_A = mkA "Italian" ;
+ expensive_A = mkA "expensive" ;
+ delicious_A = mkA "delicious" ;
+ boring_A = mkA "boring" ;
+
+ eat_V2 = mkV2 eat_V ;
+ drink_V2 = mkV2 drink_V ;
+ pay_V2 = mkV2 pay_V ;
+ lady_N = mkN "lady" ;
+ gentleman_N = mkN "gentleman" "gentlemen" ;
+
+}
diff --git a/book/examples/chapter5/LexFoodsFin.gf b/book/examples/chapter5/LexFoodsFin.gf
new file mode 100644
index 000000000..4cf26511a
--- /dev/null
+++ b/book/examples/chapter5/LexFoodsFin.gf
@@ -0,0 +1,20 @@
+-- (c) 2009 Aarne Ranta under LGPL
+
+instance LexFoodsFin of LexFoods =
+ open SyntaxFin, ParadigmsFin in {
+ oper
+ wine_N = mkN "viini" ;
+ pizza_N = mkN "pizza" ;
+ cheese_N = mkN "juusto" ;
+ fish_N = mkN "kala" ;
+ fresh_A = mkA "tuore" ;
+ warm_A = mkA
+ (mkN "lmmin" "lmpimn" "lmmint" "lmpimn" "lmpimn"
+ "lmpimin" "lmpimi" "lmpimien" "lmpimiss" "lmpimiin"
+ )
+ "lmpimmpi" "lmpimin" ;
+ italian_A = mkA "italialainen" ;
+ expensive_A = mkA "kallis" ;
+ delicious_A = mkA "herkullinen" ;
+ boring_A = mkA "tyls" ;
+}
diff --git a/book/examples/chapter5/LexFoodsGer.gf b/book/examples/chapter5/LexFoodsGer.gf
new file mode 100644
index 000000000..a420e22d3
--- /dev/null
+++ b/book/examples/chapter5/LexFoodsGer.gf
@@ -0,0 +1,16 @@
+-- (c) 2009 Aarne Ranta under LGPL
+
+instance LexFoodsGer of LexFoods =
+ open SyntaxGer, ParadigmsGer in {
+ oper
+ wine_N = mkN "Wein" ;
+ pizza_N = mkN "Pizza" "Pizzen" feminine ;
+ cheese_N = mkN "Kse" "Kse" masculine ;
+ fish_N = mkN "Fisch" ;
+ fresh_A = mkA "frisch" ;
+ warm_A = mkA "warm" "wrmer" "wrmste" ;
+ italian_A = mkA "italienisch" ;
+ expensive_A = mkA "teuer" ;
+ delicious_A = mkA "kstlich" ;
+ boring_A = mkA "langweilig" ;
+}
diff --git a/book/examples/chapter5/LexFoodsIta.gf b/book/examples/chapter5/LexFoodsIta.gf
new file mode 100644
index 000000000..11de5fcda
--- /dev/null
+++ b/book/examples/chapter5/LexFoodsIta.gf
@@ -0,0 +1,16 @@
+-- (c) 2009 Aarne Ranta under LGPL
+
+instance LexFoodsIta of LexFoods =
+ open SyntaxIta, ParadigmsIta in {
+ oper
+ wine_N = mkN "vino" ;
+ pizza_N = mkN "pizza" ;
+ cheese_N = mkN "formaggio" ;
+ fish_N = mkN "pesce" ;
+ fresh_A = mkA "fresco" ;
+ warm_A = mkA "caldo" ;
+ italian_A = mkA "italiano" ;
+ expensive_A = mkA "caro" ;
+ delicious_A = mkA "delizioso" ;
+ boring_A = mkA "noioso" ;
+}
diff --git a/book/examples/chapter5/LexFoodsSwe.gf b/book/examples/chapter5/LexFoodsSwe.gf
new file mode 100644
index 000000000..72e7e3e86
--- /dev/null
+++ b/book/examples/chapter5/LexFoodsSwe.gf
@@ -0,0 +1,16 @@
+-- (c) 2009 Aarne Ranta under LGPL
+
+instance LexFoodsSwe of LexFoods =
+ open SyntaxSwe, ParadigmsSwe in {
+ oper
+ wine_N = mkN "vin" "vinet" "viner" "vinerna" ;
+ pizza_N = mkN "pizza" ;
+ cheese_N = mkN "ost" ;
+ fish_N = mkN "fisk" ;
+ fresh_A = mkA "frsk" ;
+ warm_A = mkA "varm" ;
+ italian_A = mkA "italiensk" ;
+ expensive_A = mkA "dyr" ;
+ delicious_A = mkA "lcker" ;
+ boring_A = mkA "trkig" ;
+}
diff --git a/book/examples/chapter6/Aggregation.gf b/book/examples/chapter6/Aggregation.gf
new file mode 100644
index 000000000..28cbd39ef
--- /dev/null
+++ b/book/examples/chapter6/Aggregation.gf
@@ -0,0 +1,33 @@
+abstract Aggregation = {
+ cat S ; NP ; VP ;
+ data
+ PredVP : NP -> VP -> S ;
+ ConjS : S -> S -> S ;
+ ConjVP : VP -> VP -> VP ;
+ ConjNP : NP -> NP -> NP ;
+ Run, Walk : VP ;
+ John, Mary : NP ;
+
+ fun aggr : S -> S ; -- main aggregation function
+ def aggr (ConjS (PredVP x X) (PredVP y Y)) =
+ ifS (eqNP x y)
+ (PredVP x (ConjVP X Y))
+ (ifS (eqVP X Y)
+ (PredVP (ConjNP x y) X)
+ (ConjS (PredVP x X) (PredVP y Y))) ;
+ fun ifS : Bool -> S -> S -> S ; -- if b then x else y
+ def
+ ifS True x _ = x ;
+ ifS False _ y = y ;
+ fun eqNP : NP -> NP -> Bool ; -- x == y
+ def
+ eqNP John John = True ;
+ eqNP Mary Mary = True ;
+ eqNP _ _ = False ;
+ fun eqVP : VP -> VP -> Bool ; -- X == Y
+ def
+ eqVP Run Run = True ;
+ eqVP Walk Walk = True ;
+ eqVP _ _ = False ;
+ cat Bool ; data True, False : Bool ;
+}
diff --git a/book/examples/chapter6/AggregationEng.gf b/book/examples/chapter6/AggregationEng.gf
new file mode 100644
index 000000000..9ed403c79
--- /dev/null
+++ b/book/examples/chapter6/AggregationEng.gf
@@ -0,0 +1,17 @@
+concrete AggregationEng of Aggregation = {
+
+lincat S, NP, VP = Str ;
+
+lin
+ PredVP x y = x ++ y ;
+ ConjS a b = a ++ "or" ++ b ;
+ ConjVP a b = a ++ "or" ++ b ;
+ ConjNP a b = a ++ "or" ++ b ;
+
+ Run = "runs" ;
+ Walk = "walks" ;
+ John = "John" ;
+ Mary = "Mary" ;
+
+}
+
diff --git a/book/examples/chapter6/Bin.gf b/book/examples/chapter6/Bin.gf
new file mode 100644
index 000000000..c181656f8
--- /dev/null
+++ b/book/examples/chapter6/Bin.gf
@@ -0,0 +1,50 @@
+abstract Bin = {
+
+cat Nat ; Bin ; Pos ;
+
+data
+ Zero : Nat ;
+ Succ : Nat -> Nat ;
+
+ BZero : Bin ; -- 0
+ BPos : Pos -> Bin ; -- p
+ BOne : Pos ; -- 1
+ AZero : Pos -> Pos ; -- p0
+ AOne : Pos -> Pos ; -- p1
+
+fun
+ bin2nat : Bin -> Nat ;
+def
+ bin2nat BZero = Zero ;
+ bin2nat (BPos p) = pos2nat p ;
+fun
+ pos2nat : Pos -> Nat ;
+def
+ pos2nat BOne = one ;
+ pos2nat (AZero p) = twice (pos2nat p) ;
+ pos2nat (AOne p) = Succ (twice (pos2nat p)) ;
+fun one : Nat ;
+def one = Succ Zero ;
+fun twice : Nat -> Nat ;
+def
+ twice Zero = Zero ;
+ twice (Succ n) = Succ (Succ (twice n)) ;
+
+fun
+ nat2bin : Nat -> Bin ;
+def
+ nat2bin Zero = BZero ;
+ nat2bin (Succ n) = bSucc (nat2bin n) ;
+fun
+ bSucc : Bin -> Bin ;
+def
+ bSucc BZero = BPos BOne ;
+ bSucc (BPos p) = BPos (pSucc p) ;
+fun
+ pSucc : Pos -> Pos ;
+def
+ pSucc BOne = AZero BOne ;
+ pSucc (AZero p) = AOne p ;
+ pSucc (AOne p) = AZero (pSucc p) ;
+
+} \ No newline at end of file
diff --git a/book/examples/chapter6/Classes.gf b/book/examples/chapter6/Classes.gf
new file mode 100644
index 000000000..ac7430d25
--- /dev/null
+++ b/book/examples/chapter6/Classes.gf
@@ -0,0 +1,28 @@
+abstract Classes = {
+
+flags
+ startcat = Command ;
+
+cat
+ Command ;
+ Kind ;
+ Class ;
+ Instance Class Kind ;
+ Action Class ;
+ Device Kind ;
+
+fun
+ Act : (c : Class) -> (k : Kind) -> Instance c k -> Action c -> Device k -> Command ;
+ The : (k : Kind) -> Device k ;
+
+ Light, Fan : Kind ;
+ Switchable, Dimmable : Class ;
+
+ SwitchOn, SwitchOff : Action Switchable ;
+ Dim : Action Dimmable ;
+
+ switchable_Light : Instance Switchable Light ;
+ switchable_Fan : Instance Switchable Fan ;
+ dimmable_Light : Instance Dimmable Light ;
+
+}
diff --git a/book/examples/chapter6/ClassesEng.gf b/book/examples/chapter6/ClassesEng.gf
new file mode 100644
index 000000000..a282bd87a
--- /dev/null
+++ b/book/examples/chapter6/ClassesEng.gf
@@ -0,0 +1,29 @@
+--# -path=.:present
+
+concrete ClassesEng of Classes = open SyntaxEng, ParadigmsEng in {
+
+lincat
+ Command = Utt ;
+ Kind = CN ;
+ Class = {} ;
+ Instance = {} ;
+ Action = V2 ;
+ Device = NP ;
+
+lin
+ Act _ _ _ a d = mkUtt (mkImp a d) ;
+ The k = mkNP the_Det k ;
+
+ Light = mkCN (mkN "light") ;
+ Fan = mkCN (mkN "fan") ;
+ Switchable, Dimmable = <> ;
+
+ SwitchOn = mkV2 (mkV "on" (mkV "switch")) ;
+ SwitchOff = mkV2 (mkV "off" (mkV "switch")) ;
+ Dim = mkV2 (mkV "dim") ;
+
+ switchable_Light = <> ;
+ switchable_Fan = <> ;
+ dimmable_Light = <> ;
+
+}
diff --git a/book/examples/chapter6/DShopping.gf b/book/examples/chapter6/DShopping.gf
new file mode 100644
index 000000000..a5a06e070
--- /dev/null
+++ b/book/examples/chapter6/DShopping.gf
@@ -0,0 +1,24 @@
+abstract DShopping = {
+ flags startcat = Comment ;
+ cat
+ Comment ;
+ Dom ;
+ Item Dom ;
+ Kind Dom ;
+ Quality Dom ;
+ fun
+ DFood, DCloth : Dom ;
+
+ Pred : (d : Dom) -> Item d -> Quality d -> Comment ;
+ This, That : (d : Dom) -> Kind d -> Item d ;
+ Mod : (d : Dom) -> Quality d -> Kind d -> Kind d ;
+ Wine, Cheese, Fish : Kind DFood ;
+ Very : (d : Dom) -> Quality d -> Quality d ;
+ Fresh, Warm, Delicious, Boring : Quality DFood ;
+
+ Shirt, Jacket : Kind DCloth ;
+ Comfortable : Quality DCloth ;
+
+ Italian, Expensive, Elegant : (d : Dom) -> Quality d ;
+
+}
diff --git a/book/examples/chapter6/DShoppingEng.gf b/book/examples/chapter6/DShoppingEng.gf
new file mode 100644
index 000000000..3dc3a2cc2
--- /dev/null
+++ b/book/examples/chapter6/DShoppingEng.gf
@@ -0,0 +1,33 @@
+--# -path=.:present
+
+concrete DShoppingEng of DShopping = open SyntaxEng, ParadigmsEng in {
+
+ lincat
+ Comment = Cl ;
+ Item = NP ;
+ Kind = CN ;
+ Quality = AP ;
+ lin
+ Pred _ item quality = mkCl item quality ;
+ This _ kind = mkNP this_QuantSg kind ;
+ That _ kind = mkNP that_QuantSg kind ;
+ Mod _ quality kind = mkCN quality kind ;
+ Very _ quality = mkAP very_AdA quality ;
+
+ Shirt = mkCN (mkN "shirt") ;
+ Jacket = mkCN (mkN "jacket") ;
+ Wine = mkCN (mkN "wine") ;
+ Cheese = mkCN (mkN "cheese") ;
+ Fish = mkCN (mkN "fish" "fish") ;
+ Fresh = mkAP (mkA "fresh") ;
+ Warm = mkAP (mkA "warm") ;
+ Italian _ = mkAP (mkA "Italian") ;
+ Expensive _ = mkAP (mkA "expensive") ;
+ Elegant _ = mkAP (mkA "elegant") ;
+ Delicious = mkAP (mkA "delicious") ;
+ Boring = mkAP (mkA "boring") ;
+ Comfortable = mkAP (mkA "comfortable") ;
+
+ DFood, DCloth = {s = []} ;
+
+}
diff --git a/book/examples/chapter6/Nat.gf b/book/examples/chapter6/Nat.gf
new file mode 100644
index 000000000..ba0dfe4a1
--- /dev/null
+++ b/book/examples/chapter6/Nat.gf
@@ -0,0 +1,22 @@
+abstract Nat = {
+ cat
+ Prop ; -- proposition
+ Nat ; -- natural number
+ data
+ Zero : Nat ; -- 0
+ Succ : Nat -> Nat ; -- the successor of x
+ fun
+ Even : Nat -> Prop ; -- x is even
+ And : Prop -> Prop -> Prop ; -- A and B
+
+ fun one : Nat ;
+ def one = Succ Zero ;
+
+ fun twice : Nat -> Nat ;
+ def twice x = plus x x ;
+
+ fun plus : Nat -> Nat -> Nat ;
+ def
+ plus x Zero = x ;
+ plus x (Succ y) = Succ (plus x y) ;
+}
diff --git a/book/examples/chapter6/Verbs.gf b/book/examples/chapter6/Verbs.gf
new file mode 100644
index 000000000..371450aeb
--- /dev/null
+++ b/book/examples/chapter6/Verbs.gf
@@ -0,0 +1,22 @@
+abstract Verbs = {
+
+cat
+ S ; NP ; Subcat ; V Subcat ; Args Subcat ;
+
+fun
+ cIntr : Subcat ;
+ cTr : Subcat ;
+ cS : Subcat ;
+
+ aIntr : NP -> Args cIntr ;
+ aTr : NP -> NP -> Args cTr ;
+ aS : NP -> S -> Args cS ;
+
+ pred : (s : Subcat) -> V s -> Args s -> S ;
+
+ john, mary : NP ;
+ walk : V cIntr ;
+ love : V cTr ;
+ know : V cS ;
+
+} \ No newline at end of file
diff --git a/book/examples/chapter6/VerbsEng.gf b/book/examples/chapter6/VerbsEng.gf
new file mode 100644
index 000000000..b235178d9
--- /dev/null
+++ b/book/examples/chapter6/VerbsEng.gf
@@ -0,0 +1,22 @@
+concrete VerbsEng of Verbs = {
+
+lincat
+ S, NP, Subcat, V = Str ; Args = Str * Str ;
+
+lin
+ cIntr = [] ;
+ cTr = [] ;
+ cS = [] ;
+
+ aIntr su = <su,[]> ;
+ aTr su ob = <su,ob> ;
+ aS su s = <su,"that" ++ s> ;
+
+ pred _ v xs = xs.p1 ++ v ++ xs.p2 ;
+
+ john = "John" ; mary = "Mary" ;
+ walk = "walks" ;
+ love = "loves" ;
+ know = "knows" ;
+
+}
diff --git a/book/examples/chapter7/Query.gf b/book/examples/chapter7/Query.gf
new file mode 100644
index 000000000..b6f83e357
--- /dev/null
+++ b/book/examples/chapter7/Query.gf
@@ -0,0 +1,12 @@
+abstract Query = {
+ flags startcat=Question ;
+ cat
+ Answer ; Question ; Object ;
+ fun
+ Even : Object -> Question ;
+ Odd : Object -> Question ;
+ Prime : Object -> Question ;
+ Number : Int -> Object ;
+ Yes : Answer ;
+ No : Answer ;
+}
diff --git a/book/examples/chapter7/QueryEng.gf b/book/examples/chapter7/QueryEng.gf
new file mode 100644
index 000000000..cc14d5eb7
--- /dev/null
+++ b/book/examples/chapter7/QueryEng.gf
@@ -0,0 +1,13 @@
+concrete QueryEng of Query = {
+ lincat
+ Answer, Question, Object = Str ;
+ lin
+ Even = pred "even" ;
+ Odd = pred "odd" ;
+ Prime = pred "prime" ;
+ Number i = i.s ;
+ Yes = "yes" ;
+ No = "no" ;
+ oper
+ pred : Str -> Str -> Str = \f,x -> "is" ++ x ++ f ;
+}
diff --git a/book/examples/chapter7/QueryFin.gf b/book/examples/chapter7/QueryFin.gf
new file mode 100644
index 000000000..b3461e34a
--- /dev/null
+++ b/book/examples/chapter7/QueryFin.gf
@@ -0,0 +1,13 @@
+concrete QueryFin of Query = {
+ lincat
+ Answer, Question, Object = Str ;
+ lin
+ Even = pred "parillinen" ;
+ Odd = pred "pariton" ;
+ Prime = pred "alkuluku" ;
+ Number i = i.s ;
+ Yes = "kyll" ;
+ No = "ei" ;
+ oper
+ pred : Str -> Str -> Str = \f,x -> "onko" ++ x ++ f ;
+}
diff --git a/book/examples/chapter8/Calculator.gf b/book/examples/chapter8/Calculator.gf
new file mode 100644
index 000000000..188c150e0
--- /dev/null
+++ b/book/examples/chapter8/Calculator.gf
@@ -0,0 +1,7 @@
+abstract Calculator = {
+flags startcat = Exp ;
+cat Exp ;
+fun
+ EPlus, EMinus, ETimes, EDiv : Exp -> Exp -> Exp ;
+ EInt : Int -> Exp ;
+}
diff --git a/book/examples/chapter8/CalculatorC.gf b/book/examples/chapter8/CalculatorC.gf
new file mode 100644
index 000000000..99db80530
--- /dev/null
+++ b/book/examples/chapter8/CalculatorC.gf
@@ -0,0 +1,10 @@
+concrete CalculatorC of Calculator = open Formal, Prelude in {
+lincat
+ Exp = TermPrec ;
+lin
+ EPlus = infixl 0 "+" ;
+ EMinus = infixl 0 "-" ;
+ ETimes = infixl 1 "*" ;
+ EDiv = infixl 1 "/" ;
+ EInt i = constant i.s ;
+}
diff --git a/book/examples/chapter8/CalculatorJ.gf b/book/examples/chapter8/CalculatorJ.gf
new file mode 100644
index 000000000..c5f40c8d3
--- /dev/null
+++ b/book/examples/chapter8/CalculatorJ.gf
@@ -0,0 +1,13 @@
+concrete CalculatorJ of Calculator = open Prelude in {
+lincat
+ Exp = SS ;
+lin
+ EPlus = postfix "iadd" ;
+ EMinus = postfix "isub" ;
+ ETimes = postfix "imul" ;
+ EDiv = postfix "idiv" ;
+ EInt i = ss ("ldc" ++ i.s) ;
+oper
+ postfix : Str -> SS -> SS -> SS = \op,x,y ->
+ ss (x.s ++ ";" ++ y.s ++ ";" ++ op) ;
+}
diff --git a/book/examples/chapter8/CalculatorP.gf b/book/examples/chapter8/CalculatorP.gf
new file mode 100644
index 000000000..4e6315827
--- /dev/null
+++ b/book/examples/chapter8/CalculatorP.gf
@@ -0,0 +1,14 @@
+concrete CalculatorP of Calculator = open Prelude in {
+
+lincat
+ Exp = SS ;
+lin
+ EPlus = infix "+" ;
+ EMinus = infix "-" ;
+ ETimes = infix "*" ;
+ EDiv = infix "/" ;
+ EInt i = i ;
+oper
+ infix : Str -> SS -> SS -> SS = \f,x,y ->
+ ss ("(" ++ x.s ++ f ++ y.s ++ ")") ;
+}
diff --git a/book/examples/chapter8/CalculatorS.gf b/book/examples/chapter8/CalculatorS.gf
new file mode 100644
index 000000000..d8c1df456
--- /dev/null
+++ b/book/examples/chapter8/CalculatorS.gf
@@ -0,0 +1,11 @@
+concrete CalculatorS of Calculator = open Prelude in {
+ lin
+ EPlus = infix "plus" ;
+ EMinus = infix "minus" ;
+ ETimes = infix "times" ;
+ EDiv = infix ["divided by"] ;
+ EInt i = i ;
+ oper
+ infix : Str -> SS -> SS -> SS = \op,x,y ->
+ ss (x.s ++ op ++ y.s ++ "PAUSE") ;
+}
diff --git a/book/examples/chapter8/Geometry.gf b/book/examples/chapter8/Geometry.gf
new file mode 100644
index 000000000..0b27d8714
--- /dev/null
+++ b/book/examples/chapter8/Geometry.gf
@@ -0,0 +1,7 @@
+abstract Geometry = Logic ** {
+fun
+ Line, Point, Circle : Dom ;
+ Intersect, Parallel : Ind -> Ind -> Atom ;
+ Vertical : Ind -> Atom ;
+ Centre : Ind -> Ind ;
+}
diff --git a/book/examples/chapter8/GeometryEng.gf b/book/examples/chapter8/GeometryEng.gf
new file mode 100644
index 000000000..36d840303
--- /dev/null
+++ b/book/examples/chapter8/GeometryEng.gf
@@ -0,0 +1,13 @@
+--# -path=alltenses
+
+concrete GeometryEng of Geometry = LogicEng **
+ open SyntaxEng, ParadigmsEng in {
+lin
+ Line = mkCN (mkN "line") ;
+ Point = mkCN (mkN "point") ;
+ Circle = mkCN (mkN "circle") ;
+ Intersect = pred (mkV2 "intersect") ;
+ Parallel = pred (mkA2 (mkA "parallel") (mkPrep "to")) ;
+ Vertical = pred (mkA "vertical") ;
+ Centre = app (mkN2 (mkN "centre") (mkPrep "of")) ;
+}
diff --git a/book/examples/chapter8/GeometryEngb.gf b/book/examples/chapter8/GeometryEngb.gf
new file mode 100644
index 000000000..265f3f71a
--- /dev/null
+++ b/book/examples/chapter8/GeometryEngb.gf
@@ -0,0 +1,11 @@
+concrete GeometryEng of Geometry = LogicEng **
+ open SyntaxEng, ParadigmsEng in {
+lin
+ Line = mkN "line" ;
+ Point = mkN "point" ;
+ Circle = mkN "circle" ;
+ Intersect = pred (mkV2 "intersect") ;
+ Parallel = pred (mkA2 (mkA "parallel") (mkPrep "to")) ;
+ Vertical = pred (mkA "vertical") ;
+ Centre = app (mkN2 (mkN "centre") (mkPrep "of")) ;
+}
diff --git a/book/examples/chapter8/Geometryb.gf b/book/examples/chapter8/Geometryb.gf
new file mode 100644
index 000000000..dc39c9ce4
--- /dev/null
+++ b/book/examples/chapter8/Geometryb.gf
@@ -0,0 +1,7 @@
+abstract Geometry = Logic ** {
+fun
+ Line, Point, Circle : Dom ;
+ Intersect, Parallel : Ind -> Ind -> Prop ;
+ Vertical : Ind -> Prop ;
+ Centre : Ind -> Ind ;
+}
diff --git a/book/examples/chapter8/Logic.gf b/book/examples/chapter8/Logic.gf
new file mode 100644
index 000000000..f2b292428
--- /dev/null
+++ b/book/examples/chapter8/Logic.gf
@@ -0,0 +1,21 @@
+abstract Logic = {
+flags startcat = Stm ;
+cat
+ Stm ; -- top-level statement
+ Prop ; -- proposition
+ Atom ; -- atomic formula
+ Ind ; -- individual term
+ Dom ; -- domain expression
+ Var ; -- variable
+ [Prop] {2} ; -- list of propositions, 2 or more
+ [Var] {1} ; -- list of variables, 1 or more
+fun
+ SProp : Prop -> Stm ;
+ And, Or : [Prop] -> Prop ;
+ If : Prop -> Prop -> Prop ;
+ Not : Prop -> Prop ;
+ PAtom : Atom -> Prop ;
+ All, Exist : [Var] -> Dom -> Prop -> Prop ;
+ IVar : Var -> Ind ;
+ VString : String -> Var ;
+}
diff --git a/book/examples/chapter8/LogicBEng.gf b/book/examples/chapter8/LogicBEng.gf
new file mode 100644
index 000000000..b950c6b39
--- /dev/null
+++ b/book/examples/chapter8/LogicBEng.gf
@@ -0,0 +1,38 @@
+concrete LogicEng of Logic = open
+ SyntaxEng, (P = ParadigmsEng), SymbolicEng, Prelude in {
+lincat
+ Stm = Text ;
+ Prop = S ;
+ Atom = Cl ;
+ Ind = NP ;
+ Dom = CN ;
+ Var = NP ;
+ [Prop] = [S] ;
+ [Var] = NP ;
+lin
+ SProp = mkText ;
+ And = mkS and_Conj ; -- A, B ... and C
+ Or = mkS or_Conj ; -- A, B ... or C
+ If A B = -- if A B
+ mkS (mkAdv if_Subj A) B ;
+ Not A = -- it is not the case that A
+ mkS negativePol (mkCl
+ (mkVP (mkNP the_Quant
+ (mkCN case_CN A)))) ;
+ All xs A B = -- for all A's xs, B
+ mkS (mkAdv for_Prep
+ (mkNP all_Predet (mkNP a_Quant
+ plNum (mkCN A xs)))) B ;
+ Exist xs A B = -- for some A's xs, B
+ mkS (mkAdv for_Prep
+ (mkNP somePl_Det (mkCN A xs))) B ;
+ PAtom = mkS ;
+ IVar x = x ;
+ VString s = symb s ;
+ BaseProp A B = mkListS A B ;
+ ConsProp A As = mkListS A As ;
+ BaseVar x = x ;
+ ConsVar x xs = mkNP and_Conj (mkListNP x xs) ;
+oper
+ case_CN : CN = mkCN (P.mkN "case") ;
+}
diff --git a/book/examples/chapter8/LogicEng.gf b/book/examples/chapter8/LogicEng.gf
new file mode 100644
index 000000000..eae85d255
--- /dev/null
+++ b/book/examples/chapter8/LogicEng.gf
@@ -0,0 +1,39 @@
+concrete LogicEng of Logic = open
+ SyntaxEng, (P = ParadigmsEng), SymbolicEng, Prelude in {
+lincat
+ Stm = Text ;
+ Prop = {pos,neg : S ; isAtom : Bool} ;
+ Atom = Cl ;
+ Ind = NP ;
+ Dom = CN ;
+ Var = NP ;
+ [Prop] = ListS ;
+ [Var] = NP ;
+lin
+ SProp p = mkText p.pos ;
+ And ps = complexProp (mkS and_Conj ps) ;
+ Or ps = complexProp (mkS or_Conj ps) ;
+ If A B = complexProp (mkS if_then_Conj (mkListS A.pos B.pos)) ;
+ Not A = complexProp A.neg ;
+ All xs A B = complexProp (mkS (mkAdv for_Prep
+ (mkNP all_Predet (mkNP a_Quant plNum (mkCN A xs)))) B.pos) ;
+ Exist xs A B = complexProp (mkS (mkAdv for_Prep
+ (mkNP somePl_Det (mkCN A xs))) B.pos) ;
+ PAtom p =
+ {pos = mkS p ; neg = mkS negativePol p ; isAtom = True} ;
+ IVar x = x ;
+ VString s = symb s ;
+ BaseProp A B = mkListS A.pos B.pos ;
+ ConsProp A As = mkListS A.pos As ;
+ BaseVar x = x ;
+ ConsVar x xs = mkNP and_Conj (mkListNP x xs) ;
+oper
+ complexProp : S -> {pos,neg : S ; isAtom : Bool} = \s -> {
+ pos = s ;
+ neg = negS s ;
+ isAtom = False
+ } ;
+ negS : S -> S = \s -> mkS negativePol (mkCl (mkNP it_Pron)
+ (mkNP the_Quant (mkCN (mkCN (P.mkN "case")) s))) ;
+ if_Then_Conj : Conj = P.mkConj "if" "then" ;
+}
diff --git a/book/examples/chapter8/Logicb.gf b/book/examples/chapter8/Logicb.gf
new file mode 100644
index 000000000..5b5aa9ab9
--- /dev/null
+++ b/book/examples/chapter8/Logicb.gf
@@ -0,0 +1,11 @@
+abstract Logic = {
+cat
+ Prop ; Ind ; Dom ; Var ; [Prop] {2} ; [Var] {1} ;
+fun
+ And, Or : [Prop] -> Prop ;
+ If : Prop -> Prop -> Prop ;
+ Not : Prop -> Prop ;
+ All, Exist : [Var] -> Dom -> Prop -> Prop ;
+ IVar : Var -> Ind ;
+ VString : String -> Var ;
+}
diff --git a/book/examples/chapter9/Anaphora.gf b/book/examples/chapter9/Anaphora.gf
new file mode 100644
index 000000000..5cbb92c94
--- /dev/null
+++ b/book/examples/chapter9/Anaphora.gf
@@ -0,0 +1,17 @@
+abstract Anaphora = TestSemantics - [she_NP] ** {
+
+cat
+ Proof Prop ;
+
+fun
+ IfS : (A : S) -> (Proof (iS A) -> S) -> S ;
+
+ AnaNP : (A : CN) -> (a : Ind) -> Proof (iCN A a) -> NP ;
+
+ pe : (B : Ind -> Prop) -> Proof (Exist B) -> Ind ;
+ qe : (B : Ind -> Prop) -> (c : Proof (Exist B)) -> Proof (B (pe B c)) ;
+
+ pc : (A,B : Prop) -> Proof (And A B) -> Proof A ;
+ qc : (A,B : Prop) -> Proof (And A B) -> Proof B ;
+
+}
diff --git a/book/examples/chapter9/AnaphoraIta.gf b/book/examples/chapter9/AnaphoraIta.gf
new file mode 100644
index 000000000..288872160
--- /dev/null
+++ b/book/examples/chapter9/AnaphoraIta.gf
@@ -0,0 +1,17 @@
+concrete AnaphoraIta of Anaphora = TestSemanticsIta - [she_NP] **
+ open ResIta, Prelude, Formal in {
+
+lincat
+ Proof = {} ;
+
+lin
+ IfS A B = {s = "se" ++ A.s ++ B.s} ;
+
+ AnaNP cn _ _ = case cn.g of {
+ Masc => pronNP "lui" "lo" "gli" Masc Sg Per3 ;
+ Fem => pronNP "lei" "la" "le" Fem Sg Per3
+ } ;
+
+ pe _ _ = constant [] ; ----
+
+}
diff --git a/book/examples/chapter9/Grammar.gf b/book/examples/chapter9/Grammar.gf
new file mode 100644
index 000000000..57e3f8dcc
--- /dev/null
+++ b/book/examples/chapter9/Grammar.gf
@@ -0,0 +1,39 @@
+abstract Grammar = {
+
+ flags startcat = S ;
+
+ cat
+ S ; Cl ; NP ; VP ; AP ; CN ;
+ Det ; N ; A ; V ; V2 ; AdA ;
+ Tense ; Pol ;
+ Conj ;
+ data
+ UseCl : Tense -> Pol -> Cl -> S ;
+ PredVP : NP -> VP -> Cl ;
+ ComplV2 : V2 -> NP -> VP ;
+ DetCN : Det -> CN -> NP ;
+ ModCN : AP -> CN -> CN ;
+
+ CompAP : AP -> VP ;
+ AdAP : AdA -> AP -> AP ;
+
+ ConjS : Conj -> S -> S -> S ;
+ ConjNP : Conj -> NP -> NP -> NP ;
+
+ UseV : V -> VP ;
+ UseN : N -> CN ;
+ UseA : A -> AP ;
+
+ a_Det, the_Det, every_Det : Det ;
+ this_Det, these_Det : Det ;
+ that_Det, those_Det : Det ;
+ i_NP, she_NP, we_NP : NP ;
+ very_AdA : AdA ;
+
+ Pos, Neg : Pol ;
+ Pres, Perf : Tense ;
+
+ and_Conj, or_Conj : Conj ;
+
+
+}
diff --git a/book/examples/chapter9/GrammarIta.gf b/book/examples/chapter9/GrammarIta.gf
new file mode 100644
index 000000000..93b2b78fb
--- /dev/null
+++ b/book/examples/chapter9/GrammarIta.gf
@@ -0,0 +1,141 @@
+concrete GrammarIta of Grammar = open ResIta, Prelude in {
+ lincat
+ S = {s : Str} ;
+ Cl = {s : ResIta.Tense => Bool => Str} ;
+ NP = ResIta.NP ;
+ -- {s : Case => {clit,obj : Str ; isClit : Bool} ; a : Agr} ;
+ VP = ResIta.VP ;
+ -- {v : Verb ; clit : Str ; clitAgr : ClitAgr ; obj : Agr => Str} ;
+ AP = {s : Gender => Number => Str ; isPre : Bool} ;
+ CN = Noun ; -- {s : Number => Str ; g : Gender} ;
+ Det = {s : Gender => Case => Str ; n : Number} ;
+ N = Noun ; -- {s : Number => Str ; g : Gender} ;
+ A = Adj ; -- {s : Gender => Number => Str ; isPre : Bool} ;
+ V = Verb ; -- {s : VForm => Str ; aux : Aux} ;
+ V2 = Verb ** {c : Case} ;
+ AdA = {s : Str} ;
+ Pol = {s : Str ; b : Bool} ;
+ Tense = {s : Str ; t : ResIta.Tense} ;
+ Conj = {s : Str ; n : Number} ;
+ lin
+ UseCl t p cl = {s = t.s ++ p.s ++ cl.s ! t.t ! p.b} ;
+ PredVP np vp =
+ let
+ subj = (np.s ! Nom).obj ;
+ obj = vp.obj ! np.a ;
+ clit = vp.clit ;
+ verb = table {
+ Pres => agrV vp.v np.a ;
+ Perf => agrV (auxVerb vp.v.aux) np.a ++ agrPart vp.v np.a vp.clitAgr
+ }
+ in {
+ s = \\t,b => subj ++ neg b ++ clit ++ verb ! t ++ obj
+ } ;
+
+ ComplV2 v2 np =
+ let
+ nps = np.s ! v2.c
+ in {
+ v = v2 ;
+ clit = nps.clit ;
+ clitAgr = case <nps.isClit,v2.c> of {
+ <True,Acc> => CAgr np.a ;
+ _ => CAgrNo
+ } ;
+ obj = \\_ => nps.obj
+ } ;
+
+ UseV v = {
+ v = v ;
+ clit = [] ;
+ clitAgr = CAgrNo ;
+ obj = \\_ => []
+ } ;
+
+ DetCN det cn = {
+ s = \\c => {
+ obj = det.s ! cn.g ! c ++ cn.s ! det.n ;
+ clit = [] ;
+ isClit = False
+ } ;
+ a = Ag cn.g det.n Per3
+ } ;
+
+ ModCN ap cn = {
+ s = \\n => preOrPost ap.isPre (ap.s ! cn.g ! n) (cn.s ! n) ;
+ g = cn.g
+ } ;
+
+ CompAP ap = {
+ v = essere_V ;
+ clit = [] ;
+ clitAgr = CAgrNo ;
+ obj = \\ag => case ag of {
+ Ag g n _ => ap.s ! g ! n
+ }
+ } ;
+
+ AdAP ada ap = {
+ s = \\g,n => ada.s ++ ap.s ! g ! n ;
+ isPre = ap.isPre ;
+ } ;
+
+ ConjNP co nx ny = {
+ s = \\c => {
+ obj = (nx.s ! c).obj ++ co.s ++ (ny.s ! c).obj ;
+ clit = [] ;
+ isClit = False
+ } ;
+ a = conjAgr co.n nx.a ny.a
+ } ;
+
+ ConjS co x y = {s = x.s ++ co.s ++ y.s} ;
+
+ UseN n = n ;
+
+ UseA adj = adj ;
+
+ a_Det = adjDet (mkAdj "un" "una" [] [] True) Sg ;
+
+ every_Det = adjDet (regAdj "ogni") Sg ;
+
+ the_Det = {
+ s = table {
+ Masc => table {
+ Nom | Acc => elisForms "lo" "l'" "il" ;
+ Dat => elisForms "allo" "all'" "al"
+ } ;
+ Fem => table {
+ Nom | Acc => elisForms "la" "'l" "la" ;
+ Dat => elisForms "alla" "all'" "alla"
+ }
+ } ;
+ n = Sg
+ } ;
+
+ this_Det = adjDet (regAdj "questo") Sg ;
+ these_Det = adjDet (regAdj "questo") Pl ;
+ that_Det = adjDet quello_A Sg ;
+ those_Det = adjDet quello_A Pl ;
+
+ i_NP = pronNP "io" "mi" "mi" Masc Sg Per1 ;
+ she_NP = pronNP "lei" "la" "le" Fem Sg Per3 ;
+ we_NP = pronNP "noi" "ci" "ci" Masc Pl Per1 ;
+
+ very_AdA = ss "molto" ;
+
+ Pos = {s = [] ; b = True} ;
+ Neg = {s = [] ; b = False} ;
+ Pres = {s = [] ; t = ResIta.Pres} ;
+ Perf = {s = [] ; t = ResIta.Perf} ;
+
+ and_Conj = {s = "e" ; n = Pl} ;
+ or_Conj = {s = "o" ; n = Sg} ;
+
+ oper
+ quello_A : Adj = mkAdj
+ (elisForms "quello" "quell'" "quel") "quella"
+ (elisForms "quegli" "quegli" "quei") "quelle"
+ True ;
+
+}
diff --git a/book/examples/chapter9/Logic.gf b/book/examples/chapter9/Logic.gf
new file mode 100644
index 000000000..0ce8df7e9
--- /dev/null
+++ b/book/examples/chapter9/Logic.gf
@@ -0,0 +1,9 @@
+abstract Logic = {
+ cat
+ Prop ; Ind ;
+ data
+ And, Or, If : Prop -> Prop -> Prop ;
+ Not : Prop -> Prop ;
+ All, Exist : (Ind -> Prop) -> Prop ;
+ Past : Prop -> Prop ;
+}
diff --git a/book/examples/chapter9/LogicIta.gf b/book/examples/chapter9/LogicIta.gf
new file mode 100644
index 000000000..f94edc11c
--- /dev/null
+++ b/book/examples/chapter9/LogicIta.gf
@@ -0,0 +1,54 @@
+concrete LogicIta of Logic = GrammarIta ** open ResIta, Formal, Prelude in {
+
+
+lincat
+ T, I = SS ;
+lin
+ And x y = infixSS "&" x y ;
+ Or x y = infixSS "v" x y ;
+ If x y = infixSS "->" x y ;
+ Not x = prefixSS "~" x ;
+ All P = prefixSS (parenth ("A" ++ P.$0)) P ;
+ Exist P = prefixSS (parenth ("E" ++ P.$0)) P ;
+ Past P = prefixSS "Past" P ;
+
+lin
+ iN f = star (f.s ! Sg) ;
+ iA f = star (f.s ! Masc ! Sg) ;
+ iV f = star (f.s ! VInf) ;
+ iV2 f x y = star (f.s ! VInf) (cc2 x y) ;
+
+oper star : Str -> SS -> SS = \f,x -> prefixSS f (ss (parenth x.s)) ;
+
+{-
+
+lincat
+ T, I = TermPrec ;
+lin
+ And = infixl 2 "&" ;
+ Or = infixl 2 "v" ;
+ If = infixr 1 "->" ;
+-- Not = prefix 3 "~" ;
+-- All : (I -> T) -> T ;
+-- Exist : (I -> T) -> T ;
+-- Past : T -> T ;
+
+lin
+ iS : S -> T ;
+ iCl : Cl -> T ;
+ iNP : NP -> (I -> T) -> T ;
+ iVP : VP -> I -> T ;
+ iAP : AP -> I -> T ;
+ iCN : CN -> I -> T ;
+ iDet : Det -> (I -> T) -> (I -> T) -> T ;
+ iN : N -> I -> T ;
+ iA : A -> I -> T ;
+ iV : V -> I -> T ;
+ iV2 : V2 -> I -> I -> T ;
+ iAdA : AdA -> (I -> T) -> I -> T ;
+ iTense : Tense -> T -> T ;
+ iPol : Pol -> T -> T ;
+ iConj : Conj -> T -> T -> T ;
+-}
+
+}
diff --git a/book/examples/chapter9/LogicSymb.gf b/book/examples/chapter9/LogicSymb.gf
new file mode 100644
index 000000000..14932fe9b
--- /dev/null
+++ b/book/examples/chapter9/LogicSymb.gf
@@ -0,0 +1,13 @@
+concrete LogicSymb of Logic = open Formal, Prelude in {
+
+lincat
+ Prop, Ind = TermPrec ;
+lin
+ And = infixl 2 "\\&" ;
+ Or = infixl 2 "\\vee" ;
+ If = infixr 1 "\\sup" ;
+ Not = prefix 3 "\\sim" ;
+ All P = prefix 3 (parenth ("\\forall" ++ P.$0)) P ;
+ Exist P = prefix 3 (parenth ("\\exists" ++ P.$0)) P ;
+ Past = prefix 3 "P" ;
+}
diff --git a/book/examples/chapter9/ParadigmsIta.gf b/book/examples/chapter9/ParadigmsIta.gf
new file mode 100644
index 000000000..010140a62
--- /dev/null
+++ b/book/examples/chapter9/ParadigmsIta.gf
@@ -0,0 +1,47 @@
+resource ParadigmsIta = GrammarIta [N,A,V] **
+ open ResIta, GrammarIta, Prelude in {
+
+oper
+ masculine : Gender = Masc ;
+ feminine : Gender = Fem ;
+
+ accusative : Case = Acc ;
+ dative : Case = Dat ;
+
+ mkN = overload {
+ mkN : (vino : Str) -> N
+ = \n -> lin N (regNoun n) ;
+ mkN : (uomo, uomini : Str) -> Gender -> N
+ = \s,p,g -> lin N (mkNoun s p g) ;
+ } ;
+
+ mkA = overload {
+ mkA : (nero : Str) -> A
+ = \a -> lin A (regAdj a) ;
+ mkA : (buono,buona,buoni,buone : Str) -> Bool -> A
+ = \sm,sf,pm,pf,p -> lin A (mkAdj sm sf pm pf False) ;
+ } ;
+
+ preA : A -> A
+ = \a -> lin A {s = a.s ; isPre = True} ;
+
+ mkV = overload {
+ mkV : (finire : Str) -> V
+ = \v -> lin V (regVerb v) ;
+ mkV : (andare,vado,vadi,va,andiamo,andate,vanno,andato : Str) -> V
+ = \i,p1,p2,p3,p4,p5,p6,p -> lin V (mkVerb i p1 p2 p3 p4 p5 p6 p Avere) ;
+ } ;
+
+ essereV : V -> V
+ = \v -> lin V {s = v.s ; aux = Essere} ;
+
+ mkV2 = overload {
+ mkV2 : Str -> V2
+ = \s -> lin V2 (regVerb s ** {c = accusative}) ;
+ mkV2 : V -> V2
+ = \v -> lin V2 (v ** {c = accusative}) ;
+ mkV2 : V -> Case -> V2
+ = \v,c -> lin V2 (v ** {c = c}) ;
+ } ;
+
+}
diff --git a/book/examples/chapter9/ResIta.gf b/book/examples/chapter9/ResIta.gf
new file mode 100644
index 000000000..f39db69f9
--- /dev/null
+++ b/book/examples/chapter9/ResIta.gf
@@ -0,0 +1,178 @@
+resource ResIta = open Prelude in {
+
+-- parameters
+
+param
+ Number = Sg | Pl ;
+ Gender = Masc | Fem ;
+ Case = Nom | Acc | Dat ;
+ Agr = Ag Gender Number Person ;
+ Aux = Avere | Essere ;
+ Tense = Pres | Perf ;
+ Person = Per1 | Per2 | Per3 ;
+
+ VForm = VInf | VPres Number Person | VPart Gender Number ;
+
+ ClitAgr = CAgrNo | CAgr Agr ;
+
+-- parts of speech
+
+oper
+ VP = {
+ v : Verb ;
+ clit : Str ;
+ clitAgr : ClitAgr ;
+ obj : Agr => Str
+ } ;
+ NP = {
+ s : Case => {clit,obj : Str ; isClit : Bool} ;
+ a : Agr
+ } ;
+
+-- the preposition word of an abstract case
+
+ prepCase : Case -> Str = \c -> case c of {
+ Dat => "a" ;
+ _ => []
+ } ;
+
+-- for predication
+
+ agrV : Verb -> Agr -> Str = \v,a -> case a of {
+ Ag _ n p => v.s ! VPres n p
+ } ;
+
+ auxVerb : Aux -> Verb = \a -> case a of {
+ Avere =>
+ mkVerb "avere" "ho" "hai" "ha" "abbiamo" "avete" "hanno" "avuto" Avere ;
+ Essere =>
+ mkVerb "essere" "sono" "sei" "" "siamo" "siete" "sono" "stato" Essere
+ } ;
+
+ agrPart : Verb -> Agr -> ClitAgr -> Str = \v,a,c -> case v.aux of {
+ Avere => case c of {
+ CAgr (Ag g n _) => v.s ! VPart g n ;
+ _ => v.s ! VPart Masc Sg
+ } ;
+ Essere => case a of {
+ Ag g n _ => v.s ! VPart g n
+ }
+ } ;
+
+ neg : Bool -> Str = \b -> case b of {True => [] ; False => "non"} ;
+
+ essere_V = auxVerb Essere ;
+
+-- for coordination
+
+ conjAgr : Number -> Agr -> Agr -> Agr = \n,xa,ya ->
+ let
+ x = agrFeatures xa ; y = agrFeatures ya
+ in Ag
+ (conjGender x.g y.g)
+ (conjNumber (conjNumber x.n y.n) n)
+ (conjPerson x.p y.p) ;
+
+ agrFeatures : Agr -> {g : Gender ; n : Number ; p : Person} = \a ->
+ case a of {Ag g n p => {g = g ; n = n ; p = p}} ;
+
+ conjGender : Gender -> Gender -> Gender = \g,h ->
+ case g of {Masc => Masc ; _ => h} ;
+
+ conjNumber : Number -> Number -> Number = \m,n ->
+ case m of {Pl => Pl ; _ => n} ;
+
+ conjPerson : Person -> Person -> Person = \p,q ->
+ case <p,q> of {
+ <Per1,_> | <_,Per1> => Per1 ;
+ <Per2,_> | <_,Per2> => Per2 ;
+ _ => Per3
+ } ;
+
+
+
+-- for morphology
+
+ Noun : Type = {s : Number => Str ; g : Gender} ;
+ Adj : Type = {s : Gender => Number => Str ; isPre : Bool} ;
+ Verb : Type = {s : VForm => Str ; aux : Aux} ;
+
+ mkNoun : Str -> Str -> Gender -> Noun = \vino,vini,g -> {
+ s = table {Sg => vino ; Pl => vini} ;
+ g = g
+ } ;
+
+ regNoun : Str -> Noun = \vino -> case vino of {
+ fuo + c@("c"|"g") + "o" => mkNoun vino (fuo + c + "hi") Masc ;
+ ol + "io" => mkNoun vino (ol + "i") Masc ;
+ vin + "o" => mkNoun vino (vin + "i") Masc ;
+ cas + "a" => mkNoun vino (cas + "e") Fem ;
+ pan + "e" => mkNoun vino (pan + "i") Masc ;
+ _ => mkNoun vino vino Masc
+ } ;
+
+ mkAdj : (_,_,_,_ : Str) -> Bool -> Adj = \buono,buona,buoni,buone,p -> {
+ s = table {
+ Masc => table {Sg => buono ; Pl => buoni} ;
+ Fem => table {Sg => buona ; Pl => buone}
+ } ;
+ isPre = p
+ } ;
+
+ regAdj : Str -> Adj = \nero -> case nero of {
+ ner + "o" => mkAdj nero (ner + "a") (ner + "i") (ner + "e") False ;
+ verd + "e" => mkAdj nero nero (verd + "i") (verd + "i") False ;
+ _ => mkAdj nero nero nero nero False
+ } ;
+
+ mkVerb : (_,_,_,_,_,_,_,_ : Str) -> Aux -> Verb =
+ \amare,amo,ami,ama,amiamo,amate,amano,amato,aux -> {
+ s = table {
+ VInf => amare ;
+ VPres Sg Per1 => amo ;
+ VPres Sg Per2 => ami ;
+ VPres Sg Per3 => ama ;
+ VPres Pl Per1 => amiamo ;
+ VPres Pl Per2 => amate ;
+ VPres Pl Per3 => amano ;
+ VPart g n => (regAdj amato).s ! g ! n
+ } ;
+ aux = aux
+ } ;
+
+ regVerb : Str -> Verb = \amare -> case amare of {
+ am + "are" => mkVerb amare (am+"o") (am+"i") (am+"a")
+ (am+"iamo") (am+"ate") (am+"ano") (am+"ato") Avere ;
+ tem + "ere" => mkVerb amare (tem+"o") (tem+"i") (tem+"e")
+ (tem+"iamo") (tem+"ete") (tem+"ono") (tem+"uto") Avere ;
+ fin + "ire" => mkVerb amare (fin+"isco") (fin+"isci") (fin+"isce")
+ (fin+"iamo") (fin+"ite") (fin+"iscono") (fin+"ito") Avere
+ } ;
+
+-- for structural words
+
+ adjDet : Adj -> Number -> {s : Gender => Case => Str ; n : Number} =
+ \adj,n -> {
+ s = \\g,c => prepCase c ++ adj.s ! g ! n ;
+ n = n
+ } ;
+
+ pronNP : (s,a,d : Str) -> Gender -> Number -> Person -> NP =
+ \s,a,d,g,n,p -> {
+ s = table {
+ Nom => {clit = [] ; obj = s ; isClit = False} ;
+ Acc => {clit = a ; obj = [] ; isClit = True} ;
+ Dat => {clit = d ; obj = [] ; isClit = True}
+ } ;
+ a = Ag g n p
+ } ;
+
+-- phonological auxiliaries
+
+ vowel : pattern Str = #("a" | "e" | "i" | "o" | "u" | "h") ;
+ s_impuro : pattern Str = #("z" | "s" + ("b"|"c"|"d"|"f"|"m"|"p"|"q"|"t")) ;
+
+ elisForms : (_,_,_ : Str) -> Str = \lo,l',il ->
+ pre {#s_impuro => lo ; #vowel => l' ; _ => il} ;
+
+}
diff --git a/book/examples/chapter9/Semantics.gf b/book/examples/chapter9/Semantics.gf
new file mode 100644
index 000000000..0976caa93
--- /dev/null
+++ b/book/examples/chapter9/Semantics.gf
@@ -0,0 +1,39 @@
+abstract Semantics = Grammar, Logic ** {
+fun
+ iS : S -> Prop ;
+ iCl : Cl -> Prop ;
+ iNP : NP -> (Ind -> Prop) -> Prop ;
+ iVP : VP -> Ind -> Prop ;
+ iAP : AP -> Ind -> Prop ;
+ iCN : CN -> Ind -> Prop ;
+ iDet : Det -> (Ind -> Prop) -> (Ind -> Prop) -> Prop ;
+ iN : N -> Ind -> Prop ;
+ iA : A -> Ind -> Prop ;
+ iV : V -> Ind -> Prop ;
+ iV2 : V2 -> Ind -> Ind -> Prop ;
+ iAdA : AdA -> (Ind -> Prop) -> Ind -> Prop ;
+ iTense : Tense -> Prop -> Prop ;
+ iPol : Pol -> Prop -> Prop ;
+ iConj : Conj -> Prop -> Prop -> Prop ;
+def
+ iS (UseCl t p cl) = iTense t (iPol p (iCl cl)) ;
+ iCl (PredVP np vp) = iNP np (iVP vp) ;
+ iVP (ComplV2 v2 np) i = iNP np (iV2 v2 i) ;
+ iNP (DetCN det cn) f = iDet det (iCN cn) f ;
+ iCN (ModCN ap cn) i = And (iAP ap i) (iCN cn i) ;
+ iVP (CompAP ap) i = iAP ap i ;
+ iAP (AdAP ada ap) i = iAdA ada (iAP ap) i ;
+ iS (ConjS conj x y) = iConj conj (iS x) (iS y) ;
+ iNP (ConjNP conj x y) f = iConj conj (iNP x f) (iNP y f) ;
+ iVP (UseV v) i = iV v i ;
+ iAP (UseA a) i = iA a i ;
+ iCN (UseN n) i = iN n i ;
+ iDet a_Det d f = Exist (\x -> And (d x) (f x)) ;
+ iDet every_Det d f = All (\x -> If (d x) (f x)) ;
+ iPol Pos t = t ;
+ iPol Neg t = Not t ;
+ iTense Pres t = t ;
+ iTense Perf t = Past t ;
+ iConj and_Conj a b = And a b ;
+ iConj or_Conj a b = Or a b ;
+}
diff --git a/book/examples/chapter9/SemanticsIta.gf b/book/examples/chapter9/SemanticsIta.gf
new file mode 100644
index 000000000..70d4b79b9
--- /dev/null
+++ b/book/examples/chapter9/SemanticsIta.gf
@@ -0,0 +1,42 @@
+concrete SemanticsIta of Semantics = GrammarIta, LogicSymb ** open ResIta, Formal, Prelude in {
+
+lin
+ iN f = star (f.s ! Sg) ;
+ iA f = star (f.s ! Masc ! Sg) ;
+ iV f = star (f.s ! VInf) ;
+ iV2 f x y = star (f.s ! VInf) (cc2 x y) ;
+
+oper star : Str -> SS -> TermPrec = \f,x -> prefix 3 (f ++ "*") (constant (parenth x.s)) ;
+
+{-
+
+lincat
+ T, I = TermPrec ;
+lin
+ And = infixl 2 "&" ;
+ Or = infixl 2 "v" ;
+ If = infixr 1 "->" ;
+-- Not = prefix 3 "~" ;
+-- All : (I -> T) -> T ;
+-- Exist : (I -> T) -> T ;
+-- Past : T -> T ;
+
+lin
+ iS : S -> T ;
+ iCl : Cl -> T ;
+ iNP : NP -> (I -> T) -> T ;
+ iVP : VP -> I -> T ;
+ iAP : AP -> I -> T ;
+ iCN : CN -> I -> T ;
+ iDet : Det -> (I -> T) -> (I -> T) -> T ;
+ iN : N -> I -> T ;
+ iA : A -> I -> T ;
+ iV : V -> I -> T ;
+ iV2 : V2 -> I -> I -> T ;
+ iAdA : AdA -> (I -> T) -> I -> T ;
+ iTense : Tense -> T -> T ;
+ iPol : Pol -> T -> T ;
+ iConj : Conj -> T -> T -> T ;
+-}
+
+}
diff --git a/book/examples/chapter9/Syntax.gf b/book/examples/chapter9/Syntax.gf
new file mode 100644
index 000000000..01a51d0ee
--- /dev/null
+++ b/book/examples/chapter9/Syntax.gf
@@ -0,0 +1,47 @@
+interface Syntax = Grammar -
+ [UseCl,PredVP,ComplV2,UseV,DetCN,ModCN,CompAP,AdAP,
+ ConjS,ConjNP,UseN,UseA,Pres,Perf,Pos,Neg] **
+ open Grammar in {
+
+oper
+ mkS = overload {
+ mkS : Cl -> S = UseCl Pres Pos ;
+ mkS : Tense -> Cl -> S = \t -> UseCl t Pos ;
+ mkS : Pol -> Cl -> S = UseCl Pres ;
+ mkS : Tense -> Pol -> Cl -> S = UseCl ;
+ mkS : Conj -> S -> S -> S = ConjS ;
+ } ;
+
+ mkCl = overload {
+ mkCl : NP -> V -> Cl = \np,v -> PredVP np (UseV v) ;
+ mkCl : NP -> V2 -> NP -> Cl = \np,v,o -> PredVP np (ComplV2 v o) ;
+ mkCl : NP -> A -> Cl = \np,a -> PredVP np (CompAP (UseA a)) ;
+ mkCl : NP -> AP -> Cl = \np,ap -> PredVP np (CompAP ap) ;
+ mkCl : NP -> VP -> Cl = PredVP ;
+ } ;
+
+ mkAP = overload {
+ mkAP : A -> AP = UseA ;
+ mkAP : AdA -> AP -> AP = AdAP ;
+ } ;
+
+ mkNP = overload {
+ mkNP : Det -> N -> NP = \d,n -> DetCN d (UseN n) ;
+ mkNP : Det -> CN -> NP = \d,n -> DetCN d n ;
+ mkNP : Conj -> NP -> NP -> NP = ConjNP ;
+ } ;
+
+ mkCN = overload {
+ mkCN : N -> CN = UseN ;
+ mkCN : A -> N -> CN = \a,n -> ModCN (UseA a) (UseN n) ;
+ mkCN : A -> CN -> CN = \a,n -> ModCN (UseA a) n ;
+ mkCN : AP -> N -> CN = \a,n -> ModCN a (UseN n) ;
+ mkCN : AP -> CN -> CN = \a,n -> ModCN a n ;
+ } ;
+
+ presTense : Tense = Pres ;
+ perfTense : Tense = Perf ;
+ posPol : Pol = Pos ;
+ negPol : Pol = Neg ;
+
+}
diff --git a/book/examples/chapter9/SyntaxIta.gf b/book/examples/chapter9/SyntaxIta.gf
new file mode 100644
index 000000000..b4562b0de
--- /dev/null
+++ b/book/examples/chapter9/SyntaxIta.gf
@@ -0,0 +1,3 @@
+instance SyntaxIta of Syntax = GrammarIta -
+ [PredVP,ComplV2,UseV,DetCN,ModCN,CompAP,AdAP,UseN,UseA] **
+ open GrammarIta in {} ;
diff --git a/book/examples/chapter9/Test.gf b/book/examples/chapter9/Test.gf
new file mode 100644
index 000000000..ebe55e7e0
--- /dev/null
+++ b/book/examples/chapter9/Test.gf
@@ -0,0 +1,9 @@
+abstract Test = Grammar ** {
+
+fun
+ man_N, woman_N, house_N, tree_N : N ;
+ big_A, small_A, green_A : A ;
+ walk_V, arrive_V : V ;
+ love_V2, please_V2 : V2 ;
+
+} ;
diff --git a/book/examples/chapter9/TestIta.gf b/book/examples/chapter9/TestIta.gf
new file mode 100644
index 000000000..8ae524371
--- /dev/null
+++ b/book/examples/chapter9/TestIta.gf
@@ -0,0 +1,17 @@
+concrete TestIta of Test = GrammarIta ** open ParadigmsIta in {
+
+lin
+ man_N = mkN "uomo" "uomini" masculine ;
+ woman_N = mkN "donna" ;
+ house_N = mkN "casa" ;
+ tree_N = mkN "albero" ;
+ big_A = preA (mkA "grande") ;
+ small_A = preA (mkA "piccolo") ;
+ green_A = mkA "verde" ;
+ walk_V = mkV "camminare" ;
+ arrive_V = essereV (mkV "arrivare") ;
+ love_V2 = mkV2 "amare" ;
+ please_V2 = mkV2 (essereV (mkV "piacere" "piaccio" "piaci" "piace"
+ "piacciamo" "piacete" "piacciono" "piaciuto")) dative ;
+
+} ;
diff --git a/book/examples/chapter9/TestSemantics.gf b/book/examples/chapter9/TestSemantics.gf
new file mode 100644
index 000000000..ce8fe4428
--- /dev/null
+++ b/book/examples/chapter9/TestSemantics.gf
@@ -0,0 +1 @@
+abstract TestSemantics = Test, Semantics ;
diff --git a/book/examples/chapter9/TestSemanticsIta.gf b/book/examples/chapter9/TestSemanticsIta.gf
new file mode 100644
index 000000000..ce6abfc09
--- /dev/null
+++ b/book/examples/chapter9/TestSemanticsIta.gf
@@ -0,0 +1 @@
+concrete TestSemanticsIta of TestSemantics = TestIta, SemanticsIta ;