blob: c4a44dc44348f149a5905afff87dea6ef5f0a5a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package ast.nodes;
import ast.types.*;
import java.util.ArrayList;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
/**
* Node for the `assignment` statement of the grammar.
*/
public class AssignmentNode implements Node {
private final ExprListNode lhr;
private final Node assign;
private final ExprListNode rhr;
public AssignmentNode(Node lhr, Node assign, Node rhr) {
this.lhr = (ExprListNode) lhr;
this.assign = assign;
this.rhr = (ExprListNode) rhr;
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
ArrayList<SemanticError> errors = new ArrayList<>();
// errors.addAll(lhr.checkSemantics(ST, _nesting));
errors.addAll(assign.checkSemantics(ST, _nesting));
errors.addAll(rhr.checkSemantics(ST, _nesting));
int lsize = lhr.getSize();
// FIXME: unused variable
// int rsize = rhr.getSize();
// if (lsize == rsize) {
for (int i = 0; i < lsize; i++) {
ExprNode latom = (ExprNode) lhr.getElem(i);
ST.insert(latom.getId(), new AtomType(), _nesting, "");
// ExprNode ratom = (ExprNode) rhr.getElem(i);
}
// } else {
// FIX: sgravata da più problemi che altro
// errors.add(new SemanticError("ValueError: different size of left or right side assignment"));
// }
return errors;
}
// TODO: check it out for this type
@Override
public Type typeCheck() {
return rhr.typeCheck();
}
// TODO: add code generation for assignment
@Override
public String codeGeneration() {
return "";
}
@Override
public String toPrint(String prefix) {
return prefix + "Assignment\n" + lhr.toPrint(prefix + " ") + assign.toPrint(prefix + " ")
+ rhr.toPrint(prefix + " ");
}
}
|