summaryrefslogtreecommitdiff
path: root/devel/compiler
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2007-03-24 23:11:59 +0000
committeraarne <aarne@cs.chalmers.se>2007-03-24 23:11:59 +0000
commit436ddd5ebf531c2693af9402236a5a0c462dc5b7 (patch)
tree1bff96f484f3af5f78f9b1d92ad14532a440f9f2 /devel/compiler
parent4fdc0b598a36ab6b368e39f354364e20d27e9993 (diff)
simple source language for compiler experiment
Diffstat (limited to 'devel/compiler')
-rw-r--r--devel/compiler/Src.cf64
-rw-r--r--devel/compiler/ex.src31
2 files changed, 95 insertions, 0 deletions
diff --git a/devel/compiler/Src.cf b/devel/compiler/Src.cf
new file mode 100644
index 000000000..5901ff8ed
--- /dev/null
+++ b/devel/compiler/Src.cf
@@ -0,0 +1,64 @@
+Gr. Grammar ::= [Def] ;
+
+DPar. Def ::= "param" Ident "=" [Constr] ;
+DOper. Def ::= "oper" Ident ":" Type "=" Exp ;
+DOpty. Def ::= "oper" Ident "=" Type ;
+DLin. Def ::= "lin" Ident ":" Type "=" Exp ;
+
+terminator Def ";" ;
+
+Con. Constr ::= Ident [Type] ;
+
+separator nonempty Constr "|" ;
+
+TBas. Type1 ::= Ident ;
+TVal. Type1 ::= "Ints" Integer ;
+TRec. Type1 ::= "{" [Typing] "}" ;
+TFun. Type ::= Type1 "->" Type ;
+
+coercions Type 1 ;
+
+terminator Type "" ;
+
+FTyp. Typing ::= Ident ":" Type ;
+
+separator Typing ";" ;
+
+EVar. Exp2 ::= "$" Ident ;
+ECon. Exp2 ::= Ident ;
+EVal. Exp2 ::= Integer ;
+EStr. Exp2 ::= String ;
+ERec. Exp2 ::= "{" [Assign] "}" ;
+EApp. Exp1 ::= Exp1 Exp2 ;
+ESel. Exp1 ::= Exp1 "!" Exp2 ;
+EPro. Exp1 ::= Exp1 "." Exp2 ;
+ETab. Exp1 ::= "table" "{" [Case] "}" ;
+ETbv. Exp1 ::= "table" "(" Type ")" "{" [Exp] "}" ;
+ECat. Exp ::= Exp "++" Exp1 ;
+EAbs. Exp ::= "\\" Ident "->" Exp ;
+
+coercions Exp 2 ;
+
+separator Exp ";" ;
+
+FExp. Assign ::= Ident "=" Exp ;
+
+separator Assign ";" ;
+
+Cas. Case ::= Patt "=>" Exp ;
+
+separator Case ";" ;
+
+PVal. Patt ::= Integer ;
+PVar. Patt ::= "$" Ident ;
+PRec. Patt ::= "{" [AssPatt] "}" ;
+PCon. Patt ::= "(" Ident [Patt] ")" ;
+
+terminator Patt "" ;
+
+FPatt. AssPatt ::= Ident "=" Patt ;
+
+separator AssPatt ";" ;
+
+comment "--" ;
+comment "{-" "-}" ;
diff --git a/devel/compiler/ex.src b/devel/compiler/ex.src
new file mode 100644
index 000000000..33890fb89
--- /dev/null
+++ b/devel/compiler/ex.src
@@ -0,0 +1,31 @@
+param Num = Sg | Pl ;
+param Gen = Masc | Fem ;
+
+oper Agr = {g : Gen ; n : Num} ;
+
+oper CN = {s : Num -> Str ; g : Gen} ;
+oper NP = {s : Str ; a : Agr} ;
+
+oper artDef : Gen -> Str = \g -> table {
+ (Masc) => "le" ;
+ (Fem) => "la"
+} ! g ;
+
+
+lin Voiture : CN = {
+ s = table {
+ (Sg) => "voiture" ;
+ (Pl) => "voitures"
+ } ;
+ g = Fem
+} ;
+
+lin Bus : CN = {
+ s = table {$x => "bus"} ;
+ g = Masc
+} ;
+
+lin Def : CN -> NP = \cn -> {
+ s = artDef cn.g ++ cn.s ! Sg ;
+ a = {g = cn.g ; n = Sg}
+} ;