summaryrefslogtreecommitdiff
path: root/examples/tutorial/calculator/CalculatorJ.gf
blob: 0df7b73fe453091415ef4d36ae058c6a624695ac (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
--# -path=.:prelude

concrete CalculatorJ of Calculator = open Prelude in {

  flags lexer=codevars ; unlexer=code ;

  lincat 
    Prog, Exp, Var = SS ;

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

    EPlus  = postfix "iadd" ;
    EMinus = postfix "isub" ;
    ETimes = postfix "imul" ;
    EDiv   = postfix "imul" ;

    EInt = prefixSS "iconst" ;
    EVar = prefixSS "iload" ;

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