From 85770ebcb0eff27c354e20b7051d471020518791 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 21 Aug 2017 00:37:14 -0400 Subject: [PATCH] more updates --- parseManager/Program.cs | 2 +- parseManager/bin/Debug/parsetest2.txt | 14 ++- parseManager/parseManager.cs | 171 +++++++++++++++++++++++--- 3 files changed, 165 insertions(+), 22 deletions(-) diff --git a/parseManager/Program.cs b/parseManager/Program.cs index 29f4a5f..f79500a 100644 --- a/parseManager/Program.cs +++ b/parseManager/Program.cs @@ -8,7 +8,7 @@ */ using System; using parseManager; // IMPORTANT -public class define : standardParseDefine // If you want the standard methods you must include this +public class define : standardDefine // If you want the standard methods you must include this, Also this class cannot be static! { public void testM(object arg1) { diff --git a/parseManager/bin/Debug/parsetest2.txt b/parseManager/bin/Debug/parsetest2.txt index 5838c26..3f197e8 100644 --- a/parseManager/bin/Debug/parsetest2.txt +++ b/parseManager/bin/Debug/parsetest2.txt @@ -1,9 +1,19 @@ -ENTRY START +ENABLE leaking +[TEST]{ + "Jump was successful!" + GOTO("HERE") +} [START]{ "Test 1:" num=ADD(5,5) "num = $num$" c=5 + ::HERE:: a,b="sdf",true "a,b,c = $a$ $b$ $c$" -} \ No newline at end of file + yum="TEST" + JUMP(yum) + test=true + if count==stop and test==true then GOTO(end)|GOTO(loop) +} +-- (count==stop and name=="bob") ? GOTO(end) : GOTO(loop) \ No newline at end of file diff --git a/parseManager/parseManager.cs b/parseManager/parseManager.cs index bc8345c..8a0bfef 100644 --- a/parseManager/parseManager.cs +++ b/parseManager/parseManager.cs @@ -21,6 +21,7 @@ namespace parseManager { string _filepath; bool _hasDefine; + bool _active = true; string _define; string _entry = "START"; Type _defineType; @@ -40,6 +41,13 @@ namespace parseManager _flags.Add("debugging", false); _flags.Add("topdown", true); } + public bool GetFlag(string flag){ + bool f; + if(_flags.TryGetValue(flag,out f)){ + return f; + } + return false; + } void debug(object msg) { if (_flags["debugging"]) @@ -96,6 +104,25 @@ namespace parseManager { return 0; // TODO Add runcode stuff so constructs and functions can work! } + public chunk[] GetChunks(){ + var chunks = _chunks.Values; + var temp = new chunk[_chunks.Count]; + var i=0; + foreach(var item in _chunks) + { + temp[i]=item.Value; + i++; + } + return temp; + } + public chunk GetCurrentChunk() + { + return _currentChunk; + } + public void Deactivate() + { + _active = false; + } public parseManager(string filepath) { InitFlags(); @@ -136,6 +163,7 @@ namespace parseManager chunk cchunk; if (_chunks.TryGetValue(BLOCK, out cchunk)) { _currentChunk = cchunk; + _currentChunk.ResetPos(); } else { PushError("Attempt to JUMP to a non existing block!"); } @@ -161,6 +189,7 @@ namespace parseManager chunk cchunk; if (_chunks.TryGetValue(_entry, out cchunk)) { _currentChunk = cchunk; + _currentChunk.ResetPos(); } else { PushError("Entrypoint is Invalid!"); } @@ -168,6 +197,7 @@ namespace parseManager public void PushError(string err) { Console.WriteLine(err); + Deactivate(); } public nextType Next(string BLOCK) { @@ -186,7 +216,7 @@ namespace parseManager var cCMD = _currentChunk.GetCLine(); object[] stuff; if (cCMD == null) { - if (_flags["leaking"]) { + if (_flags["leaking"] && _active) { SetBlock(_currentChunk.GetNextChunk()); return Next(); } @@ -196,6 +226,20 @@ namespace parseManager } var type = cCMD.GetCMDType(); stuff = cCMD.GetArgs(); + if (type == "LABEL") { + cCMD = _currentChunk.GetCLine(); + if (cCMD == null) { + if (_flags["leaking"] && _active) { + SetBlock(_currentChunk.GetNextChunk()); + return Next(); + } + tempReturn.SetCMDType("EOF"); + tempReturn.SetText("Reached the end of the file!"); + return tempReturn; + } + type = cCMD.GetCMDType(); + stuff = cCMD.GetArgs(); + } if (type == "FUNC") { var func = (string)stuff[0]; var args = (string[])stuff[1]; @@ -222,14 +266,18 @@ namespace parseManager // For Now handle 1 var name to 1 value var env = GetENV(); env[retargs[0]] = data; - } else if(type=="ASSIGN"){ - var vars=(string[])stuff[0]; - var vals=(string[])stuff[1]; + tempReturn.SetCMDType("method"); + tempReturn.SetText("INVOKED METHOD: " + func); + } else if (type == "ASSIGN") { + var vars = (string[])stuff[0]; + var vals = (string[])stuff[1]; var env = GetENV(); - var types=ResolveVar(vals); - for(int i=0;i _labels = new Dictionary(); List _compiledlines = new List(); int _pos = 0; chunk _next = null; @@ -310,7 +359,7 @@ namespace parseManager tCont = Regex.Replace(tCont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline); tCont = Regex.Replace(tCont, @"^\s+$[\r\n]*", "", RegexOptions.Multiline); _lines = tCont.Split(new [] { "\r\n", "\n" }, StringSplitOptions.None); - compile(); // compiles the code into something that can beused quickly + compile(); // compiles the code into something that can be used quickly } void compile() { @@ -321,13 +370,33 @@ namespace parseManager var FuncWOReturn = Regex.Match(temp, @"^([a-zA-Z0-9_]+)\s?\((.*)\)"); var pureLine = Regex.Match(temp, "^\"(.+)\""); var assignment = Regex.Match(temp, "^([a-zA-Z0-9_,\\[\\]\"]+)=([a-zA-Z0-9_\",\\[\\]]+)"); - if (FuncWReturn.ToString() != "") { + var label = Regex.Match(temp, "::(.*)::"); + var logic = Regex.Match(temp,@"if\s*(.+)\s*then\s*(.+?\))\s*\|\s*(.+?\))"); + if(logic.ToString()!=""){ + var condition = logic.Groups[1].ToString(); + var _if = logic.Groups[2].ToString(); + var _else = logic.Groups[3].ToString(); + var temps = Regex.Match(condition,"(.+?)([and ]+?[or ]+)"); + string[] conds; + if(temps.ToString()!=""){ + var count=temps.Groups.Count; + conds= new string[count+1]; + for(int b=1;b _vars = new Dictionary(); + public bool TryGetValue(int ind, out object obj) + { + if (this[ind] != null) { + obj = this[ind]; + return true; + } + obj = null; + return false; + } + public object this[int ind] { + get { + object obj; + if (_vars.TryGetValue(ind, out obj)) { + return obj; + } + return null; + } + set { + _vars[ind] = value; + } + } + } public class nextType { string _type; @@ -525,27 +635,50 @@ namespace parseManager } } } -public class standardParseDefine +public class standardDefine { public void EXIT() { - // TODO Exit the script + GLOBALS.GetPM().Deactivate(); } public void QUIT() { - // TODO Quit the script + Environment.Exit(0); } - public void GOTO(string label) + public int GOTO(string label) { - // TODO goto a label in the script + var test = GLOBALS.GetPM(); + var c = test.GetCurrentChunk(); + int pos; + if(c.TryGetLabel(label, out pos)){ + c.SetPos(pos); + return 0; + } else if(test.GetFlag("forseelabels")){ + var chunks = test.GetChunks(); + for(int i=0;i