control flow
This commit is contained in:
@@ -57,7 +57,7 @@ Rule id[[ Id ]] = \"Id\"
|
||||
Syntax Int:int ::= '0' | ('-'?_decimal)
|
||||
|
||||
Semantics int-val[[ _:int ]] : ints
|
||||
Rule int-val[[ '0' ]] = decimal-natural(\"0\")
|
||||
Rule int-val[[ '0' ]] = 0
|
||||
Rule int-val[[ Dec ]] = dec-val[[ Dec ]]
|
||||
Rule int-val[[ '-' Dec ]] = integer-negate(dec-val[[ Dec ]])
|
||||
|
||||
|
||||
6
IBAF-cbs/IBAF/IBAF-Start/IBAF-Funcons.cbs
Normal file
6
IBAF-cbs/IBAF/IBAF-Start/IBAF-Funcons.cbs
Normal file
@@ -0,0 +1,6 @@
|
||||
//Funcon increment(Id:ids) : => values
|
||||
// ~> assign(bound(\"Id\"), int-add(assigned(bound(\"Id\")), 1))
|
||||
|
||||
Funcon
|
||||
print-line(S:strings) : => null-type
|
||||
~> print(S, "\n")
|
||||
@@ -9,6 +9,9 @@ Syntax Stmt: statement ::= block
|
||||
| 'int' id '=' exp ';'
|
||||
| 'return' exp? ';'
|
||||
| 'fun' id '(' params ')' block
|
||||
| 'if' '(' exp ')' block ('else' block)?
|
||||
| 'while' '(' exp ')' block
|
||||
| 'for' '(' 'int' id '=' exp ';' exp ')' block
|
||||
|
||||
Syntax Block: block ::= '{' statement* '}'
|
||||
|
||||
@@ -24,6 +27,14 @@ Rule execute[[ 'int' Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp
|
||||
Rule execute[[ 'return' Exp ';' ]] = return eval-exp[[ Exp ]]
|
||||
Rule execute[[ 'return' ';' ]] = return null
|
||||
Rule execute[[ 'fun' Id '(' Params ')' Block ]] = null
|
||||
Rule execute[[ 'if' '(' Exp ')' Block ]] = if-else(eval-exp[[ Exp ]], execute-block[[ Block ]], null)
|
||||
Rule execute[[ 'if' '(' Exp ')' Block1 'else' Block2 ]] = if-else(eval-exp[[ Exp ]], execute-block[[ Block1 ]], execute-block[[ Block2 ]])
|
||||
Rule execute[[ 'while' '(' Exp ')' Block ]] = while(eval-exp[[ Exp ]], execute-block[[ Block ]])
|
||||
Rule execute[[ 'for' '(' 'int' Id '=' Exp1 ';' Exp2 ')' Block ]] = scope(
|
||||
bind(id[[ Id ]], allocate-initialised-variable(integers, eval-exp[[ Exp1 ]])),
|
||||
// while(eval-exp[[ Exp2 ]], sequential(execute-block[[ Block ]], increment Id))
|
||||
while(eval-exp[[ Exp2 ]], sequential(execute-block[[ Block ]], assign(bound id[[ Id ]], int-add(1,assigned bound id[[ Id ]]))))
|
||||
)
|
||||
|
||||
Rule execute[[ ]] = null
|
||||
Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
||||
@@ -42,6 +53,8 @@ Rule collect-params[[ Id ]] = bind(
|
||||
)
|
||||
Rule collect-params[[ Id ',' Params ]] = collect-params[[ Id ]], give(checked tail given, collect-params[[ Params ]])
|
||||
|
||||
|
||||
|
||||
# Handling variable declarations
|
||||
|
||||
Semantics collect-declared-vars[[ Stmt*:statement* ]] : (=>environments)+
|
||||
|
||||
Reference in New Issue
Block a user