private GSCore ExecuteElementWithoutreport(GSCore E) { if (E is GSList) { GSList L = (GSList)E; if (L.Count == 0) { return(GSCore.Void); } else if (L.Count == 1) { return(ExecuteElement(L[0])); } else { if (L.Parts.IsFirstToken()) { GSCore res = null; try { res = ExecuteMessage(L.Parts.getFirstToken(), L.Parts.getSublist(1)); } catch { res = new GSString(); } finally { } return(res); } else { GSCore result = null; foreach (GSCore item in L.Parts) { result = ExecuteElement(item); if (result is GSReturn) { break; } } if (result == null) { return(new GSString()); } return(result); } } } else if (E is GSToken) { return(EvaluateProperty(((GSToken)E).Token)); } else { return(E); } }
/// <summary> /// Reading text with text template /// Lines starting with ## are comments /// Lines starting with # are program /// Other lines are printed to output /// </summary> /// <param name="text"></param> public void readTextTemplate(String text) { Parts.Clear(); Parent = this; StringReader sr = new StringReader(text); String line = null; GSList currentList = this; while ((line = sr.ReadLine()) != null) { if (line.StartsWith("#")) { readTextListLine(line.Substring(1), ref currentList); } else { GSList list = currentList.createAndAddSublist(); list.Add(new GSToken() { Token = "println" }); list.Add(new GSString() { Value = line }); } } }
public GSList createAndAddSublist() { GSList list = new GSList() { Parent = this }; Parts.Add(list); return(list); }
private GSCore execForeach(GSCoreCollection args) { if (args.Count < 4) { Debugger.Log(0, "", "Insufficient arguments for (FOREACH varName : list commands ) "); return(null); } GSCore t1 = args.getSafe(0); GSCore l1 = ExecuteElement(args.getSafe(2)); if (!(t1 is GSToken)) { Debugger.Log(0, "", "Token shoudl be second argument in FOREACH "); return(null); } if (!(l1 is GSList)) { Debugger.Log(0, "", "List should be fourth argument in FOREACH "); return(null); } GSToken tk = (GSToken)t1; GSList lst = (GSList)l1; GSCore r = null; int ik = 0; foreach (GSCore item in lst.Parts) { SetVariable(tk.Token, item); for (int i = 3; i < args.Count; i++) { r = ExecuteElement(args.getSafe(i)); if (r is GSReturn) { break; } } ik++; if (r is GSReturn) { GSReturn ret = r as GSReturn; if (ret.Type == GSReturn.TYPE_BREAK) { break; } if (ret.Type == GSReturn.TYPE_RETURN) { return(ret); } } } return(new GSNumber(ik)); }
/// <summary> /// Reading text with script /// Lines starting with # are comments /// Other lines are program /// </summary> /// <param name="text"></param> public void readList(String text) { Parts.Clear(); Parent = this; StringReader sr = new StringReader(text); String line = null; GSList currentList = this; while ((line = sr.ReadLine()) != null) { readTextListLine(line, ref currentList); } }
/// <summary> /// reading one line /// </summary> /// <param name="line"></param> /// <param name="currentList"></param> public void readTextListLine(string line, ref GSList currentList) { // if line starts with #, then if (line.TrimStart().StartsWith("#")) { return; } int mode = 0; StringBuilder part = new StringBuilder(); foreach (char C in line) { if (mode == 0) { if (char.IsWhiteSpace(C)) { } else if (C == '\'') { mode = 1; } else if (C == '\"') { mode = 3; } else if (C == '(') { currentList = currentList.createAndAddSublist(); } else if (C == ')') { currentList = currentList.Parent; } else { part.Append(C); mode = 2; } } else if (mode == 1) { if (char.IsWhiteSpace(C) || C == ')') { currentList.Add(new GSString() { Value = part.ToString() }); part.Clear(); mode = 0; if (C == ')') { currentList = currentList.Parent; } } else { part.Append(C); } } else if (mode == 2) { if (char.IsWhiteSpace(C) || C == ')') { double d; int i; string value = part.ToString(); if (double.TryParse(value, out d)) { currentList.Add(new GSNumber() { DoubleValue = d }); } else if (int.TryParse(value, out i)) { currentList.Add(new GSNumber() { IntegerValue = i }); } else { currentList.Add(new GSToken() { Token = part.ToString() }); } part.Clear(); mode = 0; if (C == ')') { currentList = currentList.Parent; } } else { part.Append(C); } } else if (mode == 3) { if (C == '\"') { currentList.Add(new GSString(part.ToString())); part.Clear(); mode = 0; } else if (C == '\\') { mode = 4; } else { part.Append(C); } } else if (mode == 4) { part.Append(C); mode = 3; } } if (part.Length > 0) { if (mode == 1) { currentList.Add(new GSString() { Value = part.ToString() }); } else { double d; int i; string value = part.ToString(); if (double.TryParse(value, out d)) { currentList.Add(new GSNumber() { DoubleValue = d }); } else if (int.TryParse(value, out i)) { currentList.Add(new GSNumber() { IntegerValue = i }); } else { currentList.Add(new GSToken() { Token = part.ToString() }); } } } }