module IBAF-Start

imports
  libstratego-gpp
  signatures/-
  pp/IBAF-parenthesize
  pp/IBAF-pp

imports
  

// Language "IBAFlang"

rules
to-funcons:
  |[ start[: (:AExp:) :] ]| ->
  |[ initialise-binding finalise-failing eval-arith[: (:AExp:) :] ]|

// #1 Arithmetic expressions
              

to-funcons:
  |[ eval-arith[: (:N:) :] ]| ->
  |[ int-val[: (:N:) :] ]|
to-funcons:
  |[ eval-arith[: (:I:) :] ]| ->
  |[ assigned (bound (id[: (:I:) :])) ]|
to-funcons:
  |[ eval-arith[: (:AExp1:)+(:AExp2:) :] ]| ->
  |[ integer-add (eval-arith[: (:AExp1:) :], 
             eval-arith[: (:AExp2:) :]) ]|
to-funcons:
  |[ eval-arith[: (:AExp1:)/(:AExp2:) :] ]| ->
  |[ checked integer-divide (eval-arith[: (:AExp1:) :], 
                    eval-arith[: (:AExp2:) :]) ]|
to-funcons:
  |[ eval-arith[: ((:AExp:)) :] ]| ->
  |[ eval-arith[: (:AExp:) :] ]|
to-funcons-lex: 
  FCTDoubleQuoted(L-decimal(LEX-decimal(str))) -> 
  FCTString(<double-quote> str)
to-funcons:
  |[ int-val[: (:D:) :] ]| ->
  |[ decimal-natural (\"(:D:)\") ]|
to-funcons:
  |[ int-val[: -(:D:) :] ]| ->
  |[ integer-negate (int-val[: (:D:) :]) ]|
to-funcons-lex: 
  FCTDoubleQuoted(L-id(LEX-id(str))) -> 
  FCTString(<double-quote> str)
to-funcons:
  |[ id[: (:I:) :] ]| ->
  |[ \"(:I:)\" ]|

