From d11b8a0c563ea4161fa3b7b8af017b8e973bd8fe Mon Sep 17 00:00:00 2001 From: sam-astro <77079540+sam-astro@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:38:00 -0500 Subject: [PATCH] Checks for re-intitialization --- Slang/Main.cpp | 14 +++++++++++++- Slang/script.sl | 12 ++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Slang/Main.cpp b/Slang/Main.cpp index 5dbb72b..8603a45 100644 --- a/Slang/Main.cpp +++ b/Slang/Main.cpp @@ -474,6 +474,18 @@ int ProcessLine(vector> words, int lineNum, vector& varia { if (words[lineNum][0] == types[t]) { + //Checks if it is a re-init of an existing variable + for (int v = 0; v < (int)variables.size(); v++) + { + if (words[lineNum][1] == split(variables[v], ' ')[1]) + { + vector inputs = { words[lineNum][1], words[lineNum][2], words[lineNum][3] }; + evalEqu(inputs, variables, variableValues); + + return 0; + } + } + //Checks if it is variable variables.push_back(words[lineNum][0] + " " + words[lineNum][1]); variableValues.push_back(GetRealValue((string)words[lineNum][3], variables, variableValues)); @@ -481,7 +493,7 @@ int ProcessLine(vector> words, int lineNum, vector& varia return 0; } } - // Second, iterate all existing local variable names + // Second, iterate all existing variable names for (int v = 0; v < (int)variables.size(); v++) { if (words[lineNum][0] == split(variables[v], ' ')[1]) diff --git a/Slang/script.sl b/Slang/script.sl index 3b0990b..658317b 100644 --- a/Slang/script.sl +++ b/Slang/script.sl @@ -13,6 +13,8 @@ void Next(string in, string sin) void Main(string input, int in2) { + int x = 0 + int a = 0 int b = 1 @@ -21,14 +23,20 @@ void Main(string input, int in2) int k = 0 - while x < 1 + while x < 100 { k = a k += b a = b b = k + + string str = x + + str += "::" + str += k - print k + x += 10 + print str } Next "seen", "bop" } \ No newline at end of file