module IBAF-Statements imports libstratego-gpp signatures/- pp/IBAF-parenthesize pp/IBAF-pp imports cbs-gen/IBAF-Expressions // Language "IBAFlang" rules // # Statements to-funcons: |[ execute[: {(:Stmt*:)} :] ]| -> |[ scope (collateral (collect-declared-vars[: (:Stmt*:) :]), execute[: (:Stmt*:) :]) ]| to-funcons: |[ execute[: print((:Exp:)); :] ]| -> |[ print eval-exp[: (:Exp:) :] ]| to-funcons: |[ execute[: (:Id:); :] ]| -> |[ assign (bound id[: (:Id:) :], 0) ]| to-funcons: |[ execute[: (:Id:)=(:Exp:); :] ]| -> |[ assign (bound id[: (:Id:) :], eval-exp[: (:Exp:) :]) ]| to-funcons: |[ execute[: return(:Exp:); :] ]| -> |[ return eval-exp[: (:Exp:) :] ]| to-funcons: |[ execute[: return; :] ]| -> |[ return null ]| to-funcons: |[ execute[: fun(:Id:)(){(:Stmt*:)} :] ]| -> |[ null ]| to-funcons: |[ execute[: :] ]| -> |[ null ]| to-funcons: |[ execute[: (:Stmt:)(:Stmt+:) :] ]| -> |[ sequential (execute[: (:Stmt:) :], execute[: (:Stmt+:) :]) ]| // # Handling variable declarations to-funcons: |[ collect-declared-vars[: (:Id:)=(:Exp:); :] ]| -> |[ bind (id[: (:Id:) :], allocate-variable (integers)) ]| to-funcons: |[ collect-declared-vars[: (:Id:); :] ]| -> |[ bind (id[: (:Id:) :], allocate-variable (integers)) ]| to-funcons: |[ collect-declared-vars[: fun(:Id:)(){(:Stmt*:)} :] ]| -> |[ bind (id[: (:Id:) :], function abstraction (execute[: {(:Stmt*:)} :])) ]| to-funcons: |[ collect-declared-vars[: :] ]| -> |[ map () ]| to-funcons: |[ collect-declared-vars[: (:Stmt:) :] ]| -> |[ map () ]| to-funcons: |[ collect-declared-vars[: (:Stmt1:)(:Stmt2:)(:Stmt*:) :] ]| -> |[ collect-declared-vars[: (:Stmt1:) :], collect-declared-vars[: (:Stmt2:) :], collect-declared-vars[: (:Stmt*:) :] ]|