diff --git a/README.md b/README.md index 571f24f..fb9cd8d 100755 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ ![GitHub repo size in bytes](https://img.shields.io/github/repo-size/stormprograms/stormscript.svg) -[![Build Status](https://dev.azure.com/alegosdude/stormscript/_apis/build/status/stormprograms.StormScript%20(1)?branchName=dev)](https://dev.azure.com/alegosdude/stormscript/_build/latest?definitionId=2?branchName=dev) - [![Total alerts](https://img.shields.io/lgtm/alerts/g/stormprograms/StormScript.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/stormprograms/StormScript/alerts/) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/stormprograms/StormScript.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/stormprograms/StormScript/context:cpp) diff --git a/docs/building.md b/docs/building.md index a71057d..ae01d6f 100644 --- a/docs/building.md +++ b/docs/building.md @@ -2,7 +2,7 @@ Make a directory called build -**You must have gcc/g++ installed (MinGW for Windows) and CMake** +**You must have gcc-8/g++-8 installed (MinGW for Windows) and CMake** GDB is also highly recommended for debugging @@ -14,7 +14,7 @@ Terminal: ## Windows Make sure you have MinGW and CMake installed (in PATH) -run `cmake -G "MinGW Makefiles" -D CMAKE_C_COMPILER="gcc" -D CMAKE_CXX_COMPILER="g++"` +run `cmake -G "MinGW Makefiles"` then run `mingw32-make` also make sure that you have src/core in PATH for errors to work diff --git a/docs/development/style.md b/docs/development/style.md index 077123a..aadbcb3 100644 --- a/docs/development/style.md +++ b/docs/development/style.md @@ -17,7 +17,8 @@ This should go without saying, but please comment on your code. I love reading c # C++ Style C++ has the strictest rules when it comes to styling as it makes up the majority of the project. -**TABS ARE ALWAYS 4 SPACES** +## Indention +Use the `\t` character ## Includes **YOU MUST FOLLOW THIS** @@ -38,9 +39,18 @@ if (expressions[*y].t == ENDEXPR) *y += 1; or ```cpp if (expressions[*y].t == ENDEXPR) - *y += 1; + *y += 1; ``` +Otherwise, curly braces go 1 space in front of scope defining statement. + +```cpp +switch (expressions[*y].t) { + ... +} +``` + + ## If statements and Switches If you are dealing with enumerations, integers, or characters, you should use switch statements otherwise use if statements. diff --git a/docs/development/the_parser.md b/docs/development/the_parser.md index 3fe0f8e..5af833a 100644 --- a/docs/development/the_parser.md +++ b/docs/development/the_parser.md @@ -18,6 +18,6 @@ Expressions are "sorted" into 5 different enumerations: ## Characters that are left out -Needless to say, whitespace and empty newlines are left out of the parsed program as they serve no purpose to the actual execution of the program. +Needless to say, whitespace, comments, and empty newlines are left out of the parsed program as they serve no purpose to the actual execution of the program. Less obviously, parentheses are completely left out of the program (for now) because they currently would only change the look of the program \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index 1c7bcf7..0a75be7 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,3 +1,4 @@ -socket s => "AF_INET", "127.0.0.1", 9090; - -s.connect => "Hello, World"; \ No newline at end of file +for 25 { + printl random; + printl randomrange 1 10; +} \ No newline at end of file diff --git a/src/parser/parse.cc b/src/parser/parse.cc index f6a1016..079ccca 100755 --- a/src/parser/parse.cc +++ b/src/parser/parse.cc @@ -8,18 +8,18 @@ the interpreter parses the file and calls functions in other files void parse() { int y = 0; - while (y!=prg.size()){ + while (y!=parserProgram.size()){ int z = 0; bool inquotes = false; if (program.expressions.size() > 0) program.expressions.resize(program.expressions.size()+1); - while (prg[y][0]==' ') - prg[y].erase(prg[y].begin()); + while (parserProgram[y][0]==' ') + parserProgram[y].erase(parserProgram[y].begin()); - while (z!=prg[y].size()){ - if (prg[y][z]=='"'){ + while (z!=parserProgram[y].size()){ + if (parserProgram[y][z]=='"'){ if (inquotes == false) inquotes = true; else @@ -27,27 +27,27 @@ void parse() { } // this is what checks for chars to remove from prs version - if (((prg[y][z]==' ') || (prg[y][z]=='\n') || (prg[y][z]=='(') || (prg[y][z]==')')) && (inquotes==false)){ + if (((parserProgram[y][z]==' ') || (parserProgram[y][z]=='\n') || (parserProgram[y][z]=='(') || (parserProgram[y][z]==')')) && (inquotes==false)){ if ((program.expressions.back().contents.size() != 0)) program.expressions.resize(program.expressions.size()+1); z++; program.expressions.back().line = y; continue; } - else if ((prg[y][z]=='#')) // line comment + else if ((parserProgram[y][z]=='#')) // line comment break; - else if (((prg[y][z]==';') || (prg[y][z]=='}') || (prg[y][z]=='{')) && (inquotes==false)) { + else if (((parserProgram[y][z]==';') || (parserProgram[y][z]=='}') || (parserProgram[y][z]=='{')) && (inquotes==false)) { program.expressions.resize(program.expressions.size() + 1); - program.expressions.back() = string(1,prg[y][z]); + program.expressions.back() = string(1,parserProgram[y][z]); program.expressions.back().line = y; break; } - else if (((prg[y][z]=='+') || (prg[y][z]=='-') || (prg[y][z]=='*') || ((prg[y][z]=='/') && (program.expressions[program.expressions.size()-2].contents!="mod")) || (prg[y][z]=='[') || (prg[y][z]==',') || (prg[y][z]==']') || (prg[y][z] == ':') || (prg[y][z] == '.')) && (inquotes==false)) { - program.expressions.push_back( string(1,prg[y][z]) ); + else if (((parserProgram[y][z]=='+') || (parserProgram[y][z]=='-') || (parserProgram[y][z]=='*') || ((parserProgram[y][z]=='/') && (program.expressions[program.expressions.size()-2].contents!="mod")) || (parserProgram[y][z]=='[') || (parserProgram[y][z]==',') || (parserProgram[y][z]==']') || (parserProgram[y][z] == ':') || (parserProgram[y][z] == '.')) && (inquotes==false)) { + program.expressions.push_back( string(1,parserProgram[y][z]) ); program.expressions.back().line = y; program.expressions.resize(program.expressions.size()+1); } - else if ((prg[y][z]=='\t') && (inquotes==false)) { + else if ((parserProgram[y][z]=='\t') && (inquotes==false)) { z++; program.expressions.back().line = y; continue; @@ -55,7 +55,7 @@ void parse() { else { if (program.expressions.size() == 0) program.expressions.push_back(expression()); - program.expressions.back().contents+=prg[y][z]; + program.expressions.back().contents+=parserProgram[y][z]; } program.expressions.back().line = y; z++; diff --git a/src/parser/parseerrors.cc b/src/parser/parseerrors.cc index b6cb0d0..b3bfc95 100644 --- a/src/parser/parseerrors.cc +++ b/src/parser/parseerrors.cc @@ -15,7 +15,7 @@ void parseErrors() { bool glob = 1; for (int i = 0; i < program.expressions.size(); i++) { - if ((program.expressions[i].line == prg.size() - 1 && i == program.expressions.size()-1) || program.expressions[i + 1].line != program.expressions[i].line) { // this checks if there is no semicolon at the end of line + if ((program.expressions[i].line == parserProgram.size() - 1 && i == program.expressions.size()-1) || program.expressions[i + 1].line != program.expressions[i].line) { // this checks if there is no semicolon at the end of line if (program.expressions[i].t != ENDEXPR && program.expressions[i].tktype != CLOSEDCURL && program.expressions[i].tktype != OPENCURL) error(1, std::to_string(program.expressions[i].line + 1)); // add 1 to line because line gives index, which always starts at 0 } diff --git a/src/parser/read.cc b/src/parser/read.cc index fc81d3f..a2aec8d 100644 --- a/src/parser/read.cc +++ b/src/parser/read.cc @@ -7,7 +7,7 @@ void stsread(char *argv[], int argc) { std::ifstream file; string contents; - prg = {}; + parserProgram = {}; int sizeoff = 0; @@ -31,20 +31,20 @@ void stsread(char *argv[], int argc) { } //create sizeof in lines sizeoff++; - prg.resize(sizeoff); //create vector for lines + parserProgram.resize(sizeoff); //create vector for lines int loc = 0; int a = 0; for (int x = 0; x <= contents.size(); x++) { if (contents[x] == '\n') { for (int y = loc; y < x; y++) - prg[a] += contents[y]; //add lines to vector + parserProgram[a] += contents[y]; //add lines to vector a++; loc = x + 1; } } for (int x = loc; x <= contents.size(); x++) - prg[prg.size() - 1] += contents[x]; //add last line to vector + parserProgram[parserProgram.size() - 1] += contents[x]; //add last line to vector interp(sizeoff, argv, argc); } diff --git a/src/sts_files.h b/src/sts_files.h index 3357b7d..2ced8df 100644 --- a/src/sts_files.h +++ b/src/sts_files.h @@ -5,6 +5,6 @@ void stsread(char *argv[], int argc); // read stormscript programs -inline std::vector prg; //unparsed program +inline std::vector parserProgram; //unparsed program #endif // STS_FILES_H_ diff --git a/src/values/getvals.cc b/src/values/getvals.cc index f8f6fe7..0a403e0 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -71,7 +71,7 @@ stsvars getval() { bool operation = ((program.expressions[program.loc+1].t == TOKEN) && (program.expressions[program.loc+1].tktype != COMMA) && (program.expressions[program.loc+1].tktype != COLON) && (program.expressions[program.loc+1].tktype != OPENCURL) && (program.expressions[program.loc+1].tktype != CLOSEDBRACKET) && - (program.expressions[program.loc+1].tktype != DOT) && + (program.expressions[program.loc+1].tktype != DOT) && (program.expressions[program.loc].btn != RANDOMRANGE) && (program.expressions.size() > program.loc+1)); switch (operation) { diff --git a/src/values/random.cc b/src/values/random.cc index c9ac538..acd0e39 100644 --- a/src/values/random.cc +++ b/src/values/random.cc @@ -2,31 +2,60 @@ #include #include +#if (PLATFORM) +#include +#endif + int genrandomintfromrange() { - long int ut = static_cast (time(NULL)); // cast unix epoch to long int int range[2]; // range will store the min and max values program.loc++; - std::vector expressions = program.expressions; + range[0] = std::stoi(getval().val); + program.loc++; + range[1] = std::stoi(getval().val); + + #if (!PLATFORM) std::random_device randomd; std::mt19937_64 generate(randomd()); - range[0] = std::stoi(getval().val); - program.loc++; - range[1] = std::stoi(getval().val); - std::uniform_int_distribution<> dis(range[0], range[1]); return dis(generate); + #else + /* + * This most likely uses more CPU than the Linux version, + * but it is the best I can do until MinGW fixes mt19937_64 + */ + { // in it's own scope to allow using namespace + // not a bad idea as long as it is in a scope for only how long it is needed + using namespace std::chrono; + nanoseconds timens = duration_cast(steady_clock::now().time_since_epoch()); + srand(timens.count()); + } + return rand() % range[1] + range[0]; + #endif + + return 0; } bool randombool() { + #if (!PLATFORM) std::random_device randomd; std::mt19937_64 generate(randomd()); std::uniform_int_distribution<> dis(0, 1); + return dis(generate); + #else + { + using namespace std::chrono; + nanoseconds timens = duration_cast(steady_clock::now().time_since_epoch()); + srand(timens.count()); + } + return rand() % 2; + #endif + return 0; }