Skip to content

Commit 045892b

Browse files
Merge pull request #31 from Jun-Software/master
pull
2 parents d89d0b4 + 8912ae9 commit 045892b

28 files changed

+175
-555
lines changed

.github/workflows/c-cpp.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ jobs:
2020
run: make
2121
- name: run
2222
run: ./JunLang
23+
- uses: actions/upload-artifact@v4
24+
with:
25+
name: JunLang
26+
path: ./JunLang

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
build
22
.idea
3-
cmake-build-debug
3+
cmake-build-debug

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# JunLang
2+
[![C/C++ CI](https://github.com/Jun-Software/JunLang/actions/workflows/c-cpp.yml/badge.svg)](https://github.com/Jun-Software/JunLang/actions/workflows/c-cpp.yml)
23

34
[中文版](https://github.com/Jun-Software/JunLang/blob/master/README-zh.md)
45

src/identifiers/addition.hpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,12 @@
33
* By lemonorangeapple
44
**/
55
void addition(vector<string>::iterator it, ifstream &file) {
6-
// Check if the variable is already declared
7-
bool undeclared = true;
8-
for (int i = 0; i <= variableCount; i++) {
9-
// If the variable is already declared, add the value
10-
if (variables[i].name == *(it + 1)) {
11-
// Check if the value is an integer
12-
if (isInteger(*(it + 2))) {
13-
// Add the integer value to the variable
14-
variables[i].value += atoi((*(it + 2)).c_str());
15-
undeclared = false;
16-
break;
17-
}
18-
// If the value is not an integer, check if it is a variable
19-
else {
20-
undeclared = true;
21-
for (int j = 0; j <= variableCount; j++) {
22-
// If the variable is already declared, add the value
23-
if (variables[j].name == *(it + 2)) {
24-
variables[i].value += variables[j].value;
25-
undeclared = false;
26-
break;
27-
}
28-
}
29-
}
30-
}
6+
string next = *(it + 2);
7+
string _this = *(it + 1);
8+
if (isInteger(next)) {
9+
variables[_this] += atoi((next).c_str());
3110
}
32-
// If the variable is not declared, throw an error
33-
if (undeclared) {
34-
cerr << "[ERROR] Variable undeclared. " << endl;
11+
else {
12+
variables[_this] += variables[next];
3513
}
3614
}

src/identifiers/division.hpp

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,12 @@
33
* By lemonorangeapple
44
**/
55
void division(vector<string>::iterator it, ifstream &file) {
6-
// Check if the variable is undeclared
7-
bool undeclared = true;
8-
// Loop through the variables
9-
for (int i = 0; i <= variableCount; i++) {
10-
// Check if the variable name matches the one in the expression
11-
if (variables[i].name == *(it + 1)) {
12-
// Check if the value is an integer
13-
if (isInteger(*(it + 2))) {
14-
// Divide the value by the integer
15-
variables[i].value /= atoi((*(it + 2)).c_str());
16-
// Set undeclared to false
17-
undeclared = false;
18-
// Break out of the loop
19-
break;
20-
}
21-
// If the value is not an integer
22-
else {
23-
// Set undeclared to true
24-
undeclared = true;
25-
// Loop through the variables
26-
for (int j = 0; j <= variableCount; j++) {
27-
// Check if the variable name matches the one in the expression
28-
if (variables[j].name == *(it + 2)) {
29-
// Divide the value by the value of the other variable
30-
variables[i].value /= variables[j].value;
31-
// Set undeclared to false
32-
undeclared = false;
33-
// Break out of the loop
34-
break;
35-
}
36-
}
37-
}
38-
}
6+
string next = *(it + 2);
7+
string _this = *(it + 1);
8+
if (isInteger(next)) {
9+
variables[_this] /= atoi((next).c_str());
3910
}
40-
// If the variable is undeclared
41-
if (undeclared) {
42-
// Print an error message
43-
cerr << "[ERROR] Variable undeclared. " << endl;
11+
else {
12+
variables[_this] /= variables[next];
4413
}
4514
}

src/identifiers/end_loop.hpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,13 @@ void end_loop(vector<string>::iterator it, ifstream &file) {
77
if (!loopFlag.empty()) {
88
// Check if loop flag is true
99
if (loopFlag.top() == true) {
10-
// Check if loop variable name is correct
11-
for (int i = 0; i <= variableCount; i++) {
12-
if (variables[i].name == loopVariableName.top()) {
13-
// Check if loop variable value is 0
14-
if (variables[i].value == 0) {
15-
// Pop loop flag
16-
loopFlag.pop();
17-
break;
18-
}
19-
else {
20-
// Check if loop line is empty
21-
if (!loopLine.empty()) {
22-
// Seekg to loop line
23-
file.seekg(int(loopLine.top()) - 2);
24-
}
25-
break;
26-
}
27-
}
10+
if (variables[loopVariableName.top()] == 0) {
11+
// Pop loop flag
12+
loopFlag.pop();
13+
}
14+
else if (!loopLine.empty()) {
15+
// Seekg to loop line
16+
file.seekg(int(loopLine.top()) - 3);
2817
}
2918
}
3019
else {

src/identifiers/equal.hpp

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,14 @@
33
* By lemonorangeapple
44
**/
55
void equal(vector<string>::iterator it, ifstream &file) {
6-
// Check if the variable is undeclared
7-
bool undeclared = true;
8-
// Loop through the variables
9-
for (int i = 0; i <= variableCount; i++) {
10-
// Check if the variable name matches
11-
if (variables[i].name == *(it + 1)) {
12-
// Check if the value is an integer
13-
if (isInteger(*(it + 2))) {
14-
// Loop through the variables
15-
for (int j = 0; j <= variableCount; j++) {
16-
// Check if the variable name matches
17-
if (variables[j].name == *(it + 3)) {
18-
// Set the undeclared flag to false
19-
undeclared = false;
20-
// Set the value to true if the variable values are equal
21-
variables[j].value = (variables[i].value == atoi((*(it + 2)).c_str()));
22-
break;
23-
}
24-
}
25-
}
26-
// Check if the value is a variable
27-
else {
28-
// Set the undeclared flag to true
29-
undeclared = true;
30-
// Loop through the variables
31-
for (int j = 0; j <= variableCount; j++) {
32-
// Check if the variable name matches
33-
if (variables[j].name == *(it + 2)) {
34-
// Loop through the variables
35-
for (int k = 0; k <= variableCount; k++) {
36-
// Check if the variable name matches
37-
if (variables[k].name == *(it + 3)) {
38-
// Set the undeclared flag to false
39-
undeclared = false;
40-
// Set the value to true if the variable values are equal
41-
variables[k].value = (variables[i].value == variables[j].value);
42-
break;
43-
}
44-
}
45-
break;
46-
}
47-
}
48-
}
49-
}
6+
string a = *(it + 1), b = *(it + 2), c = *(it + 3);
7+
if (isInteger(b)) {
8+
variables[c] = (variables[a] == atoi(b.c_str()));
509
}
51-
// If the variable is undeclared, print an error message
52-
if (undeclared) {
53-
cerr << "[Error] Variable undeclared." << endl;
10+
else if (isInteger(a)){
11+
variables[c] = (atoi(a.c_str()) == variables[b]);
12+
}
13+
else {
14+
variables[c] = (variables[a] == variables[b]);
5415
}
5516
}

src/identifiers/equal_or_greater.hpp

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,14 @@
33
* By lemonorangeapple
44
**/
55
void equal_or_greater(vector<string>::iterator it, ifstream &file) {
6-
// Check if the variable is undeclared
7-
bool undeclared = true;
8-
// Loop through all the variables
9-
for (int i = 0; i <= variableCount; i++) {
10-
// Check if the variable name matches the first argument
11-
if (variables[i].name == *(it + 1)) {
12-
// Check if the second argument is an integer
13-
if (isInteger(*(it + 2))) {
14-
// Loop through all the variables
15-
for (int j = 0; j <= variableCount; j++) {
16-
// Check if the variable name matches the third argument
17-
if (variables[j].name == *(it + 3)) {
18-
// Set the undeclared flag to false
19-
undeclared = false;
20-
// Set the value of the third argument to the value of the first argument
21-
variables[j].value = (variables[i].value >= atoi((*(it + 2)).c_str()));
22-
// Break out of the loop
23-
break;
24-
}
25-
}
26-
}
27-
// Check if the second argument is a variable
28-
else {
29-
// Set the undeclared flag to true
30-
undeclared = true;
31-
// Loop through all the variables
32-
for (int j = 0; j <= variableCount; j++) {
33-
// Check if the variable name matches the second argument
34-
if (variables[j].name == *(it + 2)) {
35-
// Loop through all the variables
36-
for (int k = 0; k <= variableCount; k++) {
37-
// Check if the variable name matches the third argument
38-
if (variables[k].name == *(it + 3)) {
39-
// Set the undeclared flag to false
40-
undeclared = false;
41-
// Set the value of the third argument to the value of the first argument
42-
variables[k].value = (variables[i].value >= variables[j].value);
43-
// Break out of the loop
44-
break;
45-
}
46-
}
47-
// Break out of the inner loop
48-
break;
49-
}
50-
}
51-
}
52-
}
6+
string a = *(it + 1), b = *(it + 2), c = *(it + 3);
7+
if (isInteger(b)) {
8+
variables[c] = (variables[a] >= atoi(b.c_str()));
539
}
54-
// If the variable is undeclared, print an error message
55-
if (undeclared) {
56-
cerr << "[Error] Variable undeclared." << endl;
10+
else if (isInteger(a)){
11+
variables[c] = (atoi(a.c_str()) >= variables[b]);
12+
}
13+
else {
14+
variables[c] = (variables[a] >= variables[b]);
5715
}
5816
}

src/identifiers/equal_or_less.hpp

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,14 @@
33
* By lemonorangeapple
44
**/
55
void equal_or_less(vector<string>::iterator it, ifstream &file) {
6-
// Check if the variable is undeclared
7-
bool undeclared = true;
8-
// Loop through the variables
9-
for (int i = 0; i <= variableCount; i++) {
10-
// Check if the variable name matches
11-
if (variables[i].name == *(it + 1)) {
12-
// Check if the second argument is an integer
13-
if (isInteger(*(it + 2))) {
14-
// Loop through the variables
15-
for (int j = 0; j <= variableCount; j++) {
16-
// Check if the third argument matches
17-
if (variables[j].name == *(it + 3)) {
18-
// Set the undeclared flag to false
19-
undeclared = false;
20-
// Set the value of the third argument to the comparison of the first and second arguments
21-
variables[j].value = (variables[i].value <= atoi((*(it + 2)).c_str()));
22-
// Break out of the loop
23-
break;
24-
}
25-
}
26-
// Break out of the loop
27-
break;
28-
}
29-
// If the second argument is not an integer
30-
else {
31-
// Set the undeclared flag to true
32-
undeclared = true;
33-
// Loop through the variables
34-
for (int j = 0; j <= variableCount; j++) {
35-
// Check if the second argument matches
36-
if (variables[j].name == *(it + 2)) {
37-
// Loop through the variables
38-
for (int k = 0; k <= variableCount; k++) {
39-
// Check if the third argument matches
40-
if (variables[k].name == *(it + 3)) {
41-
// Set the undeclared flag to false
42-
undeclared = false;
43-
// Set the value of the third argument to the comparison of the first and second arguments
44-
variables[k].value = (variables[i].value <= variables[j].value);
45-
// Break out of the loop
46-
break;
47-
}
48-
}
49-
// Break out of the loop
50-
break;
51-
}
52-
}
53-
}
54-
}
6+
string a = *(it + 1), b = *(it + 2), c = *(it + 3);
7+
if (isInteger(b)) {
8+
variables[c] = (variables[a] <= atoi(b.c_str()));
559
}
56-
// If the variable is undeclared
57-
if (undeclared) {
58-
// Print an error message
59-
cerr << "[Error] Variable undeclared." << endl;
10+
else if (isInteger(a)){
11+
variables[c] = (atoi(a.c_str()) <= variables[b]);
12+
}
13+
else {
14+
variables[c] = (variables[a] <= variables[b]);
6015
}
6116
}

0 commit comments

Comments
 (0)