From d2322241c1cf5d5ca0609db0b9673eece1668651 Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 15 Sep 2008 15:28:47 +0000 Subject: [PATCH] JEM tutorial examples - some files missing still --- examples/jem-math/LexMathSpa.gf | 18 +++++ examples/jem-math/Math.gf | 34 ++++++++++ examples/jem-math/MathEng.gf | 42 ++++++++++++ examples/jem-math/MathIta.gf | 40 ++++++++++++ examples/jem-math/MathIta1.gf | 112 ++++++++++++++++++++++++++++++++ examples/jem-math/MathSpa.gf | 8 +++ 6 files changed, 254 insertions(+) create mode 100644 examples/jem-math/LexMathSpa.gf create mode 100644 examples/jem-math/Math.gf create mode 100644 examples/jem-math/MathEng.gf create mode 100644 examples/jem-math/MathIta.gf create mode 100644 examples/jem-math/MathIta1.gf create mode 100644 examples/jem-math/MathSpa.gf diff --git a/examples/jem-math/LexMathSpa.gf b/examples/jem-math/LexMathSpa.gf new file mode 100644 index 000000000..a52ae1599 --- /dev/null +++ b/examples/jem-math/LexMathSpa.gf @@ -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" ; + +} diff --git a/examples/jem-math/Math.gf b/examples/jem-math/Math.gf new file mode 100644 index 000000000..b4e1cb2c2 --- /dev/null +++ b/examples/jem-math/Math.gf @@ -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 ; + +} diff --git a/examples/jem-math/MathEng.gf b/examples/jem-math/MathEng.gf new file mode 100644 index 000000000..ac29a504e --- /dev/null +++ b/examples/jem-math/MathEng.gf @@ -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 ; + +} diff --git a/examples/jem-math/MathIta.gf b/examples/jem-math/MathIta.gf new file mode 100644 index 000000000..a4e406fe3 --- /dev/null +++ b/examples/jem-math/MathIta.gf @@ -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 ; + + +} diff --git a/examples/jem-math/MathIta1.gf b/examples/jem-math/MathIta1.gf new file mode 100644 index 000000000..6606ce197 --- /dev/null +++ b/examples/jem-math/MathIta1.gf @@ -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 of { + => "il" ; + => "del" ; + => "al" ; + => "la" ; + => "della" ; + => "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 + } ; + +} diff --git a/examples/jem-math/MathSpa.gf b/examples/jem-math/MathSpa.gf new file mode 100644 index 000000000..961f8515b --- /dev/null +++ b/examples/jem-math/MathSpa.gf @@ -0,0 +1,8 @@ +--# -path=.:present + +concrete MathSpa of Math = MathI with + (Syntax = SyntaxSpa), + (Mathematical = MathematicalSpa), + (LexMath = LexMathSpa) ; + +