Skip to content

Commit

Permalink
readme.md i incr length
Browse files Browse the repository at this point in the history
  • Loading branch information
GaspardIV committed Jan 30, 2023
1 parent dd0917d commit 8adda0a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 58 deletions.
72 changes: 15 additions & 57 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ Jestem zadowolony z GCSE i kodu realizujacego wirtualne metody - były to wyzwan

Nie jestem zadowolony z jakości kodu jaki oddaje - niestety czas naglił i odpuszczałem sobie refaktoryzacje.

W petli for, iterator jest prawostronny - nie jest mozliwe cos takiego:
```
int [][]x;
x = new int[][2];
for (int[] y : x) {
y = new int[3];
}
```
natomiast nastepujacy kod jest w porządku:
```
int [][]x;
x = new int[][2];
x[0]= new int[3];
x[1]= new int[3];
x[0][0]=1; x[0][1]=2; x[0][2]=3;
x[1][0]=4; x[1][1]=5; x[1][2]=6;
for (int[] y : x) {
y[0] = 10;
for (int z : y) {
printInt(z);
}
}
```


Kompliacja kompilatora za pomoca polecenia: `make`

Uzycie: `./latc nazwa_pliku.lat`
Expand Down
19 changes: 18 additions & 1 deletion src/latte/frontend/visitors/StmtChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,18 @@ public Void visit(latte.Absyn.Ass p, Environment arg) {

public Void visit(latte.Absyn.Incr p, Environment arg) {
Type exprType = p.expr_.accept(new ExprChecker(), arg);

if (p.expr_ instanceof EField) {
if (((EField) p.expr_).ident_.equals("length")) {
Type type = ((EField) p.expr_).expr_.accept(new ExprChecker(), arg);
if (type instanceof Array) {
throw new SemanticError.IncrementingNonLValue(p.line_num);
}
}
}

if (!(p.expr_ instanceof EVar) && !(p.expr_ instanceof EField) && !(p.expr_ instanceof EArrayElem) && !(p.expr_ instanceof EArrayElemR)) {
throw new SemanticError.IncrementingNonLValue(p.line_num);

}
if (!exprType.equals(new Int())) {
throw new SemanticError.OperatorCannotBeAppliedToType(p.line_num, "++", exprType);
Expand All @@ -99,6 +108,14 @@ public Void visit(latte.Absyn.Incr p, Environment arg) {

public Void visit(latte.Absyn.Decr p, Environment arg) {
Type exprType = p.expr_.accept(new ExprChecker(), arg);
if (p.expr_ instanceof EField) {
if (((EField) p.expr_).ident_.equals("length")) {
Type type = ((EField) p.expr_).expr_.accept(new ExprChecker(), arg);
if (type instanceof Array) {
throw new SemanticError.DecrementingNonLValue(p.line_num);
}
}
}
if (!(p.expr_ instanceof EVar) && !(p.expr_ instanceof EField) && !(p.expr_ instanceof EArrayElem) && !(p.expr_ instanceof EArrayElemR)) {
throw new SemanticError.DecrementingNonLValue(p.line_num);
}
Expand Down

0 comments on commit 8adda0a

Please sign in to comment.