]> ruin.nu Git - proglang.git/commitdiff
initial commit
authorMichael Andreen <harv@ruin.nu>
Tue, 7 Feb 2006 09:51:45 +0000 (09:51 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 7 Feb 2006 09:51:45 +0000 (09:51 +0000)
Abs.hs [new file with mode: 0644]
documentation [new file with mode: 0644]
examples/bool [new file with mode: 0644]
examples/fac [new file with mode: 0644]
examples/fib [new file with mode: 0644]
examples/if [new file with mode: 0644]
examples/sum [new file with mode: 0644]
examples/var [new file with mode: 0644]
syntax.cf [new file with mode: 0644]

diff --git a/Abs.hs b/Abs.hs
new file mode 100644 (file)
index 0000000..c90a233
--- /dev/null
+++ b/Abs.hs
@@ -0,0 +1,47 @@
+{-
+Abstract syntax for the language. This will be translated from the abstract syntax generated by bnfc.
+
+The goal of this abstract syntax is to combine similar statements/expressions to be grouped together to simplify type checking and execution.
+
+This abstract syntax is far from ready so far, but it gives a hint of what we are planning.
+-}
+module Abs (
+       Ident
+       ,Stm(...)
+       ,Exp(...)
+       ,Op(...)
+       ,BOp(...)
+) where
+
+newtype Ident = Ident String deriving (Eq,Ord,Show)
+
+type Program = [Stm]
+
+data Stm = 
+         SNoop
+       | SDecl Type Ident Exp
+       | SExp Exp
+       | SBlock [Stm]
+       | SIf Exp Stm Stm
+       | SWhile Exp Stm
+       | SPrint Exp
+       deriving (Eq,Ord,Show)
+
+data Exp =
+         EOp Op Exp Exp
+       | EBOp BOp Exp Exp
+       | EVar Ident
+       | EInt Integer
+       | EBool Bool
+       | ExpT Type Exp
+       | ENeg Exp
+       | ERead Type
+       deriving (Eq,Ord,Show)
+
+data Op = Plus | Minus | Div | Times 
+data BOp = Lt | Gt | Eq | Neq | ELt | EGt
+
+data Type =
+         TInt
+       | TBool
+       deriving (Eq,Ord,Show)
diff --git a/documentation b/documentation
new file mode 100644 (file)
index 0000000..cb693df
--- /dev/null
@@ -0,0 +1,77 @@
+####### DOCUMENTATIATOIAITAT ION ########
+
+
+
+
+a simple c-like language with support for if/else-statements, while-loops and the standard arithmetic (+, -, /, *) and comparison expressions (<, >, <=, >=, ==, !=). also, increase/decrease expressions (++, --) are supported.
+
+data types:
+integers and booleans.
+
+comments:
+// and /* */ comments are allowed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+examples:
+
+fib
+---
+int n1 = 0;
+int n2 = 1;
+int n = readInt;
+
+while(n-- > 0){
+  int temp = n1+n2;
+  n1 = n2;
+  n2 = temp;
+}
+print n2;
+
+
+tests while, decr and assignment.
+
+
+
+if
+--
+if (readBool) {
+  if (readInt < 0)
+    print true;
+  else
+    print false;
+}
+
+
+tests if and if/else.
+
+
+
+sum
+---
+int n;
+int sum = 0;
+while ((n = readInt) != -1) sum = sum + n;
+print sum;
+
+
+
+
+var
+---
+int a = 3;
+int b = a - 5;
+int c = a + b*7;
+bool d = a == b;
+
+tests simple variable operations.
\ No newline at end of file
diff --git a/examples/bool b/examples/bool
new file mode 100644 (file)
index 0000000..c85cc54
--- /dev/null
@@ -0,0 +1,7 @@
+bool a = true;
+bool b = false;
+int c, d;
+
+if (a == b) {  c = 4; d++; }
+
+
diff --git a/examples/fac b/examples/fac
new file mode 100644 (file)
index 0000000..9a941d7
--- /dev/null
@@ -0,0 +1,4 @@
+int fac = 1;
+int n = readInt;
+while( n-- > 0) fac = fac*n;
+print fac;
diff --git a/examples/fib b/examples/fib
new file mode 100644 (file)
index 0000000..0cf71f3
--- /dev/null
@@ -0,0 +1,10 @@
+int n1 = 0;
+int n2 = 1;
+int n = readInt;
+
+while(n-- > 0){
+  int temp = n1+n2;
+  n1 = n2;
+  n2 = temp;
+}
+print n2;
diff --git a/examples/if b/examples/if
new file mode 100644 (file)
index 0000000..c002570
--- /dev/null
@@ -0,0 +1,6 @@
+if (readBool) {
+  if (readInt < 0)
+    print true;
+  else
+    print false;
+}
\ No newline at end of file
diff --git a/examples/sum b/examples/sum
new file mode 100644 (file)
index 0000000..cda8206
--- /dev/null
@@ -0,0 +1,6 @@
+int n;
+int sum = 0;
+
+while ((n = readInt) != -1) sum = sum + n;
+
+print sum;
diff --git a/examples/var b/examples/var
new file mode 100644 (file)
index 0000000..51c5584
--- /dev/null
@@ -0,0 +1,4 @@
+int a = 3;
+int b = a - 5;
+int c = a + b*7;
+bool d = a == b;
diff --git a/syntax.cf b/syntax.cf
new file mode 100644 (file)
index 0000000..7e4740e
--- /dev/null
+++ b/syntax.cf
@@ -0,0 +1,60 @@
+
+-- ordinary rules
+
+BTrue. BoolT ::= "true" ;
+BFalse. BoolT ::= "false" ;
+
+SDecl.    Stm      ::= Typ Var ";" ;
+--SAss.     Stm      ::= Ident "=" Exp  ";"  ;
+SExp.     Stm      ::= Exp ";" ;
+SBlock.   Stm      ::= "{" [Stm] "}" ;
+SIf.      Stm      ::= "if" "(" Exp ")" Stm ;
+SIfE.     Stm      ::= "if" "(" Exp ")" Stm "else" Stm ;
+SWhile.   Stm      ::= "while" "(" Exp ")" Stm ;
+-- SFor.     Stm      ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
+SPrint.   Stm      ::= "print" Exp ";" ;
+
+VVar.     Var      ::= Ident ;
+VAss.     Var      ::= Ident "=" Exp;
+
+ELt.      Exp     ::= Exp1 "<" Exp1 ;
+EELt.     Exp     ::= Exp1 "<=" Exp1 ;
+EGt.      Exp     ::= Exp1 ">" Exp1 ;
+EEGt.     Exp     ::= Exp1 ">=" Exp1 ;
+EEq.      Exp     ::= Exp1 "==" Exp1 ;
+ENEq.     Exp     ::= Exp1 "!=" Exp1 ;
+EPlus.    Exp1    ::= Exp1 "+" Exp2 ;
+EMinus.   Exp1    ::= Exp1 "-" Exp2 ;
+ETimes.   Exp2    ::= Exp2 "*" Exp3 ;
+EDiv.     Exp2    ::= Exp2 "/" Exp3 ;
+EIncr.    Exp3    ::= Ident "++" ;
+EDecr.    Exp3    ::= Ident "--" ;
+EVar.     Exp3    ::= Var ;
+EInt.     Exp3    ::= Integer ;
+ENeg.     Exp3    ::= "-" Exp3 ;
+EBool.    Exp3    ::= BoolT ;
+EReadI.   Exp3    ::= "readInt" ;
+EReadB.   Exp3    ::= "readBool" ;
+
+coercions Exp 3 ;
+
+
+_.        Stm     ::= Stm ";" ;
+
+
+terminator Stm "" ;
+
+Program.  Stms ::= [Stm] ;
+
+
+TInt.     Typ  ::= "int" ;
+TBool.  Typ  ::= "bool" ;
+
+-- pragmas
+
+internal ExpT. Exp ::= Typ Exp ;
+
+comment "/*" "*/" ;
+comment "//" ;
+
+entrypoints Stms, Exp ;