8000 Typing: add check type of Assign expression · compiler-experts/miniJava@94f8475 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94f8475

Browse files
committed
Typing: add check type of Assign expression
1 parent 2c390af commit 94f8475

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

phase2/Main/Compile.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ let execute lexbuf verbose =
55
let ast = compilationUnit Lexer.token lexbuf in
66
print_endline "successfull parsing";
77

8-
(*if verbose then AST.print_program ast;
8+
if verbose then AST.print_program ast;
99
print_endline "===================";
1010
Typing.typing ast;
1111
if verbose then AST.print_program ast;
12-
print_endline "successfull typing";*)
12+
print_endline "successfull typing";
1313
Compilation.compileAST ast;
1414
print_endline "compile successfull";
1515

phase2/Typing/Typing.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ let rec verify_expression env current_env e =
180180
e.etype <- verify_name s env current_env
181181
| ArrayInit el -> () (*TODO*)
182182
| Array (e,el) -> () (*TODO*)
183-
| AssignExp (e1,op,e2) -> () (*TODO*)
183+
| AssignExp (e1,op,e2) ->
184+
verify_expression env current_env e1;
185+
verify_expression env current_env e2;
186+
verify_assignop_type e1.etype e2.etype;
187+
e.etype <- e1.etype
184188
| Post (e,op) -> () (*TODO*)
185189
| Pre (op,e) -> () (*TODO*)
186190
| Op (e1,op,e2) ->

phase2/tests/test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public I(int e) {
1414
String mystring2 = func1(i);
1515
private String func1 (int a) {
1616
int b = 1;
17+
b += (5+4);
1718
return "YES";
1819
}
1920

0 commit comments

Comments
 (0)
0