/// <summary> /// Initializes a new instance of the <see cref="MultiplicativeTerm"/> class. /// </summary> /// <param name="node">The node to create as a term.</param> public MultiplicativeTerm(ExpNode node) { DefaultPrinter printer = new(); if (node is PowOperNode powNode) { _base = powNode.LeftChild; _exponent = powNode.RightChild; } else { _base = node; _exponent = QuickOpers.MakeNumericalNode(1); } _baseString = _base.Print(printer); }
public void DotProduct() { // Parse DefaultParser parser = new DefaultParser(); VectorProductOperNode node = new VectorProductOperNode(VectorProductMethod.DOT); parser.ParseString("<2,1,3>"); node.AddChild(parser.Tree.Root); parser = new DefaultParser(); parser.ParseString("<1,2,3>"); node.AddChild(parser.Tree.Root); // Simplify Simplifier simplifier = new Simplifier(); ExpNode exp_result = node.Execute(simplifier); // Print DefaultPrinter printer = new DefaultPrinter(); string str_result = exp_result.Print(printer); // Compare Assert.IsTrue(str_result == "13"); }
static void Main(string[] args) { while (true) { SysCon.Write("Enter an Equation (q to quit): "); string str = SysCon.ReadLine(); if (str == "q") { SysCon.Write("Done!"); return; } DefaultParser parser = new DefaultParser(); DefaultPrinter printer = new DefaultPrinter(); ParserStatus status = parser.ParseString(str); if (status.Failed) { SysCon.WriteLine($"\nError: {status.ErrorType}\n"); } else { ExpNode root = parser.Tree.Root; Simplifier simplifier = new Simplifier(); root = root.Execute(simplifier); if (root == null) { SysCon.WriteLine($"\n{simplifier.Error.Message}\n"); } else { SysCon.WriteLine($"\n{root.Print(printer)}\n"); } } } }