summaryrefslogtreecommitdiff
path: root/gf-book/examples/chapter8
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2011-01-11 15:46:43 +0000
committeraarne <aarne@chalmers.se>2011-01-11 15:46:43 +0000
commite7439d65b0e153434d3acc07df6e2a0972ee79ca (patch)
tree36716eec18256eeb600b4a552d9cc80f8ad7f16f /gf-book/examples/chapter8
parent276327f7f264e770478a6d8c6e683266505b0a55 (diff)
gf-book web page index and toc
Diffstat (limited to 'gf-book/examples/chapter8')
-rw-r--r--gf-book/examples/chapter8/Calculator.gf7
-rw-r--r--gf-book/examples/chapter8/CalculatorC.gf10
-rw-r--r--gf-book/examples/chapter8/CalculatorJ.gf13
-rw-r--r--gf-book/examples/chapter8/CalculatorP.gf14
-rw-r--r--gf-book/examples/chapter8/CalculatorS.gf11
-rw-r--r--gf-book/examples/chapter8/Geometry.gf7
-rw-r--r--gf-book/examples/chapter8/GeometryEng.gf13
-rw-r--r--gf-book/examples/chapter8/GeometryEngb.gf11
-rw-r--r--gf-book/examples/chapter8/Geometryb.gf7
-rw-r--r--gf-book/examples/chapter8/Graftal.gf7
-rw-r--r--gf-book/examples/chapter8/Logic.gf21
-rw-r--r--gf-book/examples/chapter8/LogicBEng.gf38
-rw-r--r--gf-book/examples/chapter8/LogicEng.gf39
-rw-r--r--gf-book/examples/chapter8/Logicb.gf11
-rw-r--r--gf-book/examples/chapter8/Sierpinski.gf16
15 files changed, 225 insertions, 0 deletions
diff --git a/gf-book/examples/chapter8/Calculator.gf b/gf-book/examples/chapter8/Calculator.gf
new file mode 100644
index 000000000..188c150e0
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/CalculatorC.gf b/gf-book/examples/chapter8/CalculatorC.gf
new file mode 100644
index 000000000..99db80530
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/CalculatorJ.gf b/gf-book/examples/chapter8/CalculatorJ.gf
new file mode 100644
index 000000000..c5f40c8d3
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/CalculatorP.gf b/gf-book/examples/chapter8/CalculatorP.gf
new file mode 100644
index 000000000..4e6315827
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/CalculatorS.gf b/gf-book/examples/chapter8/CalculatorS.gf
new file mode 100644
index 000000000..d8c1df456
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/Geometry.gf b/gf-book/examples/chapter8/Geometry.gf
new file mode 100644
index 000000000..0b27d8714
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/GeometryEng.gf b/gf-book/examples/chapter8/GeometryEng.gf
new file mode 100644
index 000000000..e2e22776e
--- /dev/null
+++ b/gf-book/examples/chapter8/GeometryEng.gf
@@ -0,0 +1,13 @@
+--# -path=.:present
+
+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/gf-book/examples/chapter8/GeometryEngb.gf b/gf-book/examples/chapter8/GeometryEngb.gf
new file mode 100644
index 000000000..265f3f71a
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/Geometryb.gf b/gf-book/examples/chapter8/Geometryb.gf
new file mode 100644
index 000000000..dc39c9ce4
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/Graftal.gf b/gf-book/examples/chapter8/Graftal.gf
new file mode 100644
index 000000000..e85b9b2f7
--- /dev/null
+++ b/gf-book/examples/chapter8/Graftal.gf
@@ -0,0 +1,7 @@
+-- (c) Krasimir Angelov 2009
+abstract Graftal = {
+ cat N; S;
+ fun z : N ;
+ s : N -> N ;
+ c : N -> S ;
+ }
diff --git a/gf-book/examples/chapter8/Logic.gf b/gf-book/examples/chapter8/Logic.gf
new file mode 100644
index 000000000..f2b292428
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/LogicBEng.gf b/gf-book/examples/chapter8/LogicBEng.gf
new file mode 100644
index 000000000..b950c6b39
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/LogicEng.gf b/gf-book/examples/chapter8/LogicEng.gf
new file mode 100644
index 000000000..eae85d255
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/Logicb.gf b/gf-book/examples/chapter8/Logicb.gf
new file mode 100644
index 000000000..5b5aa9ab9
--- /dev/null
+++ b/gf-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/gf-book/examples/chapter8/Sierpinski.gf b/gf-book/examples/chapter8/Sierpinski.gf
new file mode 100644
index 000000000..722088ce5
--- /dev/null
+++ b/gf-book/examples/chapter8/Sierpinski.gf
@@ -0,0 +1,16 @@
+concrete Sierpinski of Graftal = {
+ lincat N = {a : Str; b : Str} ;
+ lincat S = {s : Str} ;
+
+ lin z = {a = A; b = B} ;
+ lin s x = {
+ a = x.b ++ R ++ x.a ++ R ++ x.b ;
+ b = x.a ++ L ++ x.b ++ L ++ x.a
+ } ;
+ lin c x = {s = "newpath 300 550 moveto" ++ x.a ++ "stroke showpage"} ;
+
+ oper A : Str = "0 2 rlineto" ;
+ oper B : Str = "0 2 rlineto" ;
+ oper L : Str = "+60 rotate" ;
+ oper R : Str = "-60 rotate" ;
+}