--- /dev/null
+{-
+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)
--- /dev/null
+####### 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
--- /dev/null
+
+-- 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 ;