public override void Evaluate() { // External functions are now handled within expressions, // so simply execute the expression and throw away the value Expression subEx = new Expression(RegexMatch.Groups[1].Value, this); subEx.GetValue(); State = ExecutionState.DONE; }
public override void Evaluate() { string varname = RegexMatch.Groups[1].Value; Expression expression = new Expression(RegexMatch.Groups[2].Value, ParentContext); ParentContext.Unlock(varname); ParentContext.Lock(varname, expression); State = ExecutionState.DONE; }
public override void Evaluate() { targetExpression = new Expression(RegexMatch.Groups[1].Value, ParentContext); targetCommand = Command.Get(RegexMatch.Groups[2].Value, ParentContext); if (!objToBool(targetExpression.GetValue(), out originalValue)) { throw new kOSException("Value type error"); } ParentContext.Lock(this); State = ExecutionState.DONE; }
public override void Evaluate() { Expression e = new Expression(RegexMatch.Groups[1].Value, ParentContext); if (e.IsNull()) { StdOut("NULL"); State = ExecutionState.DONE; } else { StdOut(e.ToString()); State = ExecutionState.DONE; } }
public override void Evaluate() { Expression ex = new Expression(RegexMatch.Groups[1].Value, this); object obj = ex.GetValue(); if (obj is kOS.Node) { ((Node)obj).Remove(); } else { throw new kOSException("Supplied object ineligible for removal", this); } State = ExecutionState.DONE; }
public override void Evaluate() { String name = RegexMatch.Groups[1].Value; String paramString = RegexMatch.Groups[2].Value; var parameters = new List<String>(); foreach (String param in Utils.ProcessParams(paramString)) { Expression subEx = new Expression(param, this); parameters.Add(subEx.GetValue().ToString()); } CallExternalFunction(name, parameters.ToArray()); State = ExecutionState.DONE; }
public override void Evaluate() { Expression e = new Expression(RegexMatch.Groups[1].Value, ParentContext); Expression ex = new Expression(RegexMatch.Groups[2].Value, ParentContext); Expression ey = new Expression(RegexMatch.Groups[3].Value, ParentContext); if (e.IsNull()) throw new kOSException("Null value in print statement"); int x, y; if (Int32.TryParse(ex.GetValue().ToString(), out x) && Int32.TryParse(ey.GetValue().ToString(), out y)) { Put(e.GetValue().ToString(), x, y); } else { throw new kOSException("Non-numeric value assigned to numeric function"); } State = ExecutionState.DONE; }
public override void Evaluate() { Expression e = new Expression(RegexMatch.Groups[2].Value, ParentContext); bool untilClause = (RegexMatch.Groups[1].Value.Trim().ToUpper() == "UNTIL"); if (!untilClause) { waitTime = e.Float(); } else { waitExpression = e; } State = ExecutionState.WAIT; }
public override void Lock(string name, Expression expression) { if (ParentContext != null) ParentContext.Lock(name, expression); }
private double ParseSubExpressionAsDouble(String input) { double val = 0; if (double.TryParse(input, out val)) { return val; } else { var expValue = new Expression(input, executionContext).GetValue(); if (expValue is double) { return (double)expValue; } else if (double.TryParse(expValue.ToString(), out val)) { return val; } else { throw new kOSException("Non-numeric parameter used on a numeric function"); } } }
private bool TryParseSuffix(string text) { Match match = Regex.Match(text, "^([A-Z0-9_\\-]+?):([A-Z0-9_\\-]+?)$", RegexOptions.IgnoreCase); if (match.Success) { var obj = new Expression(match.Groups[1].Value, executionContext).GetValue(); if (obj is SpecialValue) { SpecialValue = (SpecialValue)obj; Suffix = match.Groups[2].Value.ToUpper(); Value = SpecialValue.GetSuffix(Suffix); return true; } } return false; }
public override void Evaluate() { expression = new Expression(RegexMatch.Groups[1].Value, ParentContext); int numLinesChild = Utils.NewLineCount(Input.Substring(0, RegexMatch.Groups[2].Index)); targetCommand = Get(RegexMatch.Groups[2].Value, this, Line + numLinesChild); if (expression.IsTrue()) { targetCommand.Evaluate(); Push(targetCommand); State = ExecutionState.WAIT; } else { State = ExecutionState.DONE; } }
// Evaluate a part of an expression private bool Eval(ref String text) { // Eval mathematical parts foreach (String op in OperatorList) { for (int i = 0; i < text.Length; i++) { if (text.Substring(i, 1) == "<") { // Special case: is this less than or start of angle quote? var regex = new Regex("^<[A-Za-z0-9]+?>"); // Make sure that there are no math symbols between start and end brace var match = regex.Match(text.Substring(i)); if (match.Success) { // This is angle brackets, move to end bracket i += match.Groups[0].Length; } } if (text.Substring(i, 1) == "\"") { // String detected, jump to end i = FindEndOfString(text, i + 1); } else if (text.Substring(i, 1) == "(") { i = FindEndOfBracket(text, i); } else if (i <= text.Length - op.Length && op == text.Substring(i, op.Length).ToUpper()) { Operator = op; // If this is a minus, and it comes right after an operator or is the beginning of the string, it's really a sign operator string prev = text.Substring(0, i); bool isSign = (op == "-" && (EndsWithOperator(prev) || String.IsNullOrEmpty(prev.Trim()))); if (!isSign) { String leftString = text.Substring(0, i); String rightString = text.Substring(i + op.Length); LeftSide = new Expression(leftString, executionContext); RightSide = new Expression(rightString, executionContext); Value = GetValue(); return true; } } } } // No operator found! return false; }
public override void Evaluate() { expression = new Expression(RegexMatch.Groups[1].Value, ParentContext); targetCommand = Command.Get(RegexMatch.Groups[2].Value, ParentContext); ParentContext.Lock(this); State = ExecutionState.DONE; }
public override void Evaluate() { expression = new Expression(RegexMatch.Groups[1].Value, ParentContext); targetCommand = Command.Get(RegexMatch.Groups[2].Value, this); if (expression.IsTrue()) { targetCommand.Evaluate(); Push(targetCommand); State = ExecutionState.WAIT; } else { State = ExecutionState.DONE; } }
public override void Evaluate() { waitExpression = new Expression(RegexMatch.Groups[1].Value, ParentContext); commandString = RegexMatch.Groups[2].Value; State = ExecutionState.WAIT; }
public override void Evaluate() { Expression e = new Expression(RegexMatch.Groups[1].Value, ParentContext); StdOut(e.GetValue().ToString()); State = ExecutionState.DONE; }
public override void Evaluate() { Term targetTerm = new Term(RegexMatch.Groups[1].Value); Expression e = new Expression(RegexMatch.Groups[2].Value, ParentContext); if (targetTerm.Type == Term.TermTypes.STRUCTURE) { object baseObj = new Expression(targetTerm.SubTerms[0], ParentContext).GetValue(); if (baseObj is SpecialValue) { if (((SpecialValue)baseObj).SetSuffix(targetTerm.SubTerms[1].Text.ToUpper(), e.GetValue())) { State = ExecutionState.DONE; return; } else { throw new kOSException("Suffix '" + targetTerm.SubTerms[1].Text + "' doesn't exist or is read only", this); } } else { throw new kOSException("Can't set subvalues on a " + Expression.GetFriendlyNameOfItem(baseObj), this); } } else { Variable v = FindOrCreateVariable(targetTerm.Text); if (v != null) { v.Value = e.GetValue(); State = ExecutionState.DONE; return; } } }
public override void Evaluate() { var listName = RegexMatch.Groups[2].Value; iteratorString = RegexMatch.Groups[1].Value; var expression = new Expression(listName, ParentContext).GetValue(); var list = expression as ListValue; iterator = list.GetSuffix("ITERATOR") as Enumerator; int numLinesChild = Utils.NewLineCount(Input.Substring(0, RegexMatch.Groups[2].Index)); targetCommand = Get(RegexMatch.Groups[3].Value, this, Line + numLinesChild); State = ExecutionState.WAIT; }
public override void Evaluate() { String varName = RegexMatch.Groups[1].Value; Variable v = FindOrCreateVariable(varName); if (v != null) { Expression e = new Expression(RegexMatch.Groups[2].Value, ParentContext); v.Value = e.GetValue(); State = ExecutionState.DONE; } else { throw new kOSException("Can't find or create variable '" + varName + "'"); } }
public override void Evaluate() { waitExpression = new Expression(RegexMatch.Groups[1].Value, ParentContext); var numLinesChild = Utils.NewLineCount(Input.Substring(0, RegexMatch.Groups[2].Index)); targetCommand = Get(RegexMatch.Groups[2].Value, this, Line + numLinesChild); //commandString = RegexMatch.Groups[2].Value; State = ExecutionState.WAIT; }
public override void Evaluate() { // Todo: let the user specify a volume "LOG something TO file ON volume" Volume targetVolume = SelectedVolume; // If the archive is out of reach, the signal is lost in space. if (!targetVolume.CheckRange()) { State = ExecutionState.DONE; return; } String targetFile = RegexMatch.Groups[2].Value.Trim(); Expression e = new Expression(RegexMatch.Groups[1].Value, ParentContext); if (e.IsNull()) { State = ExecutionState.DONE; } else { targetVolume.AppendToFile(targetFile, e.ToString()); State = ExecutionState.DONE; } }
private bool EvalBoolean(ref String text) { foreach (String op in SpecialOperatorList) { for (int i = 0; i < text.Length; i++) { var regex = new Regex(op); Match match = Regex.Match(text.Substring(i), op, RegexOptions.IgnoreCase); if (match.Success) { Operator = match.Groups[0].Value.Trim().ToUpper(); String leftString = text.Substring(0, i); String rightString = text.Substring(i + match.Groups[0].Value.Length); LeftSide = new Expression(leftString, executionContext); RightSide = new Expression(rightString, executionContext); Value = GetValue(); return true; } } } // No boolean operator found return false; }
public override void Evaluate() { String fileName = RegexMatch.Groups[1].Value; File file = SelectedVolume.GetByName(fileName); var parameters = new List<Expression>(); if (RegexMatch.Groups.Count > 1) { String paramString = RegexMatch.Groups[3].Value; foreach (String param in Utils.ProcessParams(paramString)) { Expression subEx = new Expression(param, this); parameters.Add(subEx); } } if (file != null) { ContextRunProgram runContext = new ContextRunProgram(this, parameters); Push(runContext); if (file.Count > 0) { runContext.Run(file); State = ExecutionState.WAIT; } else { State = ExecutionState.DONE; } } else { throw new kOSException("File not found '" + fileName + "'."); } }
public static String Evaluate(String text, ExecutionContext context) { Expression e = new Expression(text, context); return e.GetValue().ToString(); }
private bool TryParseSuffix(string text) { Match match = Regex.Match(text, Utils.BuildRegex("*:%"), RegexOptions.IgnoreCase); if (match.Success) { object leftSideResult = new Expression(match.Groups[1].Value, executionContext).GetValue(); String suffixName = match.Groups[2].Value.ToUpper(); if (leftSideResult is SpecialValue) { EvalDlg = delegate() { Value = ((SpecialValue)leftSideResult).GetSuffix(suffixName); }; EvalDlg(); return true; } } return false; }
public virtual void Lock(String name, Expression expression) { name = name.ToLower(); FindOrCreateVariable(name); if (!Locks.ContainsKey(name)) { Locks.Add(name, expression); } }
public override void Evaluate() { // For now only log to the archive. String volumeName = "Archive"; Volume targetVolume = GetVolume(volumeName); // If the archive is out of ranch, the signal is lost in space. if (!targetVolume.CheckRange()) { State = ExecutionState.DONE; return; } String targetFile = RegexMatch.Groups[1].Value.Trim(); Expression e = new Expression(RegexMatch.Groups[2].Value, ParentContext); if (e.IsNull()) { State = ExecutionState.DONE; } else { targetVolume.AppendToName(targetFile, e.ToString()); State = ExecutionState.DONE; } }