From 5a990e4313a7ea212e0306fbe36f791b707d084c Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 21 Aug 2017 19:23:03 -0400 Subject: [PATCH] added logic --- parseManager/bin/Debug/parsetest2.txt | 19 +++- parseManager/parseManager.cs | 136 +++++++++++++++++++++----- 2 files changed, 128 insertions(+), 27 deletions(-) diff --git a/parseManager/bin/Debug/parsetest2.txt b/parseManager/bin/Debug/parsetest2.txt index 3f197e8..053f31e 100644 --- a/parseManager/bin/Debug/parsetest2.txt +++ b/parseManager/bin/Debug/parsetest2.txt @@ -1,7 +1,7 @@ ENABLE leaking [TEST]{ "Jump was successful!" - GOTO("HERE") + --GOTO("HERE") } [START]{ "Test 1:" @@ -11,9 +11,20 @@ ENABLE leaking ::HERE:: a,b="sdf",true "a,b,c = $a$ $b$ $c$" - yum="TEST" - JUMP(yum) + food="yum" test=true - if count==stop and test==true then GOTO(end)|GOTO(loop) + stop=21 + "Test 2:" + count=0 + ::loop:: + if count>10 then GOTO("end")|GOTO("continue") + ::continue:: + "Count = $count$" + count=ADD(count,1) + if count>10 then GOTO("end")|GOTO("loop") + ::end:: + "Done!" + QUIT() } + -- (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 8a0bfef..983bcb1 100644 --- a/parseManager/parseManager.cs +++ b/parseManager/parseManager.cs @@ -55,7 +55,6 @@ namespace parseManager } void _Parse(string data) { - string pattern = @"\[(.+)\][\r\n]*?\{([^\0]+?)\}"; foreach (Match m in Regex.Matches(data, @"LOAD ([a-zA-Z0-9_\./]+)")) { Parse(m.Groups[1].ToString()); } @@ -65,20 +64,21 @@ namespace parseManager foreach (Match m in Regex.Matches(data, @"ENTRY ([a-zA-Z0-9_\./]+)")) { _entry = m.Groups[1].ToString(); } - var match = Regex.Matches(data, pattern); + var match = Regex.Matches(data, @"\[(.+)\][\r\n]*?\{([^\0]+?)\}"); + var count=0; foreach (Match m in match) { string Blck = m.Groups[1].ToString(); string Cont = m.Groups[2].ToString(); - int loc = Blck.IndexOf(":"); + int loc = Blck.IndexOf(":", StringComparison.Ordinal); if (loc != -1) { _chunks[Blck.Substring(0, loc)] = new chunk(Blck.Substring(0, loc), Cont, Blck.Substring(loc + 1)); Blck = Blck.Substring(0, loc); } else { _chunks[Blck] = new chunk(Blck, Cont); } - if (_lastChunk != null) { + count++; + if (_lastChunk != null) _lastChunk.SetNextChunk(_chunks[Blck]); - } _lastChunk = _chunks[Blck]; } } @@ -100,9 +100,9 @@ namespace parseManager Console.WriteLine("Load '" + filename + "' File not found. Loading failled!"); } } - public int RunCode(string code) + public void ParseCode(string code) { - return 0; // TODO Add runcode stuff so constructs and functions can work! + _Parse(code); } public chunk[] GetChunks(){ var chunks = _chunks.Values; @@ -217,8 +217,11 @@ namespace parseManager object[] stuff; if (cCMD == null) { if (_flags["leaking"] && _active) { - SetBlock(_currentChunk.GetNextChunk()); - return Next(); + var test=_currentChunk.GetNextChunk(); + if(test!=null){ + SetBlock(_currentChunk.GetNextChunk()); + return Next(); + } } tempReturn.SetCMDType("EOF"); tempReturn.SetText("Reached the end of the file!"); @@ -226,7 +229,65 @@ namespace parseManager } var type = cCMD.GetCMDType(); stuff = cCMD.GetArgs(); - if (type == "LABEL") { + if(type=="LOGIC"){//{conds,andors,_funcif,_resultif,_funcelse,_resultelse} + var conds=(string[])stuff[0]; + var andors=(string[])stuff[1]; + var funcif=(string)stuff[2]; + var argsif=(string[])stuff[3]; + var funcelse=(string)stuff[4]; + var argselse=(string[])stuff[5]; + var objs=new object[conds.Length]; // contain the actual values of what is in the env + var truths= new bool[conds.Length/3]; + var c=0; + //Console.WriteLine(string.Join(",",conds)); + //Console.WriteLine(string.Join(",",andors)); + for(int i=0;i="){ + truths[c] = (double)condA>=(double)condB; + } else if(e=="<="){ + truths[c] = (double)condA<=(double)condB; + } else if(e=="!=" || e=="~="){ + truths[c] = condA.ToString()!=condB.ToString(); + } else if(e==">"){ + truths[c] = (double)condA>(double)condB; + } else if(e=="<"){ + truths[c] = (double)condA<(double)condB; + } else { + PushError("Invalid conditional test! "+e+" is not valid!"); + } + c++; + } + var truth=truths[0]; + if(truths.Length==1 && truth){ + InvokeNR(funcif, ResolveVar(argsif)); + } else if(truths.Length==1) { + InvokeNR(funcelse, ResolveVar(argselse)); + } else { + for(int i=1;i<=]+)+(.+)"); + var s1a=s1p.Groups[1].ToString(); + var s1b=s1p.Groups[2].ToString(); + var s1c=s1p.Groups[3].ToString(); + var s2 = m.Groups[2].ToString(); + conds[p++]=s1a; + conds[p++]=s1b; + conds[p++]=s1c; + andors[p2++]=s2.Substring(1,1); + count+=s1.Length+s2.Length; } - _compiledlines.Add(new CMD("LOGIC", new object[]{"Place holder",_if,_else})); + var s1p2 = Regex.Match(condition.Substring(count,condition.Length-count-1),"(.+?)([~!><=]+)+(.+)"); + var s1a2=s1p2.Groups[1].ToString(); + var s1b2=s1p2.Groups[2].ToString(); + var s1c2=s1p2.Groups[3].ToString(); + //Console.WriteLine(s1a2+"|"+s1b2+"|"+s1c2); + conds[p++]=s1a2; + conds[p++]=s1b2; + conds[p++]=s1c2; + _compiledlines.Add(new CMD("LOGIC", new object[]{conds,andors,_funcif,_resultif,_funcelse,_resultelse})); } else if (label.ToString() != "") { _labels[label.Groups[1].ToString()] = i; _compiledlines.Add(new CMD("LABEL", new object[]{ })); @@ -442,6 +529,9 @@ namespace parseManager pos=-1; return false; } + public void RemoveNextChunk(){ + _next = null; + } public void SetNextChunk(chunk next) { _next = next;