public void Visit(Opposition opposition) { stringBuilder.Append("("); stringBuilder.Append("-"); opposition.Children[0].Accept(this); stringBuilder.Append(")"); }
private static IExpression ReadPart() { IExpression node; List <IExpression> children = new List <IExpression>(); switch (tokens[index]) { case "+": ++index; children.Add(ReadPart()); ++index; children.Add(ReadPart()); node = new Addition(children.ToArray()); return(node); case "-": ++index; children.Add(ReadPart()); ++index; children.Add(ReadPart()); node = new Subtraction(children.ToArray()); return(node); case "*": ++index; children.Add(ReadPart()); ++index; children.Add(ReadPart()); node = new Multiplication(children.ToArray()); return(node); case "/": ++index; children.Add(ReadPart()); ++index; children.Add(ReadPart()); node = new Division(children.ToArray()); return(node); case "~": ++index; children.Add(ReadPart()); node = new Opposition(children.ToArray()); return(node); default: int value = int.Parse(tokens[index]); node = new Literal(value); return(node); } }
public void Visit(Opposition opposition) { int temp = currentPriority; if (temp > 3) { stringBuilder.Append("("); } currentPriority = 3; stringBuilder.Append("-"); opposition.Children[0].Accept(this); if (temp > 3) { stringBuilder.Append(")"); } currentPriority = temp; }
public void Visit(Opposition opposition) { opposition.Children[0].Accept(this); MidValue = checked (-MidValue); }