Added if statements

This commit is contained in:
sam-astro 2021-12-24 23:14:40 -05:00
parent 95966cfc74
commit 68e0ed31c0
3 changed files with 66 additions and 2 deletions

View File

@ -315,6 +315,42 @@ int ProcessLine(vector<vector<string>> words, int l, vector<string> variables, v
}
}
}
// Gathers if statement contents
if (words[l][0] == "if")
{
vector<string> ifContents;
vector<string> ifParameters;
for (int w = 1; w < (int)words[l].size(); w++)
ifParameters.push_back(words[l][w]);
int numOfBrackets = 1;
for (int p = l + 2; p < (int)words.size(); p++)
{
numOfBrackets += countInVector(words[p], "{") - countInVector(words[p], "}");
if (numOfBrackets == 0)
break;
ifContents.push_back("");
for (int w = 0; w < (int)words[p].size(); w++)
{
ifContents[(int)ifContents.size() - 1] += words[p][w] + " ";
}
}
ifContents = removeTabs(ifContents, 1);
vector<vector<string>> words;
for (int i = 0; i < (int)ifContents.size(); i++)
words.push_back(split(ifContents[i], ' '));
if (BooleanLogic(ifParameters[0], ifParameters[1], ifParameters[2], variables, variableValues))
{
//Iterate through all lines in while loop
for (int l = 0; l < (int)ifContents.size(); l++)
{
ProcessLine(words, l, variables, variableValues);
}
}
}
return 0;
}
@ -427,6 +463,10 @@ int main(int argc, char* argv[])
std::stringstream scriptString;
scriptString << t.rdbuf();
while (true) {
system("pause");
break;
}
parseSlang(scriptString.str());
/*if (argc >= 2)

View File

@ -88,6 +88,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@ -2,11 +2,34 @@ int x = 1
void Main(input)
{
string c = 8
string d = 8
string e = 8
string f = 8
string g = 8
string h = 8
string i = 8
string j = 8
c /= 2
d /= 2
e /= 2
f /= 2
g /= 2
h /= 2
i /= 2
g /= 2
print input
while x < 10
while x < 10000
{
g /= 2
h /= 2
i /= 2
g /= 2
x += 1
print x
if x > 0
{
print x
}
}
x += 1
print x