Skip to content

pull #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 15, 2025
Merged

pull #31

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ jobs:
run: make
- name: run
run: ./JunLang
- uses: actions/upload-artifact@v4
with:
name: JunLang
path: ./JunLang
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
.idea
cmake-build-debug
cmake-build-debug
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# JunLang
[![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)

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

Expand Down
34 changes: 6 additions & 28 deletions src/identifiers/addition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,12 @@
* By lemonorangeapple
**/
void addition(vector<string>::iterator it, ifstream &file) {
// Check if the variable is already declared
bool undeclared = true;
for (int i = 0; i <= variableCount; i++) {
// If the variable is already declared, add the value
if (variables[i].name == *(it + 1)) {
// Check if the value is an integer
if (isInteger(*(it + 2))) {
// Add the integer value to the variable
variables[i].value += atoi((*(it + 2)).c_str());
undeclared = false;
break;
}
// If the value is not an integer, check if it is a variable
else {
undeclared = true;
for (int j = 0; j <= variableCount; j++) {
// If the variable is already declared, add the value
if (variables[j].name == *(it + 2)) {
variables[i].value += variables[j].value;
undeclared = false;
break;
}
}
}
}
string next = *(it + 2);
string _this = *(it + 1);
if (isInteger(next)) {
variables[_this] += atoi((next).c_str());
}
// If the variable is not declared, throw an error
if (undeclared) {
cerr << "[ERROR] Variable undeclared. " << endl;
else {
variables[_this] += variables[next];
}
}
43 changes: 6 additions & 37 deletions src/identifiers/division.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,12 @@
* By lemonorangeapple
**/
void division(vector<string>::iterator it, ifstream &file) {
// Check if the variable is undeclared
bool undeclared = true;
// Loop through the variables
for (int i = 0; i <= variableCount; i++) {
// Check if the variable name matches the one in the expression
if (variables[i].name == *(it + 1)) {
// Check if the value is an integer
if (isInteger(*(it + 2))) {
// Divide the value by the integer
variables[i].value /= atoi((*(it + 2)).c_str());
// Set undeclared to false
undeclared = false;
// Break out of the loop
break;
}
// If the value is not an integer
else {
// Set undeclared to true
undeclared = true;
// Loop through the variables
for (int j = 0; j <= variableCount; j++) {
// Check if the variable name matches the one in the expression
if (variables[j].name == *(it + 2)) {
// Divide the value by the value of the other variable
variables[i].value /= variables[j].value;
// Set undeclared to false
undeclared = false;
// Break out of the loop
break;
}
}
}
}
string next = *(it + 2);
string _this = *(it + 1);
if (isInteger(next)) {
variables[_this] /= atoi((next).c_str());
}
// If the variable is undeclared
if (undeclared) {
// Print an error message
cerr << "[ERROR] Variable undeclared. " << endl;
else {
variables[_this] /= variables[next];
}
}
25 changes: 7 additions & 18 deletions src/identifiers/end_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,13 @@ void end_loop(vector<string>::iterator it, ifstream &file) {
if (!loopFlag.empty()) {
// Check if loop flag is true
if (loopFlag.top() == true) {
// Check if loop variable name is correct
for (int i = 0; i <= variableCount; i++) {
if (variables[i].name == loopVariableName.top()) {
// Check if loop variable value is 0
if (variables[i].value == 0) {
// Pop loop flag
loopFlag.pop();
break;
}
else {
// Check if loop line is empty
if (!loopLine.empty()) {
// Seekg to loop line
file.seekg(int(loopLine.top()) - 2);
}
break;
}
}
if (variables[loopVariableName.top()] == 0) {
// Pop loop flag
loopFlag.pop();
}
else if (!loopLine.empty()) {
// Seekg to loop line
file.seekg(int(loopLine.top()) - 3);
}
}
else {
Expand Down
55 changes: 8 additions & 47 deletions src/identifiers/equal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,14 @@
* By lemonorangeapple
**/
void equal(vector<string>::iterator it, ifstream &file) {
// Check if the variable is undeclared
bool undeclared = true;
// Loop through the variables
for (int i = 0; i <= variableCount; i++) {
// Check if the variable name matches
if (variables[i].name == *(it + 1)) {
// Check if the value is an integer
if (isInteger(*(it + 2))) {
// Loop through the variables
for (int j = 0; j <= variableCount; j++) {
// Check if the variable name matches
if (variables[j].name == *(it + 3)) {
// Set the undeclared flag to false
undeclared = false;
// Set the value to true if the variable values are equal
variables[j].value = (variables[i].value == atoi((*(it + 2)).c_str()));
break;
}
}
}
// Check if the value is a variable
else {
// Set the undeclared flag to true
undeclared = true;
// Loop through the variables
for (int j = 0; j <= variableCount; j++) {
// Check if the variable name matches
if (variables[j].name == *(it + 2)) {
// Loop through the variables
for (int k = 0; k <= variableCount; k++) {
// Check if the variable name matches
if (variables[k].name == *(it + 3)) {
// Set the undeclared flag to false
undeclared = false;
// Set the value to true if the variable values are equal
variables[k].value = (variables[i].value == variables[j].value);
break;
}
}
break;
}
}
}
}
string a = *(it + 1), b = *(it + 2), c = *(it + 3);
if (isInteger(b)) {
variables[c] = (variables[a] == atoi(b.c_str()));
}
// If the variable is undeclared, print an error message
if (undeclared) {
cerr << "[Error] Variable undeclared." << endl;
else if (isInteger(a)){
variables[c] = (atoi(a.c_str()) == variables[b]);
}
else {
variables[c] = (variables[a] == variables[b]);
}
}
58 changes: 8 additions & 50 deletions src/identifiers/equal_or_greater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,14 @@
* By lemonorangeapple
**/
void equal_or_greater(vector<string>::iterator it, ifstream &file) {
// Check if the variable is undeclared
bool undeclared = true;
// Loop through all the variables
for (int i = 0; i <= variableCount; i++) {
// Check if the variable name matches the first argument
if (variables[i].name == *(it + 1)) {
// Check if the second argument is an integer
if (isInteger(*(it + 2))) {
// Loop through all the variables
for (int j = 0; j <= variableCount; j++) {
// Check if the variable name matches the third argument
if (variables[j].name == *(it + 3)) {
// Set the undeclared flag to false
undeclared = false;
// Set the value of the third argument to the value of the first argument
variables[j].value = (variables[i].value >= atoi((*(it + 2)).c_str()));
// Break out of the loop
break;
}
}
}
// Check if the second argument is a variable
else {
// Set the undeclared flag to true
undeclared = true;
// Loop through all the variables
for (int j = 0; j <= variableCount; j++) {
// Check if the variable name matches the second argument
if (variables[j].name == *(it + 2)) {
// Loop through all the variables
for (int k = 0; k <= variableCount; k++) {
// Check if the variable name matches the third argument
if (variables[k].name == *(it + 3)) {
// Set the undeclared flag to false
undeclared = false;
// Set the value of the third argument to the value of the first argument
variables[k].value = (variables[i].value >= variables[j].value);
// Break out of the loop
break;
}
}
// Break out of the inner loop
break;
}
}
}
}
string a = *(it + 1), b = *(it + 2), c = *(it + 3);
if (isInteger(b)) {
variables[c] = (variables[a] >= atoi(b.c_str()));
}
// If the variable is undeclared, print an error message
if (undeclared) {
cerr << "[Error] Variable undeclared." << endl;
else if (isInteger(a)){
variables[c] = (atoi(a.c_str()) >= variables[b]);
}
else {
variables[c] = (variables[a] >= variables[b]);
}
}
61 changes: 8 additions & 53 deletions src/identifiers/equal_or_less.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,14 @@
* By lemonorangeapple
**/
void equal_or_less(vector<string>::iterator it, ifstream &file) {
// Check if the variable is undeclared
bool undeclared = true;
// Loop through the variables
for (int i = 0; i <= variableCount; i++) {
// Check if the variable name matches
if (variables[i].name == *(it + 1)) {
// Check if the second argument is an integer
if (isInteger(*(it + 2))) {
// Loop through the variables
for (int j = 0; j <= variableCount; j++) {
// Check if the third argument matches
if (variables[j].name == *(it + 3)) {
// Set the undeclared flag to false
undeclared = false;
// Set the value of the third argument to the comparison of the first and second arguments
variables[j].value = (variables[i].value <= atoi((*(it + 2)).c_str()));
// Break out of the loop
break;
}
}
// Break out of the loop
break;
}
// If the second argument is not an integer
else {
// Set the undeclared flag to true
undeclared = true;
// Loop through the variables
for (int j = 0; j <= variableCount; j++) {
// Check if the second argument matches
if (variables[j].name == *(it + 2)) {
// Loop through the variables
for (int k = 0; k <= variableCount; k++) {
// Check if the third argument matches
if (variables[k].name == *(it + 3)) {
// Set the undeclared flag to false
undeclared = false;
// Set the value of the third argument to the comparison of the first and second arguments
variables[k].value = (variables[i].value <= variables[j].value);
// Break out of the loop
break;
}
}
// Break out of the loop
break;
}
}
}
}
string a = *(it + 1), b = *(it + 2), c = *(it + 3);
if (isInteger(b)) {
variables[c] = (variables[a] <= atoi(b.c_str()));
}
// If the variable is undeclared
if (undeclared) {
// Print an error message
cerr << "[Error] Variable undeclared." << endl;
else if (isInteger(a)){
variables[c] = (atoi(a.c_str()) <= variables[b]);
}
else {
variables[c] = (variables[a] <= variables[b]);
}
}
Loading