//variable replace public void VarSet(string name, string type, object value) { LV.Get(); if (type == "Local") { for (int i = 0; i < LV.vars.LongCount(); i++) { VariablesStruct va = LV.vars[i]; if (va.Name == name) { va = new VariablesStruct(name, type, value); LV.Set(); return; } LV.vars[i] = va; } LV.vars.Add(new VariablesStruct(name, type, value)); LV.Set(); } else { GV.Get(); for (int i = 0; i < GV.vars.LongCount(); i++) { VariablesStruct va = GV.vars[i]; if (va.Name == name) { va = new VariablesStruct(name, type, value); GV.Set(); return; } GV.vars[i] = va; } GV.vars.Add(new VariablesStruct(name, type, value)); GV.Set(); } }
//delete variable public void VarRem(string name) { LV.Get(); for (int i = 0; i < LV.vars.LongCount(); i++) { VariablesStruct va = LV.vars[i]; if (va.Name == name) { LV.vars.RemoveAt(i); LV.Set(); return; } } GV.Get(); for (int i = 0; i < GV.vars.LongCount(); i++) { VariablesStruct va = GV.vars[i]; if (va.Name == name) { GV.vars.RemoveAt(i); GV.Set(); return; } } }
//insert new variable or rewrite public void VarAdd(VariablesStruct v) { if (v.Value.ToString() == "NaN" || v.Value.ToString() == "") { v.Value = "null"; } if (v.Name != "" && v.Name != " ") { if (v.Type == "Local") { for (int i = 0; i < LV.vars.LongCount(); i++) { VariablesStruct va = LV.vars[i]; if (va.Name == v.Name) { va = v; LV.vars[i] = va; LV.Set(); return; } LV.vars[i] = va; } LV.vars.Add(v); } else { for (int i = 0; i < GV.vars.LongCount(); i++) { VariablesStruct va = GV.vars[i]; if (va.Name == v.Name) { va = v; GV.vars[i] = va; GV.Set(); return; } GV.vars[i] = va; } GV.vars.Add(v); } } }
public List <string> FOR(List <string> Lines) { List <string> _prog = new List <string>(); string openclose = ""; int count = 0; while (!(Lines[0].IndexOf(Refer.For) > -1) && (Lines[0].IndexOf(Refer.Do) > -1) && Lines.LongCount() > 0) { Lines.RemoveAt(0); } string[] args = Lines[0].Substring(Lines[0].IndexOf("(") + 1, Lines[0].LastIndexOf(")") - 1 - Lines[0].IndexOf("(")).Split(';'); if ((int)(args.LongCount()) != 3) { ExM.Get(Refer.Print).DynamicInvoke(Refer.ErrorHead + Refer.ErrorFor + "" + Refer.Do); return(null); } //prog.RemoveAt(0); if (Vars.Replace(args[0]) == args[0]) { Variables.VariablesStruct v = new Variables.VariablesStruct(); v.Type = "Local"; v.Name = args[0]; v.Value = args[1]; Vars.VarAdd(v); } for (; Cond.IsTrue("(" + args[0].Replace(" ", "") + " != " + args[2].Replace(" ", "") + ")");) { Task.Delay(10); if (Lines[count].IndexOf(Refer.End) > -1) { openclose += "{"; } //prog.RemoveAt(0); count++; if (Lines[count].IndexOf(Refer.Do) > -1 && Lines[count].IndexOf(Refer.Then) > -1) { openclose += "{"; } _prog = new List <string>(); foreach (string s in Lines) { _prog.Add(s); } while ((_prog[count].IndexOf(Refer.Then) == -1 && _prog[count].IndexOf(Refer.Do) == -1) && openclose != "{") { if (_prog[count].IndexOf(Refer.End) > -1) { _prog[count] = _prog[count].Replace(Refer.End, " "); openclose += "}"; openclose = openclose.Replace("{}", ""); if (openclose == "") { break; } } _prog[count] = _prog[count].Replace(Refer.Else, "").Replace(Refer.If, "").Replace(Refer.For, "").Replace(Refer.While, "").Replace(Refer.Then, "").Replace(Refer.Do, ""); if (_prog[0].IndexOf(Refer.Return) > -1) { return(new List <string> { _prog[0] }); } Ex.Execute(_prog[count]); count++; //_prog.RemoveAt(count); if (_prog.LongCount() - count == 1)// 1 for the "end" line { //Vars.VarRem(args[0]); //count = 0; break; } } if (_prog[count].IndexOf(Refer.If) > -1 && _prog[count].IndexOf(Refer.Then) > -1) { List <string> pro = new List <string>(); for (int i = 0; count + i < _prog.LongCount(); i++) { pro.Add(_prog[i + count]); } pro = IF.IF(pro); if (pro[0].IndexOf(Refer.Return) > -1) { return(new List <string> { pro[0] }); } for (int j = 0; j < pro.LongCount(); j++) { count++; } //prog.RemoveAt(count); prog.Add(pro[j]); } if (_prog[count].IndexOf(Refer.For) > -1 && _prog[count].IndexOf(Refer.Do) > -1) { List <string> pro = new List <string>(); for (int i = 0; count + i < _prog.LongCount(); i++) { pro.Add(Lines[i + count]); } pro = FOR(pro); if (pro[0].IndexOf(Refer.Return) > -1) { return(new List <string> { pro[0] }); } for (int j = 0; j < pro.LongCount(); j++) { count++; } } if (_prog[count].IndexOf(Refer.While) > -1 && _prog[count].IndexOf(Refer.Do) > -1) { List <string> pro = new List <string>(); for (int i = 0; count + i < _prog.LongCount(); i++) { pro.Add(Lines[i + count]); } pro = WHILE.WHILE(pro); if (pro[0].IndexOf(Refer.Return) > -1) { return(new List <string> { pro[0] }); } for (int j = 0; j < pro.LongCount(); j++) { count++; } } count = 0; //Ex.Execute(_prog[count]); if (Convert.ToInt64(args[1]) < Convert.ToInt64(args[2])) { Ex.Execute(args[0] + "++;"); } else { if (Convert.ToInt64(args[1]) > Convert.ToInt64(args[2])) { Ex.Execute(args[0] + "--;"); } } } if (_prog.LongCount() > 0) { _prog.RemoveAt(0); } Vars.VarRem(args[0]); return(_prog); }
private bool LineInter(string Line) { #region set Local var if (Line.IndexOf(Refer.Local) > -1 && Line.IndexOf("=") > -1) { Variables.VariablesStruct vs = new Variables.VariablesStruct(); vs.Name = Line.Substring(Line.Substring(Line.IndexOf(Refer.Local)).IndexOf(" "), Line.IndexOf("=") - (Line.Substring(Line.IndexOf(Refer.Local)).IndexOf(" "))).Replace(" ", ""); Line = Vars.Replace(Line); vs.Value = Line.Substring(Line.IndexOf("=") + 1).Replace(";", ""); vs.Type = "Local"; if (isNumeric((string)vs.Value)) { try { vs.Value = Evaluate((string)vs.Value); } catch (Exception e) { Ex.Get(Refer.Print).DynamicInvoke(Refer.ErrorHead + e.ToString()); } } Vars.VarAdd(vs); return(true); } #endregion #region set Global var if (Line.IndexOf(Refer.Global) > -1 && Line.IndexOf("=") > -1) { Variables.VariablesStruct vs = new Variables.VariablesStruct(); vs.Name = Line.Substring(Line.Substring(Line.IndexOf(Refer.Global)).IndexOf(" "), Line.IndexOf("=") - (Line.Substring(Line.IndexOf(Refer.Global)).IndexOf(" "))).Replace(" ", ""); Line = Vars.Replace(Line); vs.Value = Line.Substring(Line.IndexOf("=") + 1).Replace(";", ""); vs.Type = "Global"; if (isNumeric((string)vs.Value)) { try { vs.Value = Evaluate((string)vs.Value); } catch (Exception e) { Ex.Get(Refer.Print).DynamicInvoke(Refer.ErrorHead + e.ToString()); } } Vars.VarAdd(vs); return(true); } #endregion #region set var if (Line.IndexOf("=") > -1) { Variables.VariablesStruct vs = new Variables.VariablesStruct(); vs.Name = Line.Substring(0, Line.IndexOf("=")).Replace(" ", ""); Line = Vars.Replace(Line); vs.Value = Line.Substring(Line.IndexOf("=") + 1).Replace(";", ""); vs.Type = "Local"; if (isNumeric((string)vs.Value)) { try { vs.Value = Evaluate((string)vs.Value); } catch (Exception e) { Ex.Get(Refer.Print).DynamicInvoke(Refer.ErrorHead + e.ToString()); } } Vars.VarAdd(vs); return(true); } #endregion return(false); }