JEM tutorial examples - some files missing still

This commit is contained in:
aarne
2008-09-15 15:28:47 +00:00
parent a691f4dfaf
commit d2322241c1
6 changed files with 254 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
instance LexMathSpa of LexMath =
open SyntaxSpa, ParadigmsSpa, (L = LexiconSpa) in {
oper
zero_PN = mkPN "cero" ;
successor_N2 = mkN2 (mkN "sucesor") genitive ;
sum_N2 = mkN2 (mkN "suma") genitive ;
product_N2 = mkN2 (mkN "producto") genitive ;
even_A = mkA "par" ;
odd_A = mkA "impar" ;
prime_A = mkA "primo" ;
equal_A2 = mkA2 (mkA "igual") dative ;
small_A = L.small_A ;
great_A = L.big_A ;
divisible_A2 = mkA2 (mkA "divisible") (mkPrep "por") ;
number_N = mkN "entero" ;
}

34
examples/jem-math/Math.gf Normal file
View File

@@ -0,0 +1,34 @@
abstract Math = {
flags startcat = Prop ;
cat
Prop ; Exp ;
fun
And, Or, If : Prop -> Prop -> Prop ;
Zero : Exp ;
Successor : Exp -> Exp ;
Sum, Product : Exp -> Exp -> Exp ;
Even, Odd, Prime : Exp -> Prop ;
Equal, Less, Greater, Divisible : Exp -> Exp -> Prop ;
cat
Var ;
fun
X, Y : Var ;
EVar : Var -> Exp ;
EInt : Int -> Exp ;
ANumberVar : Var -> Exp ;
TheNumberVar : Var -> Exp ;
}

View File

@@ -0,0 +1,42 @@
concrete MathEng of Math = {
lincat
Prop, Exp = Str ;
lin
And a b = a ++ "and" ++ b ;
Or a b = a ++ "or" ++ b ;
If a b = "if" ++ a ++ "then" ++ b ;
Zero = "zero" ;
X = "x" ;
Y = "y" ;
Successor x = "the successor of" ++ x ;
Sum x y = "the sum of" ++ x ++ "and" ++ y ;
Product x y = "the product of" ++ x ++ "and" ++ y ;
Even x = x ++ "is even" ;
Odd x = x ++ "is odd" ;
Prime x = x ++ "is prime" ;
Equal x y = x ++ "is equal to" ++ y ;
Less x y = x ++ "is less than" ++ y ;
Greater x y = x ++ "is greater than" ++ y ;
Divisible x y = x ++ "is divisible by" ++ y ;
lincat
Var = Str ;
lin
X = "x" ;
Y = "y" ;
EVar x = x ;
EInt i = i.s ;
ANumberVar x = "a number" ++ x ;
TheNumberVar x = "the number" ++ x ;
}

View File

@@ -0,0 +1,40 @@
concrete MathIta of Math = {
lincat
Prop, Exp = Str ;
lin
And a b = a ++ "e" ++ b ;
Or a b = a ++ "o" ++ b ;
If a b = "si" ++ a ++ "allora" ++ b ;
Zero = "zero" ;
Successor x = "il successore di" ++ x ;
Sum x y = "la somma di" ++ x ++ "e" ++ y ;
Product x y = "il prodotto di" ++ x ++ "e" ++ y ;
Even x = x ++ "è pari" ;
Odd x = x ++ "è dispari" ;
Prime x = x ++ "è primo" ;
Equal x y = x ++ "è uguale a" ++ y ;
Less x y = x ++ "è inferiore a" ++ y ;
Greater x y = x ++ "è superiore a" ++ y ;
Divisible x y = x ++ "è divisibile per" ++ y ;
lincat
Var = Str ;
lin
X = "x" ;
Y = "y" ;
EVar x = x ;
EInt i = i.s ;
ANumberVar x = "un numero" ++ x ;
TheNumberVar x = "il numero" ++ x ;
}

View File

@@ -0,0 +1,112 @@
concrete MathIta1 of Math = {
param
Gender = Masc | Fem ;
Case = Nom | Gen | Dat ;
lincat
Prop = Str ;
Exp = NounPhrase ;
oper
NounPhrase : Type = {s : Case => Str ; g : Gender} ;
exp : (n,g,d : Str) -> Gender -> NounPhrase =
\n,g,d,ge -> {
s = table {
Nom => n ;
Gen => g ;
Dat => d
} ;
g = ge
} ;
const : Str -> Gender -> NounPhrase = \s,g ->
exp s ("di" ++ s) ("a" ++ s) g ;
funct1 : Str -> Gender -> NounPhrase -> NounPhrase = \f,g,x -> {
s = \\c => defArt g c ++ f ++ x.s ! Gen ;
g = g
} ;
funct2 : Str -> Gender -> NounPhrase -> NounPhrase -> NounPhrase = \f,g,x,y -> {
s = \\c => defArt g c ++ f ++ x.s ! Gen ++ y.s ! Gen ;
g = g
} ;
defArt : Gender -> Case -> Str = \g,c -> case <g,c> of {
<Masc,Nom> => "il" ;
<Masc,Gen> => "del" ;
<Masc,Dat> => "al" ;
<Fem, Nom> => "la" ;
<Fem, Gen> => "della" ;
<Fem, Dat> => "alla"
} ;
Adjective : Type = Gender -> Str ;
pred1 : Str -> NounPhrase -> Str = \a,x ->
x.s ! Nom ++ "è" ++ adj a x.g ;
pred2 : Str -> Str -> Case -> NounPhrase -> NounPhrase -> Str = \a,s,c,x,y ->
x.s ! Nom ++ "è" ++ adj a x.g ++ s ++ y.s ! c ;
adj : Str -> Adjective = \s,g -> case g of {
Masc => s ;
Fem => case s of {
ner + "o" => ner + "a" ;
_ => s
}
} ;
lin
And a b = a ++ "e" ++ b ;
Or a b = a ++ "o" ++ b ;
If a b = "si" ++ a ++ "allora" ++ b ;
Zero = const "zero" Masc ;
Successor = funct1 "successore" Masc ;
Sum = funct2 "somma" Fem ;
Product = funct2 "prodotto" Masc ;
Even = pred1 "pari" ;
Odd = pred1 "dispari" ;
Prime = pred1 "primo" ;
Equal = pred2 "uguale" [] Dat ;
Less = pred2 "inferiore" [] Dat ;
Greater = pred2 "superiore" [] Dat ;
Divisible = pred2 "divisibile" "per" Nom ;
lincat
Var = Str ;
lin
X = "x" ;
Y = "y" ;
EVar x = const x Masc ;
EInt i = const i.s Masc ;
ANumberVar x = const ("un numero" ++ x) Masc ;
TheNumberVar x = {
s = \\c => defArt Masc c ++ "numero" ++ x ;
g = Masc
} ;
-- overloaded API
oper
funct = overload {
funct : Str -> Gender -> NounPhrase = const ;
funct : Str -> Gender -> NounPhrase -> NounPhrase = funct1 ;
funct : Str -> Gender -> NounPhrase -> NounPhrase -> NounPhrase = funct2
} ;
pred = overload {
pred : Str -> NounPhrase -> Str = pred1 ;
pred : Str -> Str -> Case -> NounPhrase -> NounPhrase -> Str = pred2
} ;
}

View File

@@ -0,0 +1,8 @@
--# -path=.:present
concrete MathSpa of Math = MathI with
(Syntax = SyntaxSpa),
(Mathematical = MathematicalSpa),
(LexMath = LexMathSpa) ;