diff --git a/Slang/CMakeLists.txt b/Slang/CMakeLists.txt new file mode 100644 index 0000000..8116449 --- /dev/null +++ b/Slang/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.10) + +# set the project name +project(Slang) + +# add the executable +#add_executable(Main.cpp) + +target_include_directories(Slang PUBLIC + "${PROJECT_BINARY_DIR}" + ) \ No newline at end of file diff --git a/Slang/Main.cpp b/Slang/Main.cpp index bc08690..2976c50 100644 --- a/Slang/Main.cpp +++ b/Slang/Main.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "eval.h" @@ -19,10 +19,10 @@ using namespace std; using namespace boost; -unordered_map globalVariableValues; +unordered_map globalVariableValues; unordered_map>> functionValues; -any GetVariableValue(const string& varName, const unordered_map& variableVals) +boost::any GetVariableValue(const string& varName, const unordered_map& variableVals) { auto iA = variableVals.find(varName); if (iA != variableVals.end()) @@ -43,7 +43,7 @@ any GetVariableValue(const string& varName, const unordered_map& va } } -bool IsVar(const string& varName, const unordered_map& variableVals) +bool IsVar(const string& varName, const unordered_map& variableVals) { if (variableVals.find(varName) != variableVals.end()) return true; @@ -51,9 +51,9 @@ bool IsVar(const string& varName, const unordered_map& variableVals return false; } -vector VarValues(const vector& varNames, const unordered_map& variableVals) +vector VarValues(const vector& varNames, const unordered_map& variableVals) { - vector realValues; + vector realValues; for (int varIndex = 0; varIndex < varNames.size(); varIndex++) { @@ -85,7 +85,7 @@ bool IsFunction(const string& funcName) return false; } -any EvalExpression(const string& ex, const unordered_map& variableVals) +boost::any EvalExpression(const string& ex, const unordered_map& variableVals) { string expression = trim(ex); bool inQuotes = false; @@ -221,10 +221,10 @@ any EvalExpression(const string& ex, const unordered_map& variableV return evaluate(newExpression); } -bool BooleanLogic(const string& valA, const string& determinant, const string& valB, const unordered_map& variableVals) +bool BooleanLogic(const string& valA, const string& determinant, const string& valB, const unordered_map& variableVals) { - any valARealValue = EvalExpression(valA, variableVals); - any valBRealValue = EvalExpression(valB, variableVals); + boost::any valARealValue = EvalExpression(valA, variableVals); + boost::any valBRealValue = EvalExpression(valB, variableVals); if (determinant == "==") return AnyAsString(valARealValue) == AnyAsString(valBRealValue); @@ -244,7 +244,7 @@ bool BooleanLogic(const string& valA, const string& determinant, const string& v return false; } -int varOperation(const vector& str, unordered_map& variableValues) +int varOperation(const vector& str, unordered_map& variableValues) { if (IsVar(str[0], variableValues)) { @@ -284,16 +284,16 @@ int varOperation(const vector& str, unordered_map& variable return 1; } -any ProcessLine(const vector>& words, int lineNum, unordered_map& variableValues) +boost::any ProcessLine(const vector>& words, int lineNum, unordered_map& variableValues) { if (words[lineNum][0][0] == '/' && words[lineNum][0][1] == '/') - return any{}; + return boost::any{}; // If print statement (deprecated, now use CPP.System.Print() function) else if (words[lineNum][0] == "print") { cout << AnyAsString(EvalExpression(unWrapVec(vector(words[lineNum].begin() + 1, words[lineNum].end())), variableValues)) << endl; - return any{}; + return boost::any{}; } // Check if function return @@ -308,7 +308,7 @@ any ProcessLine(const vector>& words, int lineNum, unordered_map< else if (IsFunction(trim(split(words[lineNum][0], '(')[0]))) { ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), VarValues(split(RMParenthesis(replace(unWrapVec(words[lineNum]), trim(split(words[lineNum][0], '(')[0]), "")), ','), variableValues)); - return any{}; + return boost::any{}; } // Iterate through all types to see if line inits or @@ -316,7 +316,7 @@ any ProcessLine(const vector>& words, int lineNum, unordered_map< else if (countInVector(types, words[lineNum][0]) > 0) { variableValues[words[lineNum][1]] = EvalExpression(unWrapVec(vector(words[lineNum].begin() + 3, words[lineNum].end())), variableValues); - return any{}; + return boost::any{}; } // Check existing variables: If matches, then it means @@ -325,7 +325,7 @@ any ProcessLine(const vector>& words, int lineNum, unordered_map< { // Evaluates what the operator (ex. '=', '+=') does to the value on the left by the value on the right varOperation(vector(words[lineNum].begin(), words[lineNum].end()), variableValues); - return any{}; + return boost::any{}; } // Gathers while loop contents @@ -360,12 +360,12 @@ any ProcessLine(const vector>& words, int lineNum, unordered_map< //Iterate through all lines in while loop for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++) { - any returnVal = ProcessLine(innerWords, lineNum, variableValues); + boost::any returnVal = ProcessLine(innerWords, lineNum, variableValues); if (AnyAsString(returnVal) != "") return returnVal; } } - return any{}; + return boost::any{}; } // Gathers if statement contents @@ -402,7 +402,7 @@ any ProcessLine(const vector>& words, int lineNum, unordered_map< //Iterate through all lines in if statement for (int l = 0; l < (int)ifContents.size(); l++) { - any returnVal = ProcessLine(innerWords, l, variableValues); + boost::any returnVal = ProcessLine(innerWords, l, variableValues); if (!returnVal.empty()) return returnVal; } @@ -438,9 +438,9 @@ any ProcessLine(const vector>& words, int lineNum, unordered_map< { ProcessLine(innerWords, lineNum, variableValues); } - return any{}; + return boost::any{}; } - return any{}; + return boost::any{}; } //// Gathers else statement contents //if (words[lineNum][0] == "else") @@ -448,15 +448,15 @@ any ProcessLine(const vector>& words, int lineNum, unordered_map< // //} - return any{}; + return boost::any{}; } -any ExecuteFunction(const string functionName, const vector inputVarVals) +boost::any ExecuteFunction(const string& functionName, const vector& inputVarVals) { // Get contents of function vector> words = functionValues[functionName]; - unordered_map variableValues; + unordered_map variableValues; vector args = split(functionValues[functionName][0][0], ','); for (int i = 0; i < (int)inputVarVals.size(); i++) { @@ -466,7 +466,7 @@ any ExecuteFunction(const string functionName, const vector inputVarVals) //Iterate through all lines in function for (int lineNum = 0; lineNum < (int)words.size(); lineNum++) { - any returnVal = 0; + boost::any returnVal = 0; try { returnVal = ProcessLine(words, lineNum, variableValues); @@ -478,7 +478,7 @@ any ExecuteFunction(const string functionName, const vector inputVarVals) if (!returnVal.empty()) return returnVal; } - return any{}; + return boost::any{}; } int parseSlang(string script) @@ -543,7 +543,7 @@ int parseSlang(string script) } // Executes main, which is the starting function - ExecuteFunction("Main", vector {"hi", 0}); + ExecuteFunction("Main", vector {"hi", 0}); return 0; } diff --git a/Slang/Slang.vcxproj b/Slang/Slang.vcxproj index 4f43d62..43f7cc2 100644 --- a/Slang/Slang.vcxproj +++ b/Slang/Slang.vcxproj @@ -65,9 +65,11 @@ + + @@ -89,12 +91,12 @@ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true OldStyle - D:\Code\boost + D:\Code\boost\libs;%(AdditionalIncludeDirectories) Console true - D:\Code\boost + D:\Code\boost\stage\lib @@ -158,6 +160,9 @@ + + + diff --git a/Slang/Slang.vcxproj.filters b/Slang/Slang.vcxproj.filters index 6b7d44e..0800299 100644 --- a/Slang/Slang.vcxproj.filters +++ b/Slang/Slang.vcxproj.filters @@ -49,4 +49,7 @@ + + + \ No newline at end of file diff --git a/Slang/anyops.h b/Slang/anyops.h index 4430214..b89dadb 100644 --- a/Slang/anyops.h +++ b/Slang/anyops.h @@ -3,37 +3,39 @@ #define ANYOPS_H #include "builtin.h" -#include +#include using namespace boost; using namespace std; +int LogWarning(const string& warningText); + // Will convert type 'any' val to a bool -bool AnyAsBool(const any& val) +bool AnyAsBool(const boost::any& val) { try // Try converting to bool { return any_cast(val); } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to string { return any_cast(val) == "true"; } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to float { return any_cast(val) == 1.0f; } - catch (boost::bad_any_cast &e) // Try converting to int + catch (boost::bad_any_cast) // Try converting to int { try { return any_cast(val) == 1; } - catch (boost::bad_any_cast &e) // Does not convert, return + catch (boost::bad_any_cast) // Does not convert, return { LogWarning("invalid conversion to type \'bool\'"); return false; @@ -44,25 +46,25 @@ bool AnyAsBool(const any& val) } // Will convert type 'any' val to a string -string AnyAsString(const any& val) +string AnyAsString(const boost::any& val) { try // Try converting to string { return any_cast(val); } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to int { return to_string(any_cast(val)); } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to float { return to_string(any_cast(val)); } - catch (boost::bad_any_cast &e) // Try converting to bool + catch (boost::bad_any_cast) // Try converting to bool { try { @@ -70,7 +72,7 @@ string AnyAsString(const any& val) if (any_cast(val) == true) i = "true"; return i; } - catch (boost::bad_any_cast &e) // Does not convert, return + catch (boost::bad_any_cast) // Does not convert, return { LogWarning("invalid conversion to type \'string\'"); return ""; @@ -81,25 +83,25 @@ string AnyAsString(const any& val) } // Will convert type 'any' val to a float -float AnyAsFloat(const any& val) +float AnyAsFloat(const boost::any& val) { try // Try converting to float { return any_cast(val); } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to int { return (float)any_cast(val); } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to string, then converting it to float { return stof(any_cast(val)); } - catch (boost::bad_any_cast &e) // Try converting to bool + catch (boost::bad_any_cast) // Try converting to bool { try { @@ -107,7 +109,7 @@ float AnyAsFloat(const any& val) if (any_cast(val) == true) i = 1; return i; } - catch (boost::bad_any_cast &e) // Does not convert, return + catch (boost::bad_any_cast) // Does not convert, return { LogWarning("invalid conversion to type \'float\'"); return 0; @@ -118,25 +120,25 @@ float AnyAsFloat(const any& val) } // Will convert type 'any' val to an integer -int AnyAsInt(const any& val) +int AnyAsInt(const boost::any& val) { try // Try converting to int { return any_cast(val); } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to float { return (int)any_cast(val); } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to string, then converting it to int { return stoi(any_cast(val)); } - catch (boost::bad_any_cast &e) // Try converting to bool + catch (boost::bad_any_cast) // Try converting to bool { try { @@ -144,7 +146,7 @@ int AnyAsInt(const any& val) if (any_cast(val) == true) i = 1; return i; } - catch (boost::bad_any_cast &e) // Does not convert, return + catch (boost::bad_any_cast) // Does not convert, return { LogWarning("invalid conversion to type \'int\'"); return 0; @@ -156,35 +158,35 @@ int AnyAsInt(const any& val) // Gets type of 'any' val // 0 -> int; 1 -> float; 2 -> bool; 3 -> string; -int any_type(const any& val) +int any_type(const boost::any& val) { try // Try converting to int { int i = any_cast(val); return 0; } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to float { float f = any_cast(val); return 1; } - catch (boost::bad_any_cast &e) + catch (boost::bad_any_cast) { try // Try converting to bool { bool b = any_cast(val); return 2; } - catch (boost::bad_any_cast &e) // Try converting to string + catch (boost::bad_any_cast) // Try converting to string { try { string s = any_cast(val); return 3; } - catch (boost::bad_any_cast &e) // Does not convert, return + catch (boost::bad_any_cast) // Does not convert, return { LogWarning("variable has no type"); return -1; diff --git a/Slang/boost_x64_release.props b/Slang/boost_x64_release.props new file mode 100644 index 0000000..e7b305b --- /dev/null +++ b/Slang/boost_x64_release.props @@ -0,0 +1,17 @@ + + + + + + <_PropertySheetDisplayName>boost_x64_release + + + + D:\Code\boost;%(AdditionalIncludeDirectories) + + + D:\Code\boost\stage\lib;%(AdditionalLibraryDirectories) + + + + \ No newline at end of file diff --git a/Slang/builtin.h b/Slang/builtin.h index 9a4574f..d6a9794 100644 --- a/Slang/builtin.h +++ b/Slang/builtin.h @@ -7,11 +7,11 @@ #include #include #include -#include #include #include "strops.h" #include "graphics.h" #include "anyops.h" +#include using namespace std; using namespace boost; @@ -19,7 +19,7 @@ using namespace boost; vector types = { "int", "float", "string", "bool", "void", "null" }; unordered_map>> builtinFunctionValues; -unordered_map builtinVarVals; +unordered_map builtinVarVals; Parser mainWindow; @@ -105,7 +105,7 @@ int GetBuiltins(const string& s) } // Executes -any CPPFunction(const string& name, const vector& args) +boost::any CPPFunction(const string& name, const vector& args) { if (name == "CPP.Math.Sin") return sin(AnyAsFloat(args[0])); diff --git a/Slang/eval.cpp b/Slang/eval.cpp index 4373a00..1d2d422 100644 --- a/Slang/eval.cpp +++ b/Slang/eval.cpp @@ -7,7 +7,7 @@ #include #include "eval.h" #include "strops.h" -#include "builtin.h" +// #include "builtin.h" using namespace std; float precedence(const char& op) { @@ -29,7 +29,7 @@ float applyOp(const float& a, const float& b, const char& op) { case '^': return pow(a, b); } string s(1, op); - LogWarning("operator \'" + s + "\' does not exist"); + //LogWarning("operator \'" + s + "\' does not exist"); return 0; } diff --git a/Slang/eval.h b/Slang/eval.h index 8650d41..51ac197 100644 --- a/Slang/eval.h +++ b/Slang/eval.h @@ -1,6 +1,6 @@ #ifndef EVAL_H #define EVAL_H -float evaluate(std::string tokens); +float evaluate(const std::string& t); #endif \ No newline at end of file diff --git a/Slang/graphics.h b/Slang/graphics.h index 918aba2..389efe0 100644 --- a/Slang/graphics.h +++ b/Slang/graphics.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "strops.h" #include "builtin.h" #include "main.h" @@ -34,7 +35,7 @@ public: bool OnUserUpdate(float fElapsedTime) override { - ExecuteFunction("Update", vector {}); + ExecuteFunction("Update", vector {}); // Called once per frame //for (int x = 0; x < ScreenWidth(); x++) diff --git a/Slang/main.h b/Slang/main.h index 25cbe2d..afcb5e1 100644 --- a/Slang/main.h +++ b/Slang/main.h @@ -3,8 +3,7 @@ #define MAIN_H using namespace std; -using namespace boost; -any ExecuteFunction(const string functionName, const vector inputVarVals); +boost::any ExecuteFunction(const string& functionName, const vector& inputVarVals); #endif diff --git a/Slang/strops.cpp b/Slang/strops.cpp index 83b42de..60c0d39 100644 --- a/Slang/strops.cpp +++ b/Slang/strops.cpp @@ -3,8 +3,9 @@ #include #include #include +#include #include "strops.h" -#include "builtin.h" +//#include "builtin.h" using namespace std; const string WHITESPACE = " \n\r\t\f\v"; @@ -20,11 +21,12 @@ bool isNumber(const string& str) bool stob(string str) { - transform(str.begin(), str.end(), str.begin(), ::tolower); - istringstream is(str); - bool b; - is >> boolalpha >> b; - return b; + //transform(str.begin(), str.end(), str.begin(), ::tolower); + //istringstream is(str); + //bool b; + //is >> boolalpha >> b; + //return b; + return false; } string StringRaw(const string& s) diff --git a/Slang/strops.h b/Slang/strops.h index 6ead244..537e853 100644 --- a/Slang/strops.h +++ b/Slang/strops.h @@ -1,6 +1,8 @@ #ifndef STROPS_H #define STROPS_H +#include + using namespace std; bool isNumber(const string& str);