forked from GitHub/gf-core
introducing multiple inheritance
This commit is contained in:
7
grammars/multiple/City.gf
Normal file
7
grammars/multiple/City.gf
Normal file
@@ -0,0 +1,7 @@
|
||||
abstract City = {
|
||||
cat
|
||||
City ;
|
||||
fun
|
||||
MkCity : String -> City ;
|
||||
} ;
|
||||
|
||||
5
grammars/multiple/CityEng.gf
Normal file
5
grammars/multiple/CityEng.gf
Normal file
@@ -0,0 +1,5 @@
|
||||
concrete CityEng of City = open Prelude in {
|
||||
lin
|
||||
MkCity s = s ;
|
||||
} ;
|
||||
|
||||
7
grammars/multiple/Math.gf
Normal file
7
grammars/multiple/Math.gf
Normal file
@@ -0,0 +1,7 @@
|
||||
abstract Math = {
|
||||
cat
|
||||
Number ;
|
||||
fun
|
||||
MkNumber : Int -> Number ;
|
||||
} ;
|
||||
|
||||
5
grammars/multiple/MathEng.gf
Normal file
5
grammars/multiple/MathEng.gf
Normal file
@@ -0,0 +1,5 @@
|
||||
concrete MathEng of Math = open Prelude in {
|
||||
lin
|
||||
MkNumber i = i ;
|
||||
} ;
|
||||
|
||||
4
grammars/multiple/System.gf
Normal file
4
grammars/multiple/System.gf
Normal file
@@ -0,0 +1,4 @@
|
||||
abstract System = {
|
||||
cat Reply ;
|
||||
fun Bye : Reply ;
|
||||
}
|
||||
4
grammars/multiple/SystemCity.gf
Normal file
4
grammars/multiple/SystemCity.gf
Normal file
@@ -0,0 +1,4 @@
|
||||
abstract SystemCity = System, City ** {
|
||||
fun
|
||||
RDistance : City -> City -> Int -> Reply ;
|
||||
} ;
|
||||
6
grammars/multiple/SystemCityEng.gf
Normal file
6
grammars/multiple/SystemCityEng.gf
Normal file
@@ -0,0 +1,6 @@
|
||||
concrete SystemCityEng of SystemCity = SystemEng, CityEng ** open
|
||||
Prelude in {
|
||||
lin
|
||||
RDistance x y d =
|
||||
ss (["the distance from"] ++ x.s ++ "to" ++ y.s ++ "is" ++ d.s) ;
|
||||
} ;
|
||||
3
grammars/multiple/SystemEng.gf
Normal file
3
grammars/multiple/SystemEng.gf
Normal file
@@ -0,0 +1,3 @@
|
||||
concrete SystemEng of System = open Prelude in {
|
||||
lin Bye = ss "bye" ;
|
||||
}
|
||||
4
grammars/multiple/SystemMath.gf
Normal file
4
grammars/multiple/SystemMath.gf
Normal file
@@ -0,0 +1,4 @@
|
||||
abstract SystemMath = System, Math ** {
|
||||
fun
|
||||
RSum : Number -> Number -> Int -> Reply ;
|
||||
} ;
|
||||
6
grammars/multiple/SystemMathEng.gf
Normal file
6
grammars/multiple/SystemMathEng.gf
Normal file
@@ -0,0 +1,6 @@
|
||||
concrete SystemMathEng of SystemMath = SystemEng, MathEng ** open
|
||||
Prelude in {
|
||||
lin
|
||||
RSum x y d =
|
||||
ss (["the sum of"] ++ x.s ++ "and" ++ y.s ++ "is" ++ d.s) ;
|
||||
} ;
|
||||
7
grammars/multiple/Top.gf
Normal file
7
grammars/multiple/Top.gf
Normal file
@@ -0,0 +1,7 @@
|
||||
abstract Top = User, System ** {
|
||||
cat
|
||||
Move ;
|
||||
fun
|
||||
MUser : Query -> Move ;
|
||||
MSystem : Reply -> Move ;
|
||||
}
|
||||
1
grammars/multiple/TopCity.gf
Normal file
1
grammars/multiple/TopCity.gf
Normal file
@@ -0,0 +1 @@
|
||||
abstract TopCity = Top, UserCity, SystemCity ** {} ;
|
||||
3
grammars/multiple/TopCityEng.gf
Normal file
3
grammars/multiple/TopCityEng.gf
Normal file
@@ -0,0 +1,3 @@
|
||||
--# -path=.:../prelude
|
||||
|
||||
concrete TopCityEng of TopCity = TopEng, UserCityEng, SystemCityEng ** {} ;
|
||||
6
grammars/multiple/TopEng.gf
Normal file
6
grammars/multiple/TopEng.gf
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
concrete TopEng of Top = UserEng, SystemEng ** open Prelude in {
|
||||
lin
|
||||
MUser q = q ;
|
||||
MSystem r = r ;
|
||||
}
|
||||
1
grammars/multiple/TopMath.gf
Normal file
1
grammars/multiple/TopMath.gf
Normal file
@@ -0,0 +1 @@
|
||||
abstract TopMath = Top, UserMath, SystemMath ** {} ;
|
||||
3
grammars/multiple/TopMathEng.gf
Normal file
3
grammars/multiple/TopMathEng.gf
Normal file
@@ -0,0 +1,3 @@
|
||||
--# -path=.:../prelude
|
||||
|
||||
concrete TopMathEng of TopMath = TopEng, UserMathEng, SystemMathEng ** {} ;
|
||||
7
grammars/multiple/User.gf
Normal file
7
grammars/multiple/User.gf
Normal file
@@ -0,0 +1,7 @@
|
||||
abstract User = {
|
||||
cat
|
||||
Query ;
|
||||
fun
|
||||
QQuit : Query ;
|
||||
} ;
|
||||
|
||||
5
grammars/multiple/UserCity.gf
Normal file
5
grammars/multiple/UserCity.gf
Normal file
@@ -0,0 +1,5 @@
|
||||
abstract UserCity = User, City ** {
|
||||
fun
|
||||
QDistance : City -> City -> Query ;
|
||||
} ;
|
||||
|
||||
6
grammars/multiple/UserCityEng.gf
Normal file
6
grammars/multiple/UserCityEng.gf
Normal file
@@ -0,0 +1,6 @@
|
||||
concrete UserCityEng of UserCity = UserEng, CityEng ** open Prelude in
|
||||
{
|
||||
lin
|
||||
QDistance x y = ss (["what is the distance from"] ++ x.s ++ "to" ++ y.s) ;
|
||||
}
|
||||
|
||||
5
grammars/multiple/UserEng.gf
Normal file
5
grammars/multiple/UserEng.gf
Normal file
@@ -0,0 +1,5 @@
|
||||
concrete UserEng of User = open Prelude in {
|
||||
lin
|
||||
QQuit = ss ["that's enough"] ;
|
||||
} ;
|
||||
|
||||
5
grammars/multiple/UserMath.gf
Normal file
5
grammars/multiple/UserMath.gf
Normal file
@@ -0,0 +1,5 @@
|
||||
abstract UserMath = User, Math ** {
|
||||
fun
|
||||
QSum : Number -> Number -> Query ;
|
||||
} ;
|
||||
|
||||
6
grammars/multiple/UserMathEng.gf
Normal file
6
grammars/multiple/UserMathEng.gf
Normal file
@@ -0,0 +1,6 @@
|
||||
concrete UserMathEng of UserMath = UserEng, MathEng ** open Prelude in
|
||||
{
|
||||
lin
|
||||
QSum x y = ss (["what is the sum of"] ++ x.s ++ "and" ++ y.s) ;
|
||||
}
|
||||
|
||||
1
grammars/multiple/UserUnionCity.gf
Normal file
1
grammars/multiple/UserUnionCity.gf
Normal file
@@ -0,0 +1 @@
|
||||
abstract UserUnionCity = union User, City ;
|
||||
32
grammars/multiple/map.txt
Normal file
32
grammars/multiple/map.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
Using multiple inheritance in GF. AR 15/9/2004.
|
||||
|
||||
The following diagrams show inheritance between abstract syntaxes in two simple systems.
|
||||
|
||||
TopCity
|
||||
/ | \
|
||||
/ | \
|
||||
SystemCity UserCity Top
|
||||
/ \ / \
|
||||
System City User
|
||||
|
||||
|
||||
TopMath
|
||||
/ | \
|
||||
/ | \
|
||||
SystemMath UserMath Top
|
||||
/ \ / \
|
||||
System Math User
|
||||
|
||||
|
||||
Idea of each module:
|
||||
|
||||
User -- User's moves on any domain
|
||||
System -- System's moves on any domain
|
||||
Top -- grammar covering both kinds of moves
|
||||
X = Math, City -- possible domains
|
||||
UserX -- User's domain specific moves
|
||||
SystemX -- System's domain specific moves
|
||||
TopX -- all moves on the domain X
|
||||
|
||||
In parallel to the abstract syntax hierarchies, we have of course
|
||||
hierarchies of concrete syntaxes for any language; this directory contains Eng.
|
||||
Reference in New Issue
Block a user