static Coin GetCoin(Term t) { if (t.ToString().Equals("Coin(\"Nickel\")")) return Coin.Nickel; else if (t.ToString().Equals("Coin(\"Dime\")")) return Coin.Dime; else throw new ArgumentException("Unrecognized coin: " + t.ToString()); }
/// <summary> /// Prints a string "f(1, "abc", File(1))" given the abstract syntax representation of a term. /// </summary> /// <param name="term">The abstract syntax tree representation of the term</param> /// <returns>The text representation of the term</returns> public static string Write(Term /*?*/ term) { return(term == null ? "null" : term.ToString()); }
/// <summary> /// Add tooltip with state variables values /// /// </summary> /// <param name="sb"></param> /// <param name="node"></param> private void AddNodeTooltip(StringBuilder sb, Node node) { sb.Append("[tooltip = \""); // Create string for the tooltip StringBuilder sTooltip = new StringBuilder(); if (finiteAutomatonContext.stateProvider != null) sTooltip.Append( DefaultNodeTooltip(finiteAutomatonContext.stateProvider(node)) ); else sTooltip.Append("//Variables in state " + node.ToString() + " are undefined"); // Remove quotes in sTooltip sTooltip.Replace("\"", ""); sb.Append(sTooltip); sb.Append("\"];"); // Remove the last 3 dots at the end of a line in sb //sb.Replace(" . . . \"", "\""); }
/// <summary> /// Interpret the term as a .NET value in this context /// </summary> public IComparable InterpretTerm(Term term) { Any a = term as Any; if (a != null) { return a; } Literal l = term as Literal; if (l != null) { return l.Value; } //IComparable result; CompoundTerm ct = term as CompoundTerm; if (ct != null) { Symbol sort = ct.Symbol; // Case 1: Quoted term. No evaluation needed if (quoteSymbol.Equals(sort)) { return ct.Arguments.Head; } // Case 2: reconstruct value from sort. else { int arity = ct.Arguments.Count; ValueConstructor ctor = GetValueConstructor(sort, arity); Sequence<IComparable> args = ct.Arguments.Convert<IComparable>(InterpretTerm); return ctor(args); } } throw new ArgumentException("Can't interpret term " + term.ToString()); }
internal static string ConstructEdgeLabel(Term term) { if (term == null) return ""; CompoundTerm action = term as CompoundTerm; if (action == null) return term.ToString(); if (IsStartAction(action)) return GetActionLabel(action, null); if (IsFinishAction(action)) return GetActionLabel(null, action); return term.ToString(); }
/// <summary> /// Prints a string "f(1, "abc", File(1))" given the abstract syntax representation of a term. /// </summary> /// <param name="term">The abstract syntax tree representation of the term</param> /// <returns>The text representation of the term</returns> public static string Write(Term/*?*/ term) { return term == null ? "null" : term.ToString(); }