mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
Added function call functionality at one point, also worked on args and started on 'equation' functionaliy, allowing for multiple operations in the same line and parenthesis, like: int g = (y - 4) + ((x + b) / 4)
This commit is contained in:
parent
ce87bdbe81
commit
41d4b11ed1
@ -44,7 +44,7 @@ int ExecuteFunction(string functionName, vector<string> inputVarVals);
|
|||||||
bool isNumber(const string& str)
|
bool isNumber(const string& str)
|
||||||
{
|
{
|
||||||
for (char const& c : str) {
|
for (char const& c : str) {
|
||||||
if (isdigit(c) == 0 && c!='.') return false;
|
if (isdigit(c) == 0 && c != '.') return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ int countNoOverlap(string str, char ch1, char ch2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int indexInStr(string str, char ch) {
|
int indexInStr(string str, char ch) {
|
||||||
|
|
||||||
for (int i = 0; i < (int)str.size(); i++)
|
for (int i = 0; i < (int)str.size(); i++)
|
||||||
if (str[i] == ch)
|
if (str[i] == ch)
|
||||||
return i;
|
return i;
|
||||||
@ -112,7 +112,7 @@ int indexInStr(string str, char ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int charIndexInVec(vector<string> str, char ch) {
|
int charIndexInVec(vector<string> str, char ch) {
|
||||||
|
|
||||||
for (int i = 0; i < (int)str.size(); i++)
|
for (int i = 0; i < (int)str.size(); i++)
|
||||||
for (int w = 0; w < (int)str[i].size(); w++)
|
for (int w = 0; w < (int)str[i].size(); w++)
|
||||||
if (str[i][w] == ch)
|
if (str[i][w] == ch)
|
||||||
@ -159,7 +159,7 @@ vector<string> removeTabs(vector<string> str, int amnt) {
|
|||||||
|
|
||||||
vector<string> rangeInVec(vector<string> str, int min, int max) {
|
vector<string> rangeInVec(vector<string> str, int min, int max) {
|
||||||
if (max == -1)
|
if (max == -1)
|
||||||
max == (int)str.size();
|
max = (int)str.size();
|
||||||
|
|
||||||
vector<string> newStr;
|
vector<string> newStr;
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ vector<string> rangeInVec(vector<string> str, int min, int max) {
|
|||||||
|
|
||||||
string rangeInStr(string str, int min, int max) {
|
string rangeInStr(string str, int min, int max) {
|
||||||
if (max == -1)
|
if (max == -1)
|
||||||
max == (int)str.size();
|
max = (int)str.size();
|
||||||
|
|
||||||
string newStr;
|
string newStr;
|
||||||
|
|
||||||
@ -260,7 +260,7 @@ string GetRealValue(string var, vector<string>& variables, vector<string>& varia
|
|||||||
else if (!isNumber(var) && count(var, '\"') > 0)
|
else if (!isNumber(var) && count(var, '\"') > 0)
|
||||||
{
|
{
|
||||||
string withoutQuotes;
|
string withoutQuotes;
|
||||||
for (int ch = 1; ch < (int)var.size()-1; ch++)
|
for (int ch = 1; ch < (int)var.size() - 1; ch++)
|
||||||
{
|
{
|
||||||
withoutQuotes += var[ch];
|
withoutQuotes += var[ch];
|
||||||
}
|
}
|
||||||
@ -296,7 +296,51 @@ bool BooleanLogic(string valA, string determinant, string valB, vector<string>&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string PEMDAS(string equ)
|
string evalEqu(vector<string> str, vector<string>& variables, vector<string>& variableValues)
|
||||||
|
{
|
||||||
|
// Second, iterate all existing local variable names
|
||||||
|
for (int v = 0; v < (int)variables.size(); v++)
|
||||||
|
{
|
||||||
|
if (str[0] == variables[v])
|
||||||
|
{
|
||||||
|
if (str[1] == "=")
|
||||||
|
variableValues[v] = str[2];
|
||||||
|
else if (str[1] == "+=")
|
||||||
|
variableValues[v] = AddItem(variableValues[v], GetRealValue(str[2], variables, variableValues));
|
||||||
|
else if (str[1] == "-=")
|
||||||
|
variableValues[v] = to_string(stof(variableValues[v]) - stof(GetRealValue(str[2], variables, variableValues)));
|
||||||
|
else if (str[1] == "*=")
|
||||||
|
variableValues[v] = to_string(stof(variableValues[v]) * stof(GetRealValue(str[2], variables, variableValues)));
|
||||||
|
else if (str[1] == "/=")
|
||||||
|
variableValues[v] = to_string(stof(variableValues[v]) / stof(GetRealValue(str[2], variables, variableValues)));
|
||||||
|
|
||||||
|
//cout << words[l][1] << " is " << words[l][3] << endl << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Third, iterate all existing global variable names
|
||||||
|
for (int v = 0; v < (int)globalVariables.size(); v++)
|
||||||
|
{
|
||||||
|
if (str[0] == globalVariables[v])
|
||||||
|
{
|
||||||
|
if (str[1] == "=")
|
||||||
|
globalVariableValues[v] = str[2];
|
||||||
|
else if (str[1] == "+=")
|
||||||
|
globalVariableValues[v] = AddItem(globalVariableValues[v], GetRealValue(str[2], variables, variableValues));
|
||||||
|
else if (str[1] == "-=")
|
||||||
|
globalVariableValues[v] = to_string(stof(globalVariableValues[v]) - stof(GetRealValue(str[2], variables, variableValues)));
|
||||||
|
else if (str[1] == "*=")
|
||||||
|
globalVariableValues[v] = to_string(stof(globalVariableValues[v]) * stof(GetRealValue(str[2], variables, variableValues)));
|
||||||
|
else if (str[1] == "/=")
|
||||||
|
globalVariableValues[v] = to_string(stof(globalVariableValues[v]) / stof(GetRealValue(str[2], variables, variableValues)));
|
||||||
|
|
||||||
|
//cout << words[l][1] << " is " << words[l][3] << endl << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string PEMDAS(string equ, vector<string>& variables, vector<string>& variableValues)
|
||||||
{
|
{
|
||||||
if (split(equ, ',').size() == 1)
|
if (split(equ, ',').size() == 1)
|
||||||
return equ;
|
return equ;
|
||||||
@ -324,7 +368,7 @@ string PEMDAS(string equ)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
equ = replace(equ, "(" + unWrapVec(insideParenthesis) + ")", PEMDAS(unWrapVec(insideParenthesis)));
|
equ = replace(equ, "(" + unWrapVec(insideParenthesis) + ")", PEMDAS(unWrapVec(insideParenthesis), variables, variableValues));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,6 +522,8 @@ int ProcessLine(vector<vector<string>> words, int l, vector<string>& variables,
|
|||||||
|
|
||||||
int ExecuteFunction(string functionName, vector<string> inputVarVals)
|
int ExecuteFunction(string functionName, vector<string> inputVarVals)
|
||||||
{
|
{
|
||||||
|
//vector<string> inputVarVals = split(replace(inVals, " ", ""), ',');
|
||||||
|
|
||||||
vector<string> functionLines;
|
vector<string> functionLines;
|
||||||
int functionIndex = 0;
|
int functionIndex = 0;
|
||||||
//Get index of function
|
//Get index of function
|
||||||
@ -494,7 +540,7 @@ int ExecuteFunction(string functionName, vector<string> inputVarVals)
|
|||||||
vector<string> functionNameParts = split(functions[functionIndex], ' ');
|
vector<string> functionNameParts = split(functions[functionIndex], ' ');
|
||||||
for (int i = 1; i < (int)functionNameParts.size(); i++)
|
for (int i = 1; i < (int)functionNameParts.size(); i++)
|
||||||
{
|
{
|
||||||
variables.push_back(functionNameParts[i]);
|
variables.push_back(replace(replace(functionNameParts[i], ",", ""), " ", ""));
|
||||||
variableValues.push_back(inputVarVals[i - 1]);
|
variableValues.push_back(inputVarVals[i - 1]);
|
||||||
}
|
}
|
||||||
vector<vector<string>> words;
|
vector<vector<string>> words;
|
||||||
|
|||||||
@ -141,7 +141,6 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Main.cpp" />
|
<ClCompile Include="Main.cpp" />
|
||||||
<ClCompile Include="processLine.cpp" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="olcPixelGameEngine.h" />
|
<ClInclude Include="olcPixelGameEngine.h" />
|
||||||
|
|||||||
@ -18,9 +18,6 @@
|
|||||||
<ClCompile Include="Main.cpp">
|
<ClCompile Include="Main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="processLine.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="olcPixelGameEngine.h">
|
<ClInclude Include="olcPixelGameEngine.h">
|
||||||
|
|||||||
@ -1,34 +1,31 @@
|
|||||||
int x = 1
|
int x = 1
|
||||||
|
|
||||||
|
void Next(in, sin)
|
||||||
|
{
|
||||||
|
string green = "bean"
|
||||||
|
green += " "
|
||||||
|
green += in
|
||||||
|
|
||||||
|
print in
|
||||||
|
print sin
|
||||||
|
print green
|
||||||
|
}
|
||||||
|
|
||||||
void Main(input)
|
void Main(input)
|
||||||
{
|
{
|
||||||
int a = 8
|
int a = -8
|
||||||
|
int b = 4
|
||||||
|
|
||||||
print input
|
print input
|
||||||
int k = 0
|
int k = 0
|
||||||
while x < 1000
|
while x < 1000
|
||||||
{
|
{
|
||||||
a /= 7.2
|
|
||||||
a += 9.12867
|
|
||||||
int xThou = x
|
|
||||||
xThou /= 10000
|
|
||||||
a *= xThou
|
|
||||||
|
|
||||||
x += 1
|
x += 1
|
||||||
|
|
||||||
if x > 0
|
print x
|
||||||
{
|
|
||||||
print a
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Next "seen"
|
Next "seen" "bop"
|
||||||
}
|
}
|
||||||
|
|
||||||
void Next()
|
Main "hi"
|
||||||
{
|
|
||||||
string green = "bean"
|
|
||||||
|
|
||||||
print green
|
|
||||||
}
|
|
||||||
|
|
||||||
Main hi
|
|
||||||
Loading…
x
Reference in New Issue
Block a user