Esempio n. 1
0
 private static void ToString(Expression x, StringBuilder sb)
 {
     if (x is OpNode)
     {
         OpNode o = (OpNode)x;
         sb.Append("(");
         ToString(o.leftChild, sb);
         sb.Append(o.GetSymbol());
         ToString(o.rightChild, sb);
         sb.Append(")");
     }
     else
     {
         if (x is TermNode)
         {
             TermNode t = (TermNode)x;
             if (t.GetNegate())
             {
                 sb.Append("(");
                 sb.Append("-");
             }
             sb.Append(t.GetName());
             if (t is FuncNode)
             {
                 FuncNode f = (FuncNode)t;
                 sb.Append("(");
                 if (f.NumChildren() > 0)
                 {
                     ToString(f.Child(0), sb);
                 }
                 for (int i = 1; i < f.NumChildren(); i++)
                 {
                     sb.Append(", ");
                     ToString(f.Child(i), sb);
                 }
                 sb.Append(")");
             }
             if (t.GetNegate())
             {
                 sb.Append(")");
             }
         }
         else
         {
             if (x is ValNode)
             {
                 sb.Append(((ValNode)x).val);
             }
         }
     }
 }
Esempio n. 2
0
 private static void GetTermNames(Expression x, Bag b, bool varNames)
 {
     if (x is OpNode)
     {
         OpNode o = (OpNode)x;
         GetTermNames(o.leftChild, b, varNames);
         GetTermNames(o.rightChild, b, varNames);
     }
     else
     {
         if (x is VarNode)
         {
             if (varNames)
             {
                 VarNode v = (VarNode)x;
                 if (!b.Contains(v.name))
                 {
                     b.Add(v.name);
                 }
             }
         }
         else
         {
             if (x is FuncNode)
             {
                 FuncNode f = (FuncNode)x;
                 if (!varNames)
                 {
                     if (!b.Contains(f.name))
                     {
                         b.Add(f.name);
                     }
                 }
                 for (int i = 0; i < f.NumChildren(); i++)
                 {
                     GetTermNames(f.Child(i), b, varNames);
                 }
             }
         }
     }
 }