voor de initialise-variable verandering
This commit is contained in:
@@ -3,10 +3,14 @@ Language "IBAFlang"
|
||||
# 1: General expressions
|
||||
Syntax Exp:exp ::= id
|
||||
| int
|
||||
| 'true'
|
||||
| 'false'
|
||||
| exp '+' exp
|
||||
| exp '-' exp
|
||||
| exp '<=' exp
|
||||
| exp '<' exp
|
||||
| id '(' paramvalues? ')'
|
||||
| '(' exp ')'
|
||||
| 'true'
|
||||
| 'false'
|
||||
| exp '*' exp
|
||||
| exp '/' exp
|
||||
| exp '%' exp
|
||||
@@ -15,10 +19,6 @@ Syntax Exp:exp ::= id
|
||||
| exp '==' exp
|
||||
| exp '>=' exp
|
||||
| exp '>' exp
|
||||
| exp '<=' exp
|
||||
| exp '<' exp
|
||||
| id '(' paramvalues? ')'
|
||||
| '(' exp ')'
|
||||
|
||||
Syntax ParamValues: paramvalues ::= exp (',' paramvalues)?
|
||||
|
||||
@@ -33,7 +33,7 @@ Rule eval-exp[[ Exp1 '*' Exp2 ]] = int-mul(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]
|
||||
Rule eval-exp[[ Exp1 '/' Exp2 ]] = checked int-div(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '%' Exp2 ]] = checked int-mod(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '&&' Exp2 ]] = and(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '||' Exp2 ]] = and(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '||' Exp2 ]] = or(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '==' Exp2 ]] = is-equal(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
Rule eval-exp[[ Exp1 '>=' Exp2 ]] = is-greater-or-equal(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
Rule eval-exp[[ Exp1 '>' Exp2 ]] = is-greater(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
@@ -43,7 +43,7 @@ Rule eval-exp[[ Id '(' ParamValues? ')' ]] = handle-return apply(bound id[[ Id ]
|
||||
Rule eval-exp[[ '(' Exp ')' ]] = eval-exp[[ Exp ]]
|
||||
|
||||
Semantics eval-params[[ _:paramvalues? ]] : lists(values)
|
||||
Rule eval-params[[ ]] = []
|
||||
Rule eval-params[[ ]] = list()
|
||||
Rule eval-params[[ Exp ]] = list(eval-exp[[ Exp ]])
|
||||
Rule eval-params[[ Exp ',' ParamValues ]] = cons(eval-exp[[ Exp ]], eval-params[[ ParamValues ]])
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//Funcon increment(Id:ids) : => values
|
||||
// ~> assign(bound(\"Id\"), int-add(assigned(bound(\"Id\")), 1))
|
||||
Funcon increment(Id:ids) : => values
|
||||
~> assign(bound(\"Id\"), int-add(assigned(bound(\"Id\")), 1))
|
||||
|
||||
Funcon
|
||||
print-line(S:strings) : => null-type
|
||||
|
||||
@@ -2,6 +2,8 @@ Language "IBAFlang"
|
||||
|
||||
# Statements
|
||||
|
||||
Syntax Block: block ::= '{' statement* '}'
|
||||
|
||||
Syntax Stmt: statement ::= block
|
||||
| 'print' '(' exp ')' ';'
|
||||
| 'int' id ';'
|
||||
@@ -13,7 +15,6 @@ Syntax Stmt: statement ::= block
|
||||
| 'while' '(' exp ')' block
|
||||
| 'for' '(' 'int' id '=' exp ';' exp ')' block
|
||||
|
||||
Syntax Block: block ::= '{' statement* '}'
|
||||
|
||||
Syntax Params: params ::= id (',' params)?
|
||||
|
||||
@@ -32,8 +33,7 @@ Rule execute[[ 'if' '(' Exp ')' Block1 'else' Block2 ]] = if-else(eval-exp[[ Exp
|
||||
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 ]]))))
|
||||
while(eval-exp[[ Exp2 ]], sequential(execute-block[[ Block ]], assign(bound id[[ Id ]], int-add(1, assigned bound id[[ Id ]]))))
|
||||
)
|
||||
|
||||
Rule execute[[ ]] = null
|
||||
@@ -44,6 +44,8 @@ Rule execute-block[[ '{' Stmt* '}' ]] = scope(collateral(collect-declared-vars[[
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Handling parameter declarations
|
||||
|
||||
Semantics collect-params[[ Params:params ]] : (=>environments)+
|
||||
@@ -69,6 +71,7 @@ Rule collect-declared-vars[[ 'fun' Id '(' Params ')' '{' Stmt* '}' ]] = bind(id[
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
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* ]]
|
||||
|
||||
Reference in New Issue
Block a user