public void AstNodesLinker_Tests_Case8() { var nodePoint = new IntermediateAstNodePoint(); var varNode = new TstVarAstExpression(); varNode.Name = "a"; var intermediateNode = new IntermediateAstNode(varNode); AstNodesLinker.SetNode(intermediateNode, nodePoint); var binOpNode = new TstBinaryAstExpression(); binOpNode.KindOfOperator = TstKindOfOperator.Assign; var priority = GetPriority(binOpNode.Kind, binOpNode.KindOfOperator); intermediateNode = new IntermediateAstNode(binOpNode, KindOfIntermediateAstNode.BinaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, nodePoint); var numNode = new TstNumberAstExpressionNode(); numNode.Value = 12; intermediateNode = new IntermediateAstNode(numNode); AstNodesLinker.SetNode(intermediateNode, nodePoint); binOpNode = new TstBinaryAstExpression(); binOpNode.KindOfOperator = TstKindOfOperator.Plus; priority = GetPriority(binOpNode.Kind, binOpNode.KindOfOperator); intermediateNode = new IntermediateAstNode(binOpNode, KindOfIntermediateAstNode.BinaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, nodePoint); numNode = new TstNumberAstExpressionNode(); numNode.Value = 5; intermediateNode = new IntermediateAstNode(numNode); AstNodesLinker.SetNode(intermediateNode, nodePoint); var resultExr = (TstBaseAstExpression)nodePoint.BuildExpr(); var str = resultExr.GetDbgString(); Assert.AreEqual(str, "a = 12 + 5"); var calcResult = resultExr.Calc(); Assert.AreEqual(calcResult, 17); Assert.AreEqual(varNode.Value, 17); }
public void AstNodesLinker_Tests_Case5() { var nodePoint = new IntermediateAstNodePoint(); var numNode = new TstNumberAstExpressionNode(); numNode.Value = 12; var intermediateNode = new IntermediateAstNode(numNode); AstNodesLinker.SetNode(intermediateNode, nodePoint); var binOpNode = new TstBinaryAstExpression(); binOpNode.KindOfOperator = TstKindOfOperator.Plus; var priority = GetPriority(binOpNode.Kind, binOpNode.KindOfOperator); intermediateNode = new IntermediateAstNode(binOpNode, KindOfIntermediateAstNode.BinaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, nodePoint); var unaryOp = new TstUnaryAstExpression(); unaryOp.KindOfOperator = TstKindOfOperator.Minus; priority = GetPriority(unaryOp.Kind, unaryOp.KindOfOperator); intermediateNode = new IntermediateAstNode(unaryOp, KindOfIntermediateAstNode.UnaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, nodePoint); numNode = new TstNumberAstExpressionNode(); numNode.Value = 5; intermediateNode = new IntermediateAstNode(numNode); AstNodesLinker.SetNode(intermediateNode, nodePoint); var resultExr = (TstBaseAstExpression)nodePoint.BuildExpr(); var str = resultExr.GetDbgString(); Assert.AreEqual(str, "12 + - 5"); var calcResult = resultExr.Calc(); Assert.AreEqual(calcResult, 7); }
private void Run9() { _nodePoint = new IntermediateAstNodePoint(); _logger.Info($"_nodePoint = {_nodePoint}"); var varNode = new TstVarAstExpression(); varNode.Name = "a"; var intermediateNode = new IntermediateAstNode(varNode); _logger.Info($"intermediateNode = {intermediateNode}"); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _logger.Info($"_nodePoint = {_nodePoint}"); var binOpNode = new TstBinaryAstExpression(); binOpNode.KindOfOperator = TstKindOfOperator.Assign; _logger.Info($"binOpNode = {binOpNode}"); var priority = GetPriority(binOpNode.Kind, binOpNode.KindOfOperator); _logger.Info($"priority = {priority}"); intermediateNode = new IntermediateAstNode(binOpNode, KindOfIntermediateAstNode.BinaryOperator, priority); _logger.Info($"intermediateNode = {intermediateNode}"); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _logger.Info($"_nodePoint = {_nodePoint}"); var varNode2 = new TstVarAstExpression(); varNode2.Name = "b"; intermediateNode = new IntermediateAstNode(varNode2); _logger.Info($"intermediateNode = {intermediateNode}"); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _logger.Info($"_nodePoint = {_nodePoint}"); binOpNode = new TstBinaryAstExpression(); binOpNode.KindOfOperator = TstKindOfOperator.Assign; _logger.Info($"binOpNode = {binOpNode}"); priority = GetPriority(binOpNode.Kind, binOpNode.KindOfOperator); _logger.Info($"priority = {priority}"); intermediateNode = new IntermediateAstNode(binOpNode, KindOfIntermediateAstNode.BinaryOperator, priority); _logger.Info($"intermediateNode = {intermediateNode}"); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _logger.Info($"_nodePoint = {_nodePoint}"); var numNode = new TstNumberAstExpressionNode(); numNode.Value = 12; _logger.Info($"numNode = {numNode}"); intermediateNode = new IntermediateAstNode(numNode); _logger.Info($"intermediateNode = {intermediateNode}"); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _logger.Info($"_nodePoint = {_nodePoint}"); binOpNode = new TstBinaryAstExpression(); binOpNode.KindOfOperator = TstKindOfOperator.Plus; _logger.Info($"binOpNode = {binOpNode}"); priority = GetPriority(binOpNode.Kind, binOpNode.KindOfOperator); _logger.Info($"priority = {priority}"); intermediateNode = new IntermediateAstNode(binOpNode, KindOfIntermediateAstNode.BinaryOperator, priority); _logger.Info($"intermediateNode = {intermediateNode}"); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _logger.Info($"_nodePoint = {_nodePoint}"); numNode = new TstNumberAstExpressionNode(); numNode.Value = 5; _logger.Info($"numNode = {numNode}"); intermediateNode = new IntermediateAstNode(numNode); _logger.Info($"intermediateNode = {intermediateNode}"); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _logger.Info($"_nodePoint = {_nodePoint}"); var resultExr = (TstBaseAstExpression)_nodePoint.BuildExpr(); _logger.Info($"resultExr = {resultExr}"); var str = resultExr.GetDbgString(); _logger.Info($"str = '{str}'"); var calcResult = resultExr.Calc(); _logger.Info($"calcResult = {calcResult}"); _logger.Info($"varNode.Value = {varNode.Value}"); _logger.Info($"varNode2.Value = {varNode2.Value}"); }