summaryrefslogtreecommitdiff
path: root/book/examples/chapter8
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2010-11-22 12:55:37 +0000
committeraarne <aarne@chalmers.se>2010-11-22 12:55:37 +0000
commit76ba03b545600054176612201de78dca16eb65e1 (patch)
tree5615286b239bee637b32465e9cbf36807ab2c318 /book/examples/chapter8
parent0bf41793694e8b3101d09e34858eba8ab2c8c5b6 (diff)
started a subdir for the book
Diffstat (limited to 'book/examples/chapter8')
-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
13 files changed, 202 insertions, 0 deletions
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 ;
+}