//Find and create the leaf with number //(is called every time the number is found) Node Part() { //Number if (splitter.current_sign == Sign.Number) { Node part = new NodeNumber(splitter.parsed_value); //create the node with found value splitter.Move_sign(); //move to the next sign return(part); } //Sin if (splitter.current_sign == Sign.Sin) { Node part = PartSin(); return(part); } //Cos if (splitter.current_sign == Sign.Cos) { Node part = PartCos(); return(part); } //Tg if (splitter.current_sign == Sign.Tg) { Node part = PartTg(); return(part); } //Ctg if (splitter.current_sign == Sign.Ctg) { Node part = PartCtg(); return(part); } //Parenthesis if (splitter.current_sign == Sign.Open) { splitter.Move_sign(); //move to the next sign //Parse sequentially all the expression after the ( Node part = PlusMinus(); // Find the ) if (splitter.current_sign != Sign.Close) //if there's no ) { Console.WriteLine("Missing close parenthesis"); } splitter.Move_sign(); //move to the next sign return(part); } //If the sign is not classified Console.WriteLine($"Unknown sign: {splitter.current_sign}"); throw new SystemException($"Unknown sign: {splitter.current_sign}"); }
Node PartCtg() { splitter.Move_sign(); //move to the next sign if (OpenParenthesis()) { splitter.Move_sign(); //Parse sequentially all the expression after the ( Node inside = PlusMinus(); // Find the ) if (CloseParenthesis()) { double res = 1 / Math.Tan(inside.Calculate()); Node part = new NodeNumber(res); //create the node with value of sin splitter.Move_sign(); //move to the next sign return(part); } } return(null); }
public CreateOperation(NodeNumber A, NodeNumber B, Operation O) { a = A; b = B; op = O; }
Node Part() { //1 if (splitter.current_sign == Sign.One) { Node part = new NodeNumber(1); //create the node with found value splitter.Move_sign(); //move to the next sign return(part); } //0 if (splitter.current_sign == Sign.Zero) { Node part = new NodeNumber(0); //create the node with found value splitter.Move_sign(); //move to the next sign return(part); } //! if (splitter.current_sign == Sign.Not) { splitter.Move_sign(); //move to the next sign if (splitter.current_sign == Sign.One) { Node part = new NodeNumber(0); //Invert one to zero splitter.Move_sign(); //move to the next sign return(part); } else if (splitter.current_sign == Sign.Zero) { Node part = new NodeNumber(1); //Invert to one splitter.Move_sign(); //move to the next sign return(part); } else if (splitter.current_sign == Sign.Open) { splitter.Move_sign(); //Parse sequentially all the expression after the ( Node inside = Disj(); // Find the ) if (splitter.current_sign != Sign.Close) //if there's no ) { Console.WriteLine("Missing closing parenthesis"); Environment.Exit(0); } else if (splitter.current_sign == Sign.Close) { if (inside.Calculate() == 1) { double res = 0; Node part = new NodeNumber(res); //create the node with value of ! splitter.Move_sign();//move to the next sign return(part); } else if (inside.Calculate() == 0) { double res = 1; Node part = new NodeNumber(res); //create the node with value of ! splitter.Move_sign();//move to the next sign return(part); } } } else { Console.WriteLine("Missing opening parenthesis"); Environment.Exit(0); } } //Parenthesis if (splitter.current_sign == Sign.Open) { splitter.Move_sign(); //move to the next sign //Parse sequentially all the expression after the ( Node part = Disj(); // Find the ) if (splitter.current_sign != Sign.Close) //if there's no ) { Console.WriteLine("Missing close parenthesis"); Environment.Exit(0); } splitter.Move_sign(); //move to the next sign return(part); } //If the sign is not classified Console.WriteLine($"Unknown sign: {splitter.current_sign}"); throw new SystemException($"Unknown sign: {splitter.current_sign}"); }