Skip to content

Commit

Permalink
0.2.0-alpha Ready!
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthilde committed Aug 27, 2019
1 parent 22cc364 commit 9daba85
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 24 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.2.0-alpha
- Fixed loads of bug because I can't code.
- Fixed some operators that wasn't still working.
- Added 'i' modifier in String operations.
- Updated compile.bat (Windows) and compile.sh (Linux)
- Added 'r' variable returning a random int between 0 and 1000
- You can now Save/Load files

0.1.1-alpha
- Got rid of boost library, wrote the needed functions from scratch
- Fixed NEW that wasn't working
Expand Down
8 changes: 4 additions & 4 deletions engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int ExecuteLine(std::string line, int pptr) {
return -1;
}
else
cout << evalStringAddition(o, stringvars) << endl;
cout << evalStringAddition(o, stringvars, intvars) << endl;

return 0;
} else if (starts_with(line, "//")) // Comment
Expand All @@ -59,7 +59,7 @@ int ExecuteLine(std::string line, int pptr) {
return -1;
}
else
cout << evalStringAddition(o, stringvars);
cout << evalStringAddition(o, stringvars, intvars);
return 0;
} else if (starts_with(line, "?* ")) {
string o = line.erase(0, 3);
Expand Down Expand Up @@ -117,7 +117,7 @@ int ExecuteLine(std::string line, int pptr) {
cout << "!SYNTAX ERROR" << endl;
return -1;
} else {
stringvars[toupper(o.at(0)) - 'A'] = evalStringAddition(oa, stringvars);
stringvars[toupper(o.at(0)) - 'A'] = evalStringAddition(oa, stringvars, intvars);
return 0;
}
} else if (starts_with(line, "G ")) {
Expand Down Expand Up @@ -168,7 +168,7 @@ int ExecuteLine(std::string line, int pptr) {
string argA = trimString(o, 0, sepPos - 1);
string argB = trimString(o, sepPos + 1, line.size() - 1);

bool condi = evalStrCondition(argA, stringvars);
bool condi = evalStrCondition(argA, stringvars, intvars);
if (condi) {
int a = ExecuteLine(argB, pptr);
if (a == -1)
Expand Down
38 changes: 27 additions & 11 deletions libs/stringadd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace std;
// This code allows to perform string addition

std::string evalStringAddition(std::string o, const string* vars) {
std::string evalStringAddition(std::string o, const string* vars, const int* intvars) {
string* strings = new string[50];
string outputStr = "";

Expand All @@ -14,7 +14,8 @@ std::string evalStringAddition(std::string o, const string* vars) {
int ptr = 0; // Array pointer
int endline; // End of array. Variable for optimization purposes.
bool isInQuotes = false;

char pmc; // Previous modifier char
// O = None | 1 = Quoted text | 2 = variable | 3 = Operator | 4 = Modifier
for (int i = 0; i < o.size(); ++i) {
if (ptr > 48) { // To avoid out of range error
cout << "[stringadd.cpp] Syntax Error! (Pointer out of range)" << endl;
Expand All @@ -40,26 +41,31 @@ std::string evalStringAddition(std::string o, const string* vars) {
isInQuotes = true;
continue;
} else if (isalpha(c)) {
strings[ptr] = vars[toupper(c) - 'A'];
previousType = 2;
++ptr;
continue;
if (isupper(c)) {
strings[ptr] = vars[toupper(c) - 'A'];
previousType = 2;
++ptr;
continue;
} else if (islower(c)) {
if (c == 'i')
previousType = 4;
}
} else if (c == '+') {
cout << "[stringadd.cpp] Syntax Error! (Misplaced operator)" << endl;
return "ERR";
return "!ERR";
} else if (c == ' ') {
continue;
} else {
cout << "[stringadd.cpp] Syntax Error! (Unknown character)" << endl;
return "ERR";
return "!ERR";
}
} else if (previousType == 1 || previousType == 2) {
if (c == '"') {
cout << "[stringadd.cpp] Syntax Error! (Misplaced quote)" << endl;
return "ERR";
return "!ERR";
} else if (isalpha(c)) {
cout << "[stringadd.cpp] Syntax Error! (Misplaced variable)" << endl;
return "ERR";
return "!ERR";
} else if (c == '+') {
previousType = 3;
++ptr;
Expand All @@ -68,7 +74,17 @@ std::string evalStringAddition(std::string o, const string* vars) {
continue;
} else {
cout << "[stringadd.cpp] Syntax Error! (Unknown character)" << endl;
return "ERR";
return "!ERR";
}
} else if (previousType == 4) {
if (!isalpha(c) || !isupper(c)) {
cout << "[stringadd.cpp] Syntax Error! (Variable expected)" << endl;
return "!ERR";
} else {
previousType = 2;
strings[ptr] = to_string(intvars[c - 'A']);
++ptr;
continue;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/stringadd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef STRINGADD_H
#define STRINGADD_H

std::string evalStringAddition(std::string, const std::string*);
std::string evalStringAddition(std::string, const std::string*, const int*);
#endif
6 changes: 3 additions & 3 deletions libs/stringcond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ string trimStr(string s, int start, int end) {
}

// To eval strings
bool evalStrCondition(string condition, std::string* vars) {
bool evalStrCondition(string condition, std::string* vars, int* ivars) {
char c;
int ops = 0;
int operatorPos = 0;
Expand Down Expand Up @@ -67,12 +67,12 @@ bool evalStrCondition(string condition, std::string* vars) {
expB = trimStr(condition, operatorPos + 1, condition.size() - 1);

if (op == '=') {
if (evalStringAddition(expA, vars) == evalStringAddition(expB, vars))
if (evalStringAddition(expA, vars, ivars) == evalStringAddition(expB, vars, ivars))
return true;
else
return false;
} else {
if (evalStringAddition(expA, vars) != evalStringAddition(expB, vars))
if (evalStringAddition(expA, vars, ivars) != evalStringAddition(expB, vars, ivars))
return true;
else
return false;
Expand Down
2 changes: 1 addition & 1 deletion libs/stringcond.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef STRINGCOND_H
#define STRINGCOND_H

bool evalStrCondition(std::string, std::string*);
bool evalStrCondition(std::string, std::string*, int*);
bool evalIntCondition(std::string, int*);
#endif
4 changes: 2 additions & 2 deletions libs/stringop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ int evalString(std::string o, const int* vars, bool dev) {
int* parentheses = new int[100]; // 0 = None | 1 = ( | 2 = )
// Supported operators : * / + -
// Parentheses aren't supported.
char c;
int previousType = 0; // O = Nothing | 1 = Number | 2 = Operator | 3 = Variable
char c, pmc;
int previousType = 0; // O = Nothing | 1 = Number | 2 = Operator | 3 = Variable | 4 = Modifier
int ptr = 0; // Pointer
int endline; // Position of the array where it ends

Expand Down
7 changes: 5 additions & 2 deletions libs/tests/stringadd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ using namespace std;

//Making an array
string* vars = new string[26];

int* ivars = new int[26];
int main() {
// Storing some test variables
vars[0] = "beanos"; // Variable A = "beanos"
vars[1] = "shrek"; // Variable B = "shrek"

ivars[0] = 11;
ivars[1] = 22;
string result;

string ari;
getline(cin, ari);
result = evalStringAddition(ari, vars);
result = evalStringAddition(ari, vars, ivars);

cout << endl << "=========" << endl << "Result : \"" << result << "\"" << endl;
return 0;
Expand Down

0 comments on commit 9daba85

Please sign in to comment.