all will be int
This commit is contained in:
@@ -35,10 +35,8 @@ context-free syntax // Language
|
||||
"{" L-statement* "}"
|
||||
L-statement.L-statement--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
||||
"print" "(" L-exp ")" ";"
|
||||
L-statement.L-statement--L-type-L-id-SEMI =
|
||||
L-type L-id ";"
|
||||
L-statement.L-statement--L-type-L-id-EQUALS-L-exp-SEMI =
|
||||
L-type L-id "=" L-exp ";"
|
||||
L-statement.L-statement--L-id-SEMI =
|
||||
L-id ";"
|
||||
L-statement.L-statement--L-id-EQUALS-L-exp-SEMI =
|
||||
L-id "=" L-exp ";"
|
||||
L-statement.L-statement--R-return-L-exp-Q-SEMI =
|
||||
@@ -46,13 +44,6 @@ context-free syntax // Language
|
||||
L-statement.L-statement--R-fun-L-id-LPAREN-RPAREN-LBRACE-L-statement-S-RBRACE =
|
||||
"fun" L-id "(" ")" "{" L-statement* "}"
|
||||
|
||||
L-type.L-type--R-int =
|
||||
"int"
|
||||
L-type.L-type--R-bool =
|
||||
"bool"
|
||||
L-type.L-type--L-id =
|
||||
L-id
|
||||
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
@@ -93,10 +84,6 @@ variables // Meta-variables
|
||||
L-statement+ = "(:Stmt" [1-9]? "+:)" {prefer}
|
||||
L-statement* = "..." [1-9]? {prefer}
|
||||
L-statement* = "..." [1-9]? {prefer}
|
||||
L-type = "(:Typ" [1-9]? ":)" {prefer}
|
||||
L-type? = "(:Typ" [1-9]? "?:)" {prefer}
|
||||
L-type* = "(:Typ" [1-9]? "*:)" {prefer}
|
||||
L-type+ = "(:Typ" [1-9]? "+:)" {prefer}
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -24,12 +24,9 @@ to-funcons:
|
||||
|[ execute[: print((:Exp:)); :] ]| ->
|
||||
|[ print eval-exp[: (:Exp:) :] ]|
|
||||
to-funcons:
|
||||
|[ execute[: (:Typ:)(:Id:); :] ]| ->
|
||||
|[ null ]|
|
||||
to-funcons:
|
||||
|[ execute[: (:Typ:)(:Id:)=(:Exp:); :] ]| ->
|
||||
|[ execute[: (:Id:); :] ]| ->
|
||||
|[ assign (bound id[: (:Id:) :],
|
||||
eval-exp[: (:Exp:) :]) ]|
|
||||
0) ]|
|
||||
to-funcons:
|
||||
|[ execute[: (:Id:)=(:Exp:); :] ]| ->
|
||||
|[ assign (bound id[: (:Id:) :],
|
||||
@@ -55,18 +52,16 @@ to-funcons:
|
||||
|
||||
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: (:Typ:)(:Id:)=(:Exp:); :] ]| ->
|
||||
|[ bind (\"(:Id:)\",
|
||||
allocate-initialised-variable (integers,
|
||||
0)) ]|
|
||||
|[ collect-declared-vars[: (:Id:)=(:Exp:); :] ]| ->
|
||||
|[ bind (id[: (:Id:) :],
|
||||
allocate-variable (integers)) ]|
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: (:Typ:)(:Id:); :] ]| ->
|
||||
|[ bind (\"(:Id:)\",
|
||||
allocate-initialised-variable (integers,
|
||||
0)) ]|
|
||||
|[ collect-declared-vars[: (:Id:); :] ]| ->
|
||||
|[ bind (id[: (:Id:) :],
|
||||
allocate-variable (integers)) ]|
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: fun(:Id:)(){(:Stmt*:)} :] ]| ->
|
||||
|[ bind (\"(:Id:)\",
|
||||
|[ bind (id[: (:Id:) :],
|
||||
function abstraction (execute[: {(:Stmt*:)} :])) ]|
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: :] ]| ->
|
||||
|
||||
@@ -4,6 +4,6 @@ fun test() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
int x = test();
|
||||
x = test();
|
||||
|
||||
print(x);
|
||||
@@ -1,13 +1,13 @@
|
||||
|
||||
int z =5;
|
||||
int x =5*3;
|
||||
z =5;
|
||||
x =5*3;
|
||||
print(x);
|
||||
|
||||
x = 2;
|
||||
print(x*3);
|
||||
|
||||
{
|
||||
int y =4;
|
||||
y =4;
|
||||
print (y);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ Rule eval-exp[[ '(' Exp ')' ]] = eval-exp[[ Exp ]]
|
||||
|
||||
Lexis Id:id ::= ('a'-'z' | 'A'-'Z') ('a'-'z' | 'A'-'Z' | '0'-'9')*
|
||||
|
||||
Semantics id[[ _:id ]] : ids
|
||||
Semantics id[[ _:id ]] : identifiers
|
||||
Rule id[[ Id ]] = \"Id\"
|
||||
|
||||
|
||||
|
||||
@@ -4,23 +4,16 @@ Language "IBAFlang"
|
||||
|
||||
Syntax Stmt: statement ::= '{' statement* '}'
|
||||
| 'print' '(' exp ')' ';'
|
||||
| type id ';'
|
||||
| type id '=' exp ';'
|
||||
| id ';'
|
||||
| id '=' exp ';'
|
||||
| 'return' exp? ';'
|
||||
| 'fun' id '(' ')' '{' statement* '}'
|
||||
|
||||
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 ';' ]] = assign(bound id[[ Id ]], 0)
|
||||
Rule execute[[ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
||||
Rule execute[[ 'return' Exp ';' ]] = return eval-exp[[ Exp ]]
|
||||
Rule execute[[ 'return' ';' ]] = return null
|
||||
@@ -36,25 +29,13 @@ Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
||||
|
||||
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[[ Id '=' Exp ';' ]] = bind(id[[ Id ]],
|
||||
allocate-variable(integers)
|
||||
)
|
||||
Rule collect-declared-vars[[ Id ';' ]] = bind(id[[ Id ]],
|
||||
allocate-variable(integers)
|
||||
)
|
||||
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[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] =
|
||||
bind(
|
||||
\"Id\",
|
||||
Rule collect-declared-vars[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] = bind(id[[ Id ]],
|
||||
function abstraction(execute[[ '{' Stmt* '}' ]])
|
||||
)
|
||||
Rule collect-declared-vars[[ ]] = map()
|
||||
|
||||
Reference in New Issue
Block a user