forked from GitHub/gf-core
completed book examples
This commit is contained in:
4
book/examples/chapter2/Food.probs
Normal file
4
book/examples/chapter2/Food.probs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
This 0.8
|
||||||
|
Mod 0.2
|
||||||
|
Wine 0.0
|
||||||
|
Fresh 0.4
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
resource Exx = {
|
resource DefArtGer = {
|
||||||
|
|
||||||
param DetForm = DSg Gender Case | DPl Case ;
|
param DetForm = DSg Gender Case | DPl Case ;
|
||||||
param Gender = Masc | Fem | Neutr ;
|
param Gender = Masc | Fem | Neutr ;
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
--# -path=.:../foods:minimal:present
|
--# -path=.:present
|
||||||
|
|
||||||
concrete FoodsEng of Foods = open SyntaxEng,ParadigmsEng in {
|
concrete FoodsEng of Foods =
|
||||||
|
open SyntaxEng,ParadigmsEng in {
|
||||||
lincat
|
lincat
|
||||||
Phrase = Cl ;
|
Comment = Utt ;
|
||||||
Item = NP ;
|
Item = NP ;
|
||||||
Kind = CN ;
|
Kind = CN ;
|
||||||
Quality = AP ;
|
Quality = AP ;
|
||||||
lin
|
lin
|
||||||
Is item quality = mkCl item quality ;
|
Pred item quality = mkUtt (mkCl item quality) ;
|
||||||
This kind = mkNP this_Quant kind ;
|
This kind = mkNP this_Quant kind ;
|
||||||
That kind = mkNP that_Quant kind ;
|
That kind = mkNP that_Quant kind ;
|
||||||
These kind = mkNP this_Quant plNum kind ;
|
These kind = mkNP this_Quant plNum kind ;
|
||||||
Those kind = mkNP that_Quant plNum kind ;
|
Those kind = mkNP that_Quant plNum kind ;
|
||||||
QKind quality kind = mkCN quality kind ;
|
Mod quality kind = mkCN quality kind ;
|
||||||
Wine = mkCN (mkN "wine") ;
|
Wine = mkCN (mkN "wine") ;
|
||||||
Pizza = mkCN (mkN "pizza") ;
|
Pizza = mkCN (mkN "pizza") ;
|
||||||
Cheese = mkCN (mkN "cheese") ;
|
Cheese = mkCN (mkN "cheese") ;
|
||||||
|
|||||||
30
book/examples/chapter6/Arithm.gf
Normal file
30
book/examples/chapter6/Arithm.gf
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
abstract Arithm = {
|
||||||
|
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
|
||||||
|
|
||||||
|
cat Less Nat Nat ;
|
||||||
|
data LessZ : (y : Nat) -> Less Zero (Succ y) ;
|
||||||
|
data LessS : (x,y : Nat) -> Less x y -> Less (Succ x) (Succ y) ;
|
||||||
|
|
||||||
|
cat Span ;
|
||||||
|
data FromTo : (m,n : Nat) -> Less m n -> Span ;
|
||||||
|
|
||||||
|
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) ;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,8 +18,8 @@ lin
|
|||||||
Fan = mkCN (mkN "fan") ;
|
Fan = mkCN (mkN "fan") ;
|
||||||
Switchable, Dimmable = <> ;
|
Switchable, Dimmable = <> ;
|
||||||
|
|
||||||
SwitchOn = mkV2 (mkV "on" (mkV "switch")) ;
|
SwitchOn = mkV2 (partV (mkV "switch") "on") ;
|
||||||
SwitchOff = mkV2 (mkV "off" (mkV "switch")) ;
|
SwitchOff = mkV2 (partV (mkV "switch") "off") ;
|
||||||
Dim = mkV2 (mkV "dim") ;
|
Dim = mkV2 (mkV "dim") ;
|
||||||
|
|
||||||
switchable_Light = <> ;
|
switchable_Light = <> ;
|
||||||
|
|||||||
16
book/examples/chapter6/Smart.gf
Normal file
16
book/examples/chapter6/Smart.gf
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
abstract Smart = {
|
||||||
|
|
||||||
|
cat
|
||||||
|
Command ;
|
||||||
|
Kind ;
|
||||||
|
Device Kind ;
|
||||||
|
Action Kind ;
|
||||||
|
|
||||||
|
fun
|
||||||
|
Act : (k : Kind) -> Action k -> Device k -> Command ;
|
||||||
|
The : (k : Kind) -> Device k ; -- the light
|
||||||
|
Light, Fan : Kind ;
|
||||||
|
Dim : Action Light ;
|
||||||
|
SwitchOn, SwitchOff : (k : Kind) -> Action k ;
|
||||||
|
|
||||||
|
}
|
||||||
10
book/examples/chapter7/Map.gf
Normal file
10
book/examples/chapter7/Map.gf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
abstract Map = {
|
||||||
|
flags startcat = Query ;
|
||||||
|
cat
|
||||||
|
Query ; Input ; Place ; Click ;
|
||||||
|
fun
|
||||||
|
GoFromTo : Place -> Place -> Input ;
|
||||||
|
ThisPlace : Click -> Place ;
|
||||||
|
QueryInput : Input -> Query ;
|
||||||
|
ClickCoord : Int -> Int -> Click ;
|
||||||
|
}
|
||||||
17
book/examples/chapter7/MapEng.gf
Normal file
17
book/examples/chapter7/MapEng.gf
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
concrete MapEng of Map = {
|
||||||
|
lincat
|
||||||
|
Query = {s : Str} ;
|
||||||
|
Input, Place = {s : Str ; p : Str} ;
|
||||||
|
Click = {p : Str} ;
|
||||||
|
lin
|
||||||
|
GoFromTo x y = {
|
||||||
|
s = "I want to go from" ++ x.s ++ "to" ++ y.s ;
|
||||||
|
p = x.p ++ y.p
|
||||||
|
} ;
|
||||||
|
ThisPlace c = {
|
||||||
|
s = "this place" ;
|
||||||
|
p = c.p
|
||||||
|
} ;
|
||||||
|
QueryInput i = {s = i.s ++ ";" ++ i.p} ;
|
||||||
|
ClickCoord x y = {p = "(" ++ x.s ++ "," ++ y.s ++ ")"} ;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
--# -path=alltenses
|
--# -path=.:present
|
||||||
|
|
||||||
concrete GeometryEng of Geometry = LogicEng **
|
concrete GeometryEng of Geometry = LogicEng **
|
||||||
open SyntaxEng, ParadigmsEng in {
|
open SyntaxEng, ParadigmsEng in {
|
||||||
|
|||||||
7
book/examples/chapter8/Graftal.gf
Normal file
7
book/examples/chapter8/Graftal.gf
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
-- (c) Krasimir Angelov 2009
|
||||||
|
abstract Graftal = {
|
||||||
|
cat N; S;
|
||||||
|
fun z : N ;
|
||||||
|
s : N -> N ;
|
||||||
|
c : N -> S ;
|
||||||
|
}
|
||||||
16
book/examples/chapter8/Sierpinski.gf
Normal file
16
book/examples/chapter8/Sierpinski.gf
Normal file
@@ -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" ;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user