public override Value Handle(Expression left, Expression right, IDictionary<String, Value> symbols) { var l = left.Interpret(symbols); var symbol = right as SymbolExpression; var value = default(StringValue); //Is it a Method Call? if (symbol == null) { var contExp = right as ContainerExpression; if (contExp != null) { if (contExp.Expressions != null && contExp.Expressions.Length == 1 && contExp.Expressions[0] is SymbolExpression) { symbol = contExp.Expressions[0] as SymbolExpression; var op = contExp.Operator as ArgsOperator; if (op != null) { return op.Handle(symbol, symbols, l); } //YAMPMemberFunctionMissingException } } } if (symbol != null) { value = new StringValue(symbol.SymbolName); } if (value == null) throw new YAMPFunctionMissingException("()"); return Perform(l, value); }
public ScalarValue Function(StringValue octstr) { var sum = 0; var hex = new Stack<Int32>(); var weight = 1; for (var i = 1; i <= octstr.Length; i++) { var chr = octstr[i]; if (!ParseEngine.IsWhiteSpace(chr) && !ParseEngine.IsNewLine(chr)) { if (chr >= '0' && chr <= '7') { hex.Push((Int32)(chr - '0')); } else { throw new YAMPRuntimeException("oct2dec can only interpret octal strings."); } } } while (hex.Count != 0) { var el = hex.Pop(); sum += weight * el; weight *= 8; } return new ScalarValue(sum); }
public SetValue Function(StringValue name, ArgumentsValue args) { var set = new SetValue(name.Value, null, true); int iArgs = 1; //First is "name" foreach (var arg in args) { iArgs++; if (arg is MatrixValue) { set.AddElements((arg as MatrixValue).ToArray()); } else if (arg is StringValue) { set.Set.Add((arg as StringValue).Value); } else if (arg is NumericValue) { set.Set.Add(arg as NumericValue); } else throw new YAMPArgumentInvalidException("Element is not ScalarValue, StringValue or MatrixValue", iArgs); } return set; }
public StringValue Function(StringValue type) { var sb = new StringBuilder(); sb.AppendLine("Defined for any plot:"); var plotSettings = Context.GetDefaultProperties("plot"); foreach (var pair in plotSettings) { sb.Append("-\t").Append("Name: "); sb.AppendLine(pair.Key); sb.Append("\t").Append("Value: "); sb.AppendLine(pair.Value.ToString()); } sb.AppendLine("Defined for any series:"); var seriesSettings = Context.GetDefaultProperties("series"); foreach (var pair in seriesSettings) { sb.Append("-\t").Append("Name: "); sb.AppendLine(pair.Key); sb.Append("\t").Append("Value: "); sb.AppendLine(pair.Value.ToString()); } return new StringValue(sb.ToString()); }
public void Function(StringValue type) { var stec = new StringToEnumConverter(typeof(DisplayStyle)); var value = stec.Convert(type); Context.DefaultDisplayStyle = (DisplayStyle)value; Context.RaiseNotification(new NotificationEventArgs(NotificationType.Information, "Display format changed to " + value + ".")); }
public StringValue Function(StringValue message) { var handle = new ManualResetEvent(false); var e = new UserInputEventArgs(handle, message.Value); Context.RaiseInputPrompt(e); handle.WaitOne(); return new StringValue(e.Input); }
public StringValue Function(StringValue filter) { var regex = new Regex("^" + Regex.Escape(filter.Value).Replace("\\*", ".*").Replace("\\?", ".{1}") + "$"); var sb = new StringBuilder(); var variables = Context.AllVariables.Keys.Where(m => regex.IsMatch(m)).OrderBy(m => m).AsEnumerable(); foreach (var variable in variables) { sb.AppendLine(variable); } return new StringValue(sb.ToString()); }
public override Value Handle(Expression left, Expression right, IDictionary<String, Value> symbols) { var l = left.Interpret(symbols); var r = new StringValue(End) as Value; var symbol = right as SymbolExpression; if (symbol == null || !symbol.SymbolName.Equals(End)) { r = right.Interpret(symbols); } return Perform(l, r); }
public Value Handle(Expression left, Expression right, Value value, IDictionary<String, Value> symbols) { var obj = left.Interpret(symbols) as ObjectValue; var symbol = right as SymbolExpression; if (obj == null || symbol == null) { throw new YAMPOperationInvalidException(Op); } var key = new StringValue(symbol.SymbolName); return obj.Perform(Context, key, value); }
public SetValue Function(StringValue expression, ScalarValue size, ScalarValue maxVal, ScalarValue ordered) { SetValue set = new SetValue(expression.Value, null, ordered.Value != 0); Random rnd = new Random(); int tot = (int)size.Value; for (int i = 0; i < tot; i++) { set.Set.Add(new ScalarValue(rnd.Next((int)maxVal.Value))); } return set; }
public void Function(StringValue type, StringValue property, Value value) { switch(type.Value.ToLower()) { case "plot": Function(property, value); break; case "series": Context.SetDefaultProperty("series", property.Value, value); break; default: throw new YAMPPropertyMissingException(type.Value, new[] { "Plot", "Series" }); } }
public StringValue Function(StringValue topic) { var docu = Documentation.Create(Context); if (docu.ContainsEntry(topic.Value)) { var entry = docu.Get(topic.Value); var sb = new StringBuilder(); sb.Append(" ").AppendLine(entry.Name).AppendLine("--------------"); sb.AppendLine().AppendLine("Description:").Append("\t").AppendLine(entry.Description); if (entry is HelpFunctionSection) { var fe = entry as HelpFunctionSection; foreach (var usage in fe.Usages) { var i = 1; sb.AppendLine(); sb.AppendLine("** Usage **").Append("\t").AppendLine(usage.Usage); sb.AppendLine("** Description **").Append("\t").AppendLine(usage.Description); sb.AppendLine("** Arguments **").Append("\t").AppendLine(string.Join(", ", usage.Arguments.ToArray())); sb.AppendLine("** Returns **"); foreach (var ret in usage.Returns) { sb.Append("\t").AppendLine(ret); } foreach (var example in usage.Examples) { sb.AppendFormat(" ({0}) Example:", i).AppendLine(); sb.Append("\t").Append("-> Call: ").AppendLine(example.Example); sb.Append("\t").Append("-> Description: ").AppendLine(example.Description); i++; } } } return new StringValue(sb.ToString()); } else { return new StringValue(String.Format("The specified entry was not found. Did you mean {0}?", docu.ClosestEntry(topic.Value))); } }
public Value Function(StringValue code) { var c = new ParseContext(Context); var q = new QueryContext(c, code.Value); var p = new ParseEngine(q, c).Parse(); if (p.CanRun) { foreach (var statement in p.Statements) { return statement.Interpret(new Dictionary<String, Value>()); } } return new StringValue(); }
public ScalarValue Function(StringValue action) { switch (action.Value.ToLower()) { case "reset": Reset(); break; case "stop": Stop(); break; case "start": Start(); break; } return Function(); }
public ScalarValue Function(StringValue binarystr) { var sum = 0; var binary = new Stack<Boolean>(); var weight = 1; for (var i = 1; i <= binarystr.Length; i++) { var chr = binarystr[i]; if (!ParseEngine.IsWhiteSpace(chr) && !ParseEngine.IsNewLine(chr)) { if (chr == '0') { binary.Push(false); } else if (chr == '1') { binary.Push(true); } else { throw new YAMPRuntimeException("bin2dec can only interpret binary strings."); } } } while (binary.Count != 0) { var el = binary.Pop(); if (el) { sum += weight; } weight *= 2; } return new ScalarValue(sum); }
public SetValue Function(StringValue expression, ScalarValue size, ScalarValue maxVal) { return Function(expression, size, maxVal, new ScalarValue(0)); }
public ArgumentsValue Function(StringValue text, ArgumentsValue args) { var separators = args.Select(v => v.ToString()).ToArray(); var tokens = text.ToString().Split(separators, StringSplitOptions.RemoveEmptyEntries); return new ArgumentsValue(tokens.Select(s => new StringValue(s)).ToArray()); }
public void Function(PlotValue plot, ScalarValue series, StringValue property, Value newValue) { if (plot.Count == 0) throw new YAMPNoSeriesAvailableException("The given plot contains no series."); var n = series.GetIntegerOrThrowException("series", Name); if (n < 1 || n > plot.Count) throw new YAMPArgumentRangeException("series", 1, plot.Count); AlterSeriesProperty(plot, n - 1, property.Value, newValue); plot.UpdateProperties(); Context.RaiseNotification(new NotificationEventArgs(NotificationType.Success, "Series " + n + " changed.")); }
public void Function(MatrixValue series, StringValue property, Value newValue) { if (Context.LastPlot == null) { Context.RaiseNotification(new NotificationEventArgs(NotificationType.Failure, "No plot available... Nothing changed.")); } else { Function(Context.LastPlot, series, property, newValue); } }
public void Function(StringValue source, StringValue target) { File.Copy(source.Value, target.Value); Parser.RaiseNotification(Context, new NotificationEventArgs(NotificationType.Success, string.Format("Copied {0} to {1}.", source.Value, target.Value))); }
Value SetValue(StringValue key, Value value) { var name = key.Value; _values[name] = value; return value; }
public void Function(StringValue text, ArgumentsValue args) { var content = String.Format(text.Value, args.ToArray()); Context.RaiseNotification(new NotificationEventArgs(NotificationType.Message, content)); }
public void Function(StringValue filename, ArgumentsValue args) { if (!File.Exists(filename.Value)) { throw new YAMPFileNotFoundException(filename.Value); } var error = false; var v = Load(filename.Value, out error); var count = 0; if (!error) { foreach (var arg in args.Values) { if (arg is StringValue) { var name = (arg as StringValue).Value; if (v.ContainsKey(name)) { Context.AssignVariable(name, v[name] as Value); count++; } } } } if (error) { var table = ImageLoad(filename.Value, out error); if (!error) { var name = "image"; if (args.Length > 0 && args.Values[0] is StringValue) { name = (args.Values[0] as StringValue).Value; } else { var suffix = -1; do { suffix++; }while (Context.Variables.ContainsKey(name + suffix)); name = name + suffix; } Context.AssignVariable(name, table); count = 1; } } if (error) { var table = ASCIILoad(filename.Value, out error); if (!error) { var name = "data"; if (args.Length > 0 && args.Values[0] is StringValue) { name = (args.Values[0] as StringValue).Value; } else { var suffix = -1; do { suffix++; }while (Context.Variables.ContainsKey(name + suffix)); name = name + suffix; } Context.AssignVariable(name, table); count = 1; } } if (error) { throw new YAMPFileFormatNotSupportedException(filename.Value); } Notify(count); }
public ScalarValue Function(StringValue str) { return new ScalarValue(str.Length); }
public void Function(StringValue filename) { if (!File.Exists(filename.Value)) { throw new YAMPFileNotFoundException(filename.Value); } var error = false; var v = Load(filename.Value, out error); var count = 0; if (!error) { foreach (var key in v.Keys) { Context.AssignVariable(key, v[key]); } count = v.Count; } if (error) { var table = ImageLoad(filename.Value, out error); if (!error) { var suffix = -1; var name = "image"; do { suffix++; }while (Context.Variables.ContainsKey(name + suffix)); Context.AssignVariable(name + suffix, table); count = 1; } } if (error) { var table = ASCIILoad(filename.Value, out error); if (!error) { var suffix = -1; var name = "data"; do { suffix++; }while (Context.Variables.ContainsKey(name + suffix)); Context.AssignVariable(name + suffix, table); count = 1; } } if (error) { throw new YAMPFileFormatNotSupportedException(filename.Value); } Notify(count); }
public StringValue Function(StringValue text, ArgumentsValue args) { return new StringValue(String.Format(text.Value, args.ToArray())); }
/// <summary> /// Creates a new unit value. /// </summary> /// <param name="value">The value to represent.</param> /// <param name="unit">The unit to hold.</param> public UnitValue(ScalarValue value, StringValue unit) : this(value.Re, unit.Value) { }
public void Function(PlotValue plot, StringValue property, Value newValue) { var propertyName = property.Value; AlterProperty(plot, propertyName, newValue); plot.RaisePlotChanged(propertyName); Context.RaiseNotification(new NotificationEventArgs(NotificationType.Success, "Property changed")); }
Value GetValue(StringValue key) { var name = key.Value; var value = default(Value); if (_values.TryGetValue(name, out value)) { return value; } return new ObjectValue(); }
public void Function(PlotValue plot, MatrixValue series, StringValue property, Value newValue) { var s = new List<String>(); if (series is RangeValue) { var r = series as RangeValue; var step = (Int32)r.Step; var end = r.All ? plot.Count : (Int32)r.End; for (var j = (Int32)r.Start; j <= end; j += step) { s.Add(j.ToString()); AlterSeriesProperty(plot, j - 1, property.Value, newValue); } } else { var end = series.Length; for (var i = 1; i <= end; i++) { var n = series[i].GetIntegerOrThrowException("series", Name); s.Add(n.ToString()); AlterSeriesProperty(plot, n - 1, property.Value, newValue); } } Context.RaiseNotification(new NotificationEventArgs(NotificationType.Failure, "Series " + String.Join(", ", s.ToArray()) + " changed.")); plot.UpdateProperties(); }
public UnitValue Function(ScalarValue value, StringValue unit) { return new UnitValue(value, unit.Value); }
public void Function(StringValue property, Value value) { Context.SetDefaultProperty("plot", property.Value, value); }
public void Function(StringValue filename, StringValue filetype) { var type = (FileType)(new YAMP.Converter.StringToEnumConverter(typeof(FileType)).Convert(filetype)); var error = false; var count = 0; switch (type) { case FileType.Text: var table = ASCIILoad(filename.Value, out error); if (!error) { var suffix = -1; var name = "data"; do { suffix++; }while (Context.Variables.ContainsKey(name + suffix)); Context.AssignVariable(name + suffix, table); count = 1; } break; case FileType.Image: var data = ImageLoad(filename.Value, out error); if (!error) { var suffix = -1; var name = "image"; do { suffix++; }while (Context.Variables.ContainsKey(name + suffix)); Context.AssignVariable(name + suffix, data); count = 1; } break; case FileType.Binary: var v = Load(filename.Value, out error); if (!error) { foreach (var key in v.Keys) { Context.AssignVariable(key, v[key]); } count = v.Count; } break; } if (error) { throw new YAMPFileFormatNotSupportedException(filename.Value); } Notify(count); }