Skip to content

Commit 773b442

Browse files
Merge pull request #26 from Jun-Software/development
v1.14.11
2 parents cff82fa + 6ee64d1 commit 773b442

25 files changed

+231
-7
lines changed

src/identifiers/addition.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
* By lemonorangeapple
44
**/
55
void addition(vector<string>::iterator it) {
6+
// Check if the variable is already declared
67
bool undeclared = true;
78
for (int i = 0; i <= variableCount; i++) {
9+
// If the variable is already declared, add the value
810
if (variables[i].name == *(it + 1)) {
11+
// Check if the value is an integer
912
if (isInteger(*(it + 2))) {
13+
// Add the integer value to the variable
1014
variables[i].value += atoi((*(it + 2)).c_str());
1115
undeclared = false;
1216
break;
1317
}
18+
// If the value is not an integer, check if it is a variable
1419
else {
1520
undeclared = true;
1621
for (int j = 0; j <= variableCount; j++) {
22+
// If the variable is already declared, add the value
1723
if (variables[j].name == *(it + 2)) {
1824
variables[i].value += variables[j].value;
1925
undeclared = false;
@@ -23,6 +29,7 @@ void addition(vector<string>::iterator it) {
2329
}
2430
}
2531
}
32+
// If the variable is not declared, throw an error
2633
if (undeclared) {
2734
cerr << "[ERROR] Variable undeclared. " << endl;
2835
}

src/identifiers/division.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,43 @@
33
* By lemonorangeapple
44
**/
55
void division(vector<string>::iterator it) {
6+
// Check if the variable is undeclared
67
bool undeclared = true;
8+
// Loop through the variables
79
for (int i = 0; i <= variableCount; i++) {
10+
// Check if the variable name matches the one in the expression
811
if (variables[i].name == *(it + 1)) {
12+
// Check if the value is an integer
913
if (isInteger(*(it + 2))) {
14+
// Divide the value by the integer
1015
variables[i].value /= atoi((*(it + 2)).c_str());
16+
// Set undeclared to false
1117
undeclared = false;
18+
// Break out of the loop
1219
break;
1320
}
21+
// If the value is not an integer
1422
else {
23+
// Set undeclared to true
1524
undeclared = true;
25+
// Loop through the variables
1626
for (int j = 0; j <= variableCount; j++) {
27+
// Check if the variable name matches the one in the expression
1728
if (variables[j].name == *(it + 2)) {
29+
// Divide the value by the value of the other variable
1830
variables[i].value /= variables[j].value;
31+
// Set undeclared to false
1932
undeclared = false;
33+
// Break out of the loop
2034
break;
2135
}
2236
}
2337
}
2438
}
2539
}
40+
// If the variable is undeclared
2641
if (undeclared) {
42+
// Print an error message
2743
cerr << "[ERROR] Variable undeclared. " << endl;
2844
}
2945
}

src/identifiers/end_if.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* By lemonorangeapple
44
**/
55
void end_if(vector<string>::iterator it) {
6+
// Check if the ifFlag is empty
67
if (!ifFlag.empty()) {
8+
// Pop the last element of ifFlag
79
ifFlag.pop();
810
}
911
else {
12+
// Print an error message if ifFlag is empty
1013
cerr << "[Error] Much \"end-if\"." << endl;
1114
}
1215
}

src/identifiers/end_loop.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@
33
* By lemonorangeapple
44
**/
55
void end_loop(vector<string>::iterator it, ifstream &file) {
6+
// Check if there is loop flag
67
if (!loopFlag.empty()) {
8+
// Check if loop flag is true
79
if (loopFlag.top() == true) {
10+
// Check if loop variable name is correct
811
for (int i = 0; i <= variableCount; i++) {
912
if (variables[i].name == loopVariableName.top()) {
13+
// Check if loop variable value is 0
1014
if (variables[i].value == 0) {
15+
// Pop loop flag
1116
loopFlag.pop();
1217
break;
1318
}
1419
else {
20+
// Check if loop line is empty
1521
if (!loopLine.empty()) {
22+
// Seekg to loop line
1623
file.seekg(int(loopLine.top()) - 2);
1724
}
1825
break;
@@ -21,12 +28,16 @@ void end_loop(vector<string>::iterator it, ifstream &file) {
2128
}
2229
}
2330
else {
31+
// Pop loop flag
2432
loopFlag.pop();
33+
// Pop loop line
2534
loopLine.pop();
35+
// Pop loop variable name
2636
loopVariableName.pop();
2737
}
2838
}
2939
else {
40+
// Print error message
3041
cerr << "[Error] Much \"end-loop\"." << endl;
3142
}
3243
}

src/identifiers/equal.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,41 @@
33
* By lemonorangeapple
44
**/
55
void equal(vector<string>::iterator it) {
6+
// Check if the variable is undeclared
67
bool undeclared = true;
8+
// Loop through the variables
79
for (int i = 0; i <= variableCount; i++) {
10+
// Check if the variable name matches
811
if (variables[i].name == *(it + 1)) {
12+
// Check if the value is an integer
913
if (isInteger(*(it + 2))) {
14+
// Loop through the variables
1015
for (int j = 0; j <= variableCount; j++) {
16+
// Check if the variable name matches
1117
if (variables[j].name == *(it + 3)) {
18+
// Set the undeclared flag to false
1219
undeclared = false;
20+
// Set the value to true if the variable values are equal
1321
variables[j].value = (variables[i].value == atoi((*(it + 2)).c_str()));
1422
break;
1523
}
1624
}
1725
}
26+
// Check if the value is a variable
1827
else {
28+
// Set the undeclared flag to true
1929
undeclared = true;
30+
// Loop through the variables
2031
for (int j = 0; j <= variableCount; j++) {
32+
// Check if the variable name matches
2133
if (variables[j].name == *(it + 2)) {
34+
// Loop through the variables
2235
for (int k = 0; k <= variableCount; k++) {
36+
// Check if the variable name matches
2337
if (variables[k].name == *(it + 3)) {
38+
// Set the undeclared flag to false
2439
undeclared = false;
40+
// Set the value to true if the variable values are equal
2541
variables[k].value = (variables[i].value == variables[j].value);
2642
break;
2743
}
@@ -32,6 +48,7 @@ void equal(vector<string>::iterator it) {
3248
}
3349
}
3450
}
51+
// If the variable is undeclared, print an error message
3552
if (undeclared) {
3653
cerr << "[Error] Variable undeclared." << endl;
3754
}

src/identifiers/equal_or_greater.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,55 @@
33
* By lemonorangeapple
44
**/
55
void equal_or_greater(vector<string>::iterator it) {
6+
// Check if the variable is undeclared
67
bool undeclared = true;
8+
// Loop through all the variables
79
for (int i = 0; i <= variableCount; i++) {
10+
// Check if the variable name matches the first argument
811
if (variables[i].name == *(it + 1)) {
12+
// Check if the second argument is an integer
913
if (isInteger(*(it + 2))) {
14+
// Loop through all the variables
1015
for (int j = 0; j <= variableCount; j++) {
16+
// Check if the variable name matches the third argument
1117
if (variables[j].name == *(it + 3)) {
18+
// Set the undeclared flag to false
1219
undeclared = false;
20+
// Set the value of the third argument to the value of the first argument
1321
variables[j].value = (variables[i].value >= atoi((*(it + 2)).c_str()));
22+
// Break out of the loop
1423
break;
1524
}
1625
}
1726
}
27+
// Check if the second argument is a variable
1828
else {
29+
// Set the undeclared flag to true
1930
undeclared = true;
31+
// Loop through all the variables
2032
for (int j = 0; j <= variableCount; j++) {
33+
// Check if the variable name matches the second argument
2134
if (variables[j].name == *(it + 2)) {
35+
// Loop through all the variables
2236
for (int k = 0; k <= variableCount; k++) {
37+
// Check if the variable name matches the third argument
2338
if (variables[k].name == *(it + 3)) {
39+
// Set the undeclared flag to false
2440
undeclared = false;
41+
// Set the value of the third argument to the value of the first argument
2542
variables[k].value = (variables[i].value >= variables[j].value);
43+
// Break out of the loop
2644
break;
2745
}
2846
}
47+
// Break out of the inner loop
2948
break;
3049
}
3150
}
3251
}
3352
}
3453
}
54+
// If the variable is undeclared, print an error message
3555
if (undeclared) {
3656
cerr << "[Error] Variable undeclared." << endl;
3757
}

src/identifiers/equal_or_less.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,59 @@
33
* By lemonorangeapple
44
**/
55
void equal_or_less(vector<string>::iterator it) {
6+
// Check if the variable is undeclared
67
bool undeclared = true;
8+
// Loop through the variables
79
for (int i = 0; i <= variableCount; i++) {
10+
// Check if the variable name matches
811
if (variables[i].name == *(it + 1)) {
12+
// Check if the second argument is an integer
913
if (isInteger(*(it + 2))) {
14+
// Loop through the variables
1015
for (int j = 0; j <= variableCount; j++) {
16+
// Check if the third argument matches
1117
if (variables[j].name == *(it + 3)) {
18+
// Set the undeclared flag to false
1219
undeclared = false;
20+
// Set the value of the third argument to the comparison of the first and second arguments
1321
variables[j].value = (variables[i].value <= atoi((*(it + 2)).c_str()));
22+
// Break out of the loop
1423
break;
1524
}
1625
}
26+
// Break out of the loop
1727
break;
1828
}
29+
// If the second argument is not an integer
1930
else {
31+
// Set the undeclared flag to true
2032
undeclared = true;
33+
// Loop through the variables
2134
for (int j = 0; j <= variableCount; j++) {
35+
// Check if the second argument matches
2236
if (variables[j].name == *(it + 2)) {
37+
// Loop through the variables
2338
for (int k = 0; k <= variableCount; k++) {
39+
// Check if the third argument matches
2440
if (variables[k].name == *(it + 3)) {
41+
// Set the undeclared flag to false
2542
undeclared = false;
43+
// Set the value of the third argument to the comparison of the first and second arguments
2644
variables[k].value = (variables[i].value <= variables[j].value);
45+
// Break out of the loop
2746
break;
2847
}
2948
}
49+
// Break out of the loop
3050
break;
3151
}
3252
}
3353
}
3454
}
3555
}
56+
// If the variable is undeclared
3657
if (undeclared) {
58+
// Print an error message
3759
cerr << "[Error] Variable undeclared." << endl;
3860
}
3961
}

src/identifiers/greater.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,59 @@
33
* By lemonorangeapple
44
**/
55
void _greater(vector<string>::iterator it) {
6+
// Check if the first variable is undeclared
67
bool undeclared = true;
8+
// Loop through all variables
79
for (int i = 0; i <= variableCount; i++) {
10+
// Check if the first variable is equal to the name of the variable
811
if (variables[i].name == *(it + 1)) {
12+
// Check if the second variable is an integer
913
if (isInteger(*(it + 2))) {
14+
// Loop through all variables
1015
for (int j = 0; j <= variableCount; j++) {
16+
// Check if the second variable is equal to the name of the variable
1117
if (variables[j].name == *(it + 3)) {
18+
// Set undeclared to false
1219
undeclared = false;
20+
// Set the value of the second variable to the greater of the first and the second
1321
variables[j].value = (variables[i].value > atoi((*(it + 2)).c_str()));
22+
// Break out of the loop
1423
break;
1524
}
1625
}
26+
// Break out of the loop
1727
break;
1828
}
29+
// If the second variable is not an integer
1930
else {
31+
// Set undeclared to true
2032
undeclared = true;
33+
// Loop through all variables
2134
for (int j = 0; j <= variableCount; j++) {
35+
// Check if the second variable is equal to the name of the variable
2236
if (variables[j].name == *(it + 2)) {
37+
// Loop through all variables
2338
for (int k = 0; k <= variableCount; k++) {
39+
// Check if the third variable is equal to the name of the variable
2440
if (variables[k].name == *(it + 3)) {
41+
// Set undeclared to false
2542
undeclared = false;
43+
// Set the value of the third variable to the greater of the first and the third
2644
variables[k].value = (variables[i].value > variables[j].value);
45+
// Break out of the loop
2746
break;
2847
}
2948
}
49+
// Break out of the loop
3050
break;
3151
}
3252
}
3353
}
3454
}
3555
}
56+
// If the first variable is undeclared
3657
if (undeclared) {
58+
// Print an error message
3759
cerr << "[Error] Variable undeclared." << endl;
3860
}
3961
}

0 commit comments

Comments
 (0)