module IBAF-Expressions

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

imports
  

// Language "IBAFlang"

rules

// # 1: General expressions
                 

to-funcons:
  |[ eval-exp[: (:Id:) :] ]| ->
  |[ assigned (bound (id[: (:Id:) :])) ]|
to-funcons:
  |[ eval-exp[: (:Int:) :] ]| ->
  |[ int-val[: (:Int:) :] ]|
to-funcons:
  |[ eval-exp[: true :] ]| ->
  |[ true ]|
to-funcons:
  |[ eval-exp[: false :] ]| ->
  |[ false ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)+(:Exp2:) :] ]| ->
  |[ int-add (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)-(:Exp2:) :] ]| ->
  |[ int-sub (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)*(:Exp2:) :] ]| ->
  |[ int-mul (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)/(:Exp2:) :] ]| ->
  |[ checked int-div (eval-exp[: (:Exp1:) :], 
                    eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)%(:Exp2:) :] ]| ->
  |[ checked int-mod (eval-exp[: (:Exp1:) :], 
                    eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)&&(:Exp2:) :] ]| ->
  |[ and (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)||(:Exp2:) :] ]| ->
  |[ and (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)==(:Exp2:) :] ]| ->
  |[ is-equal (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)>=(:Exp2:) :] ]| ->
  |[ is-greater-or-equal (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)>(:Exp2:) :] ]| ->
  |[ is-greater (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)<=(:Exp2:) :] ]| ->
  |[ is-less-or-equal (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: (:Exp1:)<(:Exp2:) :] ]| ->
  |[ is-less (eval-exp[: (:Exp1:) :], 
             eval-exp[: (:Exp2:) :]) ]|
to-funcons:
  |[ eval-exp[: ((:Exp:)) :] ]| ->
  |[ eval-exp[: (:Exp:) :] ]|
to-funcons-lex: 
  FCTDoubleQuoted(L-id(LEX-id(str))) -> 
  FCTString(<double-quote> str)
to-funcons:
  |[ id[: (:Id:) :] ]| ->
  |[ \"(:Id:)\" ]|
to-funcons:
  |[ int-val[: (:Dec:) :] ]| ->
  |[ dec-val[: (:Dec:) :] ]|
to-funcons:
  |[ int-val[: -(:Dec:) :] ]| ->
  |[ integer-negate (dec-val[: (:Dec:) :]) ]|
to-funcons-lex: 
  FCTDoubleQuoted(L-decimal(LEX-decimal(str))) -> 
  FCTString(<double-quote> str)
to-funcons:
  |[ dec-val[: (:Dec:) :] ]| ->
  |[ decimal-natural (\"(:Dec:)\") ]|

