Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit ef6de65

Browse files
committed
All working before-exam
1 parent 266a23e commit ef6de65

18 files changed

+1082
-906
lines changed

comment.txt

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,8 @@
1-
# lalallaal
21
def main(): void {
3-
}
4-
5-
i, j, n: int;
6-
c: char;
7-
c: [2]char;
8-
9-
def p(): void { }
10-
11-
def a(): int {
12-
(int) j;
13-
(int) 4;
14-
(int) .023;
15-
p();
16-
c.people.age;
17-
a = b;
18-
a = (4+2) / 3;
2+
#Integer
3+
a:int;
194

20-
if a > b : {
21-
b+1;
22-
a-1;
23-
}
24-
else
25-
c-1;
26-
27-
if a > b : {
28-
b+1;
29-
a-1;
30-
}
31-
else {
32-
c-1;
33-
c+1;
34-
}
35-
36-
while i<10 : {
37-
while j<5 : {
38-
vector[i][j] = i + j;
39-
j=j+1;
40-
}
41-
i=i+1;
42-
}
43-
44-
return (int) .023;
45-
}
46-
47-
a : struct {
48-
c: char;
49-
i: [2]int;
50-
51-
b : struct {
52-
d: double;
53-
}
54-
}
55-
def main(): void {
5+
#Advandec type
6+
a.b = 4;
7+
a.b.c.d.e.f = 3;
568
}

exam-input.txt

Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,90 @@
1-
# Variable and function definitions
2-
i, j, n: int;
3-
c: char;
1+
"""
2+
Control Test
3+
PLD 17/18
4+
"""
45

5-
# Empty function
6-
def p(): void { }
6+
# Global variables
7+
integer:int;
8+
character:char;
9+
real:double;
710

8-
def f(n: int,r: double): int {
9-
real: double;
10-
c1, c2: char;
11-
c1 = (char)n;
12-
real = c1 + n + r;
13-
p(); # Invocation as a statement
14-
return (int)c1;
15-
}
11+
MATRIXSIZE:int;
12+
matrix:[10][10]int;
1613

17-
def main(): void {
18-
# Record
19-
pair: struct {
20-
integer: int;
21-
character: char;
22-
};
23-
24-
# Array
25-
vector: [10][5]double;
26-
27-
i=0;
28-
j=0;
29-
while i<10 : {
30-
while j<5 : {
31-
vector[i][j] = i + j;
32-
j=j+1;
14+
# Functions
15+
def setValue(row:int, columnn:int, value:int):void {
16+
if row >= 0 && row < MATRIXSIZE && columnn >= 0 && columnn < MATRIXSIZE: {
17+
matrix[row][column] = value;
18+
}
19+
}
20+
def getValue(row:int, columnn:int):int {
21+
if (row < 0 || row >= MATRIXSIZE) || (columnn < 0 && columnn >= MATRIXSIZE): {
22+
return -1;
23+
}
24+
else {
25+
return matrix[row][column];
26+
}
27+
}
28+
def fill(value:int):void {
29+
i,j:int; # Multiple variable definition
30+
i = 0;
31+
while i < MATRIXSIZE: {
32+
j = 0;
33+
while j < MATRIXSIZE: {
34+
setValue(i,j, value);
35+
j = j + 1;
36+
}
37+
i = i + 1;
38+
}
39+
}
40+
def show():void {
41+
i,j:int;
42+
i = 0;
43+
print '[','\n';
44+
while i < MATRIXSIZE: {
45+
j = 0;
46+
print '\t','[';
47+
while j < MATRIXSIZE: {
48+
print getValue(i,j);
49+
if j != MATRIXSIZE - 1: {
50+
print ',';
51+
}
52+
j = j + 1;
3353
}
34-
i=i+1;
35-
}
36-
37-
i=0;
38-
pair.character = '0';
39-
pair.integer = '0';
40-
while pair.integer >= i: {
41-
if pair.integer == vector[0][0] || !pair.character || i%2==0 :
42-
print 't', 'r', 'u', 'e', '\n';
43-
else
44-
print 'f', 'a', 'l', 's', 'e', '\n';
45-
i=i+1;
46-
}
47-
print f(i, (double)i); # Invocation as an expression
48-
vector[9][(int)4.3] = 5.6;
49-
f(1, 2.2); # Invocation as a statement
50-
}
54+
print ']','\n';
55+
i = i + 1;
56+
}
57+
print ']';
58+
}
59+
60+
# Record
61+
date:struct {
62+
day, mounth, year:int;
63+
};
64+
65+
# Main program
66+
# def no_main ():void{ # Uncomment to test
67+
def main():void { # Uncomment to test
68+
characters:[1][2][3]char;
69+
MATRIXSIZE = 10;
70+
fill(1);
71+
setValue(5,5,5);
72+
integer = getValue(5,5);
73+
if integer == 5: { # Uncomment { to test
74+
print 'O','k','\n';
75+
}
76+
else {
77+
print 'E','r','r','o','r','\n';
78+
}
79+
show();
80+
81+
date.day = 9;
82+
date.mounth = 3;
83+
date.year = 2016;
84+
85+
character = (char)date.day;
86+
real = 4.5 + 4. * 3e+3 - 5.4E-3;
87+
88+
#error:int; # Uncomment to test
89+
}
90+
# def no_function():void {} # Uncomment to test

small-input.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Variable and function definitions
2-
i, j, n: int;
3-
c:char;
4-
z:int;
5-
d:double;
6-
def main():void {}
1+
def main():void {
2+
a.b = 4;
3+
}

src/ast/Assignment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Assignment implements Statement {
3333
* @param right
3434
* side of the assignment.
3535
*/
36-
public Assignment(int line, int column, Variable left, Arithmetic right) {
36+
public Assignment(int line, int column, Expression left, Expression right) {
3737
this.line = line;
3838
this.column = column;
3939
this.left = left;

src/ast/Comparison.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ast;
22

3-
public class Comparison implements Expression {
3+
public class Comparison implements Expression, Statement {
44

55
private int row = ASTNode.DEFAULT_ROW_COLUMN, column = ASTNode.DEFAULT_ROW_COLUMN;
66

src/ast/IfStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String toString() {
6060
ifStatement.append("\n \t" + statement.toString());
6161
}
6262

63-
if (!elseBody.isEmpty()) {
63+
if (elseBody!=null && !elseBody.isEmpty()) {
6464
ifStatement.append("\n else :");
6565
for (Statement statement : this.getElseBody()) {
6666
ifStatement.append("\n \t" + statement.toString());

src/ast/Logical.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ast;
22

3-
public class Logical implements Expression {
3+
public class Logical implements Expression, Statement {
44

55
private int row = ASTNode.DEFAULT_ROW_COLUMN, column = ASTNode.DEFAULT_ROW_COLUMN;
66

src/ast/Read.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class Read implements Statement {
2727
* where the read statement is.
2828
* @param column
2929
* where the read statement is.
30-
* @param variable
30+
* @param expression
3131
* to read.
3232
*/
33-
public Read(int line, int column, Variable variable) {
33+
public Read(int line, int column, Expression expression) {
3434
this.line = line;
3535
this.column = column;
36-
this.expression = variable;
36+
this.expression = expression;
3737
}
3838

3939
@Override

src/ast/UnaryMinus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class UnaryMinus implements Expression {
3030
* @param variable
3131
* to apply the unary minus
3232
*/
33-
public UnaryMinus(int line, int column, Variable variable) {
33+
public UnaryMinus(int line, int column, Expression variable) {
3434
this.line = line;
3535
this.column = column;
3636
this.expression = variable;

src/ast/Variable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class Variable implements Expression {
2727
* where the variable is.
2828
* @param column
2929
* where the variable is.
30-
* @param string
30+
* @param name
3131
* that represents the lexeme of the variable.
3232
*/
33-
public Variable(int line, int column, String string) {
33+
public Variable(int line, int column, String name) {
3434
this.line = line;
3535
this.column = column;
36-
this.name = string;
36+
this.name = name;
3737
}
3838

3939
@Override

0 commit comments

Comments
 (0)