Skip to content

Commit 9daba85

Browse files
author
Matthilde
committed
0.2.0-alpha Ready!
1 parent 22cc364 commit 9daba85

8 files changed

Lines changed: 51 additions & 24 deletions

File tree

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
0.2.0-alpha
2+
- Fixed loads of bug because I can't code.
3+
- Fixed some operators that wasn't still working.
4+
- Added 'i' modifier in String operations.
5+
- Updated compile.bat (Windows) and compile.sh (Linux)
6+
- Added 'r' variable returning a random int between 0 and 1000
7+
- You can now Save/Load files
8+
19
0.1.1-alpha
210
- Got rid of boost library, wrote the needed functions from scratch
311
- Fixed NEW that wasn't working

engine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int ExecuteLine(std::string line, int pptr) {
4747
return -1;
4848
}
4949
else
50-
cout << evalStringAddition(o, stringvars) << endl;
50+
cout << evalStringAddition(o, stringvars, intvars) << endl;
5151

5252
return 0;
5353
} else if (starts_with(line, "//")) // Comment
@@ -59,7 +59,7 @@ int ExecuteLine(std::string line, int pptr) {
5959
return -1;
6060
}
6161
else
62-
cout << evalStringAddition(o, stringvars);
62+
cout << evalStringAddition(o, stringvars, intvars);
6363
return 0;
6464
} else if (starts_with(line, "?* ")) {
6565
string o = line.erase(0, 3);
@@ -117,7 +117,7 @@ int ExecuteLine(std::string line, int pptr) {
117117
cout << "!SYNTAX ERROR" << endl;
118118
return -1;
119119
} else {
120-
stringvars[toupper(o.at(0)) - 'A'] = evalStringAddition(oa, stringvars);
120+
stringvars[toupper(o.at(0)) - 'A'] = evalStringAddition(oa, stringvars, intvars);
121121
return 0;
122122
}
123123
} else if (starts_with(line, "G ")) {
@@ -168,7 +168,7 @@ int ExecuteLine(std::string line, int pptr) {
168168
string argA = trimString(o, 0, sepPos - 1);
169169
string argB = trimString(o, sepPos + 1, line.size() - 1);
170170

171-
bool condi = evalStrCondition(argA, stringvars);
171+
bool condi = evalStrCondition(argA, stringvars, intvars);
172172
if (condi) {
173173
int a = ExecuteLine(argB, pptr);
174174
if (a == -1)

libs/stringadd.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using namespace std;
66
// This code allows to perform string addition
77

8-
std::string evalStringAddition(std::string o, const string* vars) {
8+
std::string evalStringAddition(std::string o, const string* vars, const int* intvars) {
99
string* strings = new string[50];
1010
string outputStr = "";
1111

@@ -14,7 +14,8 @@ std::string evalStringAddition(std::string o, const string* vars) {
1414
int ptr = 0; // Array pointer
1515
int endline; // End of array. Variable for optimization purposes.
1616
bool isInQuotes = false;
17-
17+
char pmc; // Previous modifier char
18+
// O = None | 1 = Quoted text | 2 = variable | 3 = Operator | 4 = Modifier
1819
for (int i = 0; i < o.size(); ++i) {
1920
if (ptr > 48) { // To avoid out of range error
2021
cout << "[stringadd.cpp] Syntax Error! (Pointer out of range)" << endl;
@@ -40,26 +41,31 @@ std::string evalStringAddition(std::string o, const string* vars) {
4041
isInQuotes = true;
4142
continue;
4243
} else if (isalpha(c)) {
43-
strings[ptr] = vars[toupper(c) - 'A'];
44-
previousType = 2;
45-
++ptr;
46-
continue;
44+
if (isupper(c)) {
45+
strings[ptr] = vars[toupper(c) - 'A'];
46+
previousType = 2;
47+
++ptr;
48+
continue;
49+
} else if (islower(c)) {
50+
if (c == 'i')
51+
previousType = 4;
52+
}
4753
} else if (c == '+') {
4854
cout << "[stringadd.cpp] Syntax Error! (Misplaced operator)" << endl;
49-
return "ERR";
55+
return "!ERR";
5056
} else if (c == ' ') {
5157
continue;
5258
} else {
5359
cout << "[stringadd.cpp] Syntax Error! (Unknown character)" << endl;
54-
return "ERR";
60+
return "!ERR";
5561
}
5662
} else if (previousType == 1 || previousType == 2) {
5763
if (c == '"') {
5864
cout << "[stringadd.cpp] Syntax Error! (Misplaced quote)" << endl;
59-
return "ERR";
65+
return "!ERR";
6066
} else if (isalpha(c)) {
6167
cout << "[stringadd.cpp] Syntax Error! (Misplaced variable)" << endl;
62-
return "ERR";
68+
return "!ERR";
6369
} else if (c == '+') {
6470
previousType = 3;
6571
++ptr;
@@ -68,7 +74,17 @@ std::string evalStringAddition(std::string o, const string* vars) {
6874
continue;
6975
} else {
7076
cout << "[stringadd.cpp] Syntax Error! (Unknown character)" << endl;
71-
return "ERR";
77+
return "!ERR";
78+
}
79+
} else if (previousType == 4) {
80+
if (!isalpha(c) || !isupper(c)) {
81+
cout << "[stringadd.cpp] Syntax Error! (Variable expected)" << endl;
82+
return "!ERR";
83+
} else {
84+
previousType = 2;
85+
strings[ptr] = to_string(intvars[c - 'A']);
86+
++ptr;
87+
continue;
7288
}
7389
}
7490
}

libs/stringadd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef STRINGADD_H
22
#define STRINGADD_H
33

4-
std::string evalStringAddition(std::string, const std::string*);
4+
std::string evalStringAddition(std::string, const std::string*, const int*);
55
#endif

libs/stringcond.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ string trimStr(string s, int start, int end) {
1515
}
1616

1717
// To eval strings
18-
bool evalStrCondition(string condition, std::string* vars) {
18+
bool evalStrCondition(string condition, std::string* vars, int* ivars) {
1919
char c;
2020
int ops = 0;
2121
int operatorPos = 0;
@@ -67,12 +67,12 @@ bool evalStrCondition(string condition, std::string* vars) {
6767
expB = trimStr(condition, operatorPos + 1, condition.size() - 1);
6868

6969
if (op == '=') {
70-
if (evalStringAddition(expA, vars) == evalStringAddition(expB, vars))
70+
if (evalStringAddition(expA, vars, ivars) == evalStringAddition(expB, vars, ivars))
7171
return true;
7272
else
7373
return false;
7474
} else {
75-
if (evalStringAddition(expA, vars) != evalStringAddition(expB, vars))
75+
if (evalStringAddition(expA, vars, ivars) != evalStringAddition(expB, vars, ivars))
7676
return true;
7777
else
7878
return false;

libs/stringcond.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef STRINGCOND_H
22
#define STRINGCOND_H
33

4-
bool evalStrCondition(std::string, std::string*);
4+
bool evalStrCondition(std::string, std::string*, int*);
55
bool evalIntCondition(std::string, int*);
66
#endif

libs/stringop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ int evalString(std::string o, const int* vars, bool dev) {
3333
int* parentheses = new int[100]; // 0 = None | 1 = ( | 2 = )
3434
// Supported operators : * / + -
3535
// Parentheses aren't supported.
36-
char c;
37-
int previousType = 0; // O = Nothing | 1 = Number | 2 = Operator | 3 = Variable
36+
char c, pmc;
37+
int previousType = 0; // O = Nothing | 1 = Number | 2 = Operator | 3 = Variable | 4 = Modifier
3838
int ptr = 0; // Pointer
3939
int endline; // Position of the array where it ends
4040

libs/tests/stringadd_test.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ using namespace std;
77

88
//Making an array
99
string* vars = new string[26];
10-
10+
int* ivars = new int[26];
1111
int main() {
1212
// Storing some test variables
1313
vars[0] = "beanos"; // Variable A = "beanos"
1414
vars[1] = "shrek"; // Variable B = "shrek"
15+
16+
ivars[0] = 11;
17+
ivars[1] = 22;
1518
string result;
1619

1720
string ari;
1821
getline(cin, ari);
19-
result = evalStringAddition(ari, vars);
22+
result = evalStringAddition(ari, vars, ivars);
2023

2124
cout << endl << "=========" << endl << "Result : \"" << result << "\"" << endl;
2225
return 0;

0 commit comments

Comments
 (0)