summaryrefslogtreecommitdiff
path: root/examples/tutorial/calculator/CalculatorE.gf
blob: f432d371a648e2ba3789fcdb38bde91885894207 (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
26
27
--# -path=.:prelude

concrete CalculatorE of Calculator = open Prelude in {

  flags lexer=codevar ; unlexer=unwords ;

  lincat 
    Prog, Exp, Var = SS ;

  lin
    PEmpty = ss [] ;
    PInit exp prog = ss ("initialize" ++ prog.$0 ++ "as" ++ exp.s ++ PAUSE ++ prog.s) ;
    PAss vr exp prog = ss ("redefine" ++ vr.s ++ "as" ++ exp.s ++ PAUSE ++ prog.s) ;

    EPlus  = infix "plus" ;
    EMinus = infix "minus" ;
    ETimes = infix "times" ;
    EDiv   = infix ["divided by"] ;

    EInt i = i ;
    EVar x = x ;

  oper
    infix : Str -> SS -> SS -> SS = \op,x,y -> 
      ss (x.s ++ op ++ y.s ++ PAUSE) ;
    PAUSE = "PAUSE" ;
}