summaryrefslogtreecommitdiff
path: root/examples/tutorial/calculator/CalculatorP.gf
blob: 57ac549c190f2c610c98b973298fd0546fb69eb3 (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 CalculatorP of Calculator = open Prelude in {

  flags lexer=codevars ; unlexer=code ;

  lincat 
    Prog, Var = SS ; 
    Exp = SS ;

  lin
    PEmpty = ss [] ;
    PDecl exp prog = ss ("int" ++ prog.$0 ++ "=" ++ exp.s ++ ";" ++ prog.s) ;
    PAss vr exp prog = ss (vr.s ++ "=" ++ exp.s ++ ";" ++ prog.s) ;

    EPlus  = infix "+" ;
    EMinus = infix "-" ;
    ETimes = infix "*" ;
    EDiv   = infix "/" ;

    EInt i = i ;
    EVar x = x ;

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