summaryrefslogtreecommitdiff
path: root/examples/tutorial/calculator/Calculator.gf
blob: c2fbcd1bc08b217bb49f3885b5404ef695f89129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
abstract Calculator = {

  flags startcat = Prog ;

  cat Prog ; Exp ; Var ;

  fun
    PEmpty : Prog ;
    PDecl  : Exp -> (Var -> Prog) -> Prog ;
    PAss   : Var -> Exp  -> Prog  -> Prog ;

    EPlus, EMinus, ETimes, EDiv : Exp -> Exp -> Exp ;

    EInt : Int -> Exp ;
    EVar : Var -> Exp ;

    ex1 : Prog ;

  def
    ex1 = 
      PDecl (EPlus (EInt 2) (EInt 3)) (\x -> 
        PDecl (EPlus (EVar x) (EInt 1)) (\y -> 
          PAss x (EPlus (EVar x) (ETimes (EInt 9) (EVar y))) PEmpty)) ;

}