Files
IBAFLang/IBAF-cbs/IBAF/IBAF-Start/IBAF-Statements.cbs
2023-11-18 11:18:25 +01:00

65 lines
1.6 KiB
Plaintext

Language "IBAFlang"
# Statements
Syntax Stmt: statement ::= '{' statement* '}'
| 'print' '(' exp ')' ';'
| type id ';'
| type id '=' exp ';'
| id '=' exp ';'
Syntax Typ:type ::= 'int'
| 'bool'
| id
Semantics execute[[ Stmt*:statement* ]] : => null-type
Rule execute[[ '{' Stmt* '}' ]] = scope(collateral collect-declared-vars[[ Stmt* ]], execute[[ Stmt* ]])
Rule execute[[ 'print' '(' Exp ')' ';' ]] = print eval-exp[[ Exp ]]
Rule execute[[ Typ Id ';' ]] = null
Rule execute[[ Typ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
Rule execute[[ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
Rule execute[[ ]] = null
Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
# Handling variable declarations
Semantics collect-declared-vars[[ Stmt*:statement* ]] : (=>environments)+
Rule collect-declared-vars[[ Typ Id '=' Exp ';' ]] =
bind(
\"Id\",
allocate-initialised-variable(
integers, //TODO: use type
0 //TODO: use correct default value for type
)
)
Rule collect-declared-vars[[ Typ Id ';' ]] =
bind(
\"Id\",
allocate-initialised-variable(
integers, //TODO: use type
0 //TODO: use correct default value for type
)
)
Rule collect-declared-vars[[ ]] = map()
Rule collect-declared-vars[[ Stmt ]] = map()
Rule collect-declared-vars[[ Stmt1 Stmt2 Stmt* ]] = collect-declared-vars[[ Stmt1 ]], collect-declared-vars[[ Stmt2 ]], collect-declared-vars[[ Stmt* ]]