private void ProcessConceptLeaf() { _lastIsOperator = null; var value = NameHelper.CreateName(_currToken.Content); var kindOfName = value.KindOfName; switch (kindOfName) { case KindOfName.Concept: case KindOfName.Channel: case KindOfName.Entity: { var node = new ConstValueAstExpression(); node.Value = value; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotName; } break; default: throw new ArgumentOutOfRangeException(nameof(kindOfName), kindOfName, null); } }
private void ProcessUnaryOperator(KindOfOperatorOfLogicalQueryNode kindOfOperator) { var node = new LogicalQueryNode(); _lastLogicalQueryNode = node; node.Kind = KindOfLogicalQueryNode.UnaryOperator; node.KindOfOperator = kindOfOperator; var kind = KindOfOperator.Unknown; switch (kindOfOperator) { case KindOfOperatorOfLogicalQueryNode.Not: kind = KindOfOperator.Not; break; default: throw new ArgumentOutOfRangeException(nameof(kindOfOperator), kindOfOperator, null); } var priority = OperatorsHelper.GetPriority(kind); #if DEBUG //Log($"priority = {priority}"); #endif var intermediateNode = new IntermediateAstNode(node, KindOfIntermediateAstNode.UnaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotOperator; }
private void ProcessCallingFunction() { _lastIsOperator = null; _context.Recovery(_currToken); var parser = new CallingFunctionExpressionParser(_context); parser.Run(); var node = parser.Result; #if DEBUG //Log($"node = {node}"); #endif var priority = OperatorsHelper.GetPriority(KindOfOperator.CallFunction); #if DEBUG //Log($"priority = {priority}"); #endif var intermediateNode = new IntermediateAstNode(node, KindOfIntermediateAstNode.UnaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.Init; }
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); }
private void ProcessStringToken() { _lastIsOperator = null; var node = new ConstValueAstExpression(); var value = new StringValue(_currToken.Content); node.Value = value; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); }
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 ProcessNumberToken() { _context.Recovery(_currToken); var parser = new NumberParser(_context); parser.Run(); var node = new ConstValueAstExpression(); node.Value = parser.Result; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); }
private void ProcessVar() { _lastIsOperator = null; var value = NameHelper.CreateName(_currToken.Content); var node = new VarAstExpression(); node.Name = value; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotName; }
private void ProcessIsOperator() { var node = new BinaryOperatorAstExpression(); node.KindOfOperator = KindOfOperator.Is; _lastIsOperator = node; var priority = OperatorsHelper.GetPriority(node.KindOfOperator); var intermediateNode = new IntermediateAstNode(node, KindOfIntermediateAstNode.BinaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.Init; }
private void ProcessChannel() { _lastIsOperator = null; var name = NameHelper.CreateName(_currToken.Content); #if DEBUG //Log($"name = {name}"); #endif var node = new ConstValueAstExpression(); node.Value = name; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); }
private void StartProcessingFuzzyLogicNonNumericSequenceValue(StrongIdentifierValue value) { _fuzzyLogicNonNumericSequenceValue = new FuzzyLogicNonNumericSequenceValue(); var node = new LogicalQueryNode(); node.Kind = KindOfLogicalQueryNode.FuzzyLogicNonNumericSequence; node.FuzzyLogicNonNumericSequenceValue = _fuzzyLogicNonNumericSequenceValue; _fuzzyLogicNonNumericSequenceValue.AddIdentifier(value); var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotFuzzyLogicNonNumericSequenceItem; }
private void ProcessConceptOrQuestionVar(StrongIdentifierValue value) { #if DEBUG //Log($"value = {value}"); #endif var node = CreateLogicalQueryNodeByStrongIdentifierValue(value); #if DEBUG //Log($"node = {node}"); #endif var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotConcept; }
private void ProcessNullToken() { _context.Recovery(_currToken); var parser = new NullParser(_context); parser.Run(); #if DEBUG //Log($"parser.Result = {parser.Result}"); #endif var node = new ConstValueAstExpression(); node.Value = parser.Result; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); }
private void ProcessUsualBinaryOperator(KindOfOperator kindOfOperator) { _lastIsOperator = null; var node = new BinaryOperatorAstExpression(); node.KindOfOperator = kindOfOperator; var priority = OperatorsHelper.GetPriority(kindOfOperator); #if DEBUG //Log($"priority = {priority}"); #endif var intermediateNode = new IntermediateAstNode(node, KindOfIntermediateAstNode.BinaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.Init; }
private void ProcessRuleOrFact() { _context.Recovery(_currToken); var parser = new LogicalQueryParser(_context); parser.Run(); var ruleInstanceItem = parser.Result; #if DEBUG //Log($"ruleInstanceItem = {ruleInstanceItem}"); #endif var value = new RuleInstanceValue(ruleInstanceItem); var node = new ConstValueAstExpression(); node.Value = value; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); }
private void ProcessGroup() { var node = new LogicalQueryNode(); _lastLogicalQueryNode = node; node.Kind = KindOfLogicalQueryNode.Group; var parser = new LogicalExpressionParser(_context, true); parser.Run(); #if DEBUG //Log($"parser.Result = {parser.Result}"); #endif node.Left = parser.Result; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotPredicate; }
private void ProcessPredicate(StrongIdentifierValue name) { var node = new LogicalQueryNode(); _lastLogicalQueryNode = node; node.Kind = KindOfLogicalQueryNode.Relation; node.Name = name; node.ParamsList = new List <LogicalQueryNode>(); var priority = OperatorsHelper.GetPriority(KindOfOperator.Predicate); #if DEBUG //Log($"priority = {priority}"); #endif var intermediateNode = new IntermediateAstNode(node, KindOfIntermediateAstNode.UnaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.WaitForPredicateParameter; }
private void ProcessLogicalQueryOperator() { _lastIsOperator = null; //_context.Recovery(_currToken); var parser = new LogicalQueryOperationParser(_context); parser.Run(); var resultItem = parser.Result; #if DEBUG //Log($"resultItem = {resultItem}"); #endif var node = new UnaryOperatorAstExpression(); node.KindOfOperator = KindOfOperator.CallLogicalQuery; var priority = OperatorsHelper.GetPriority(node.KindOfOperator); #if DEBUG //Log($"priority = {priority}"); #endif var intermediateNode = new IntermediateAstNode(node, KindOfIntermediateAstNode.UnaryOperator, priority); AstNodesLinker.SetNode(intermediateNode, _nodePoint); var valueNode = new ConstValueAstExpression(); valueNode.Value = resultItem; var valueIntermediateNode = new IntermediateAstNode(valueNode); AstNodesLinker.SetNode(valueIntermediateNode, _nodePoint); _state = State.GotCallLogicalQueryOperator; }
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}"); }
/// <inheritdoc/> protected override void OnRun() { #if DEBUG //Log($"_state = {_state}"); //Log($"_isGroup = {_isGroup}"); //Log($"_currToken = {_currToken}"); //Log($"Result = {Result}"); //Log($"_nodePoint = {_nodePoint}"); #endif if (_terminatingTokenKindList.Contains(_currToken.TokenKind)) { _context.Recovery(_currToken); Exit(); return; } switch (_state) { case State.Init: switch (_currToken.TokenKind) { case TokenKind.Word: case TokenKind.LogicalVar: case TokenKind.Identifier: ProcessWord(); break; case TokenKind.Entity: { var name = NameHelper.CreateName(_currToken.Content); #if DEBUG //Log($"name = {name}"); #endif var node = new LogicalQueryNode(); node.Kind = KindOfLogicalQueryNode.Entity; node.Name = name; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotEntity; } break; default: throw new UnexpectedTokenException(_currToken); } break; case State.WaitForPredicateParameter: switch (_currToken.TokenKind) { case TokenKind.Entity: case TokenKind.LogicalVar: { _context.Recovery(_currToken); var parser = new LogicalExpressionParser(_context); parser.Run(); #if DEBUG //Log($"parser.Result = {parser.Result}"); #endif _lastLogicalQueryNode.ParamsList.Add(parser.Result); _state = State.GotPredicateParameter; } break; case TokenKind.Word: case TokenKind.Identifier: { switch (_currToken.KeyWordTokenKind) { case KeyWordTokenKind.Null: { _context.Recovery(_currToken); var parser = new NullParser(_context); parser.Run(); #if DEBUG //Log($"parser.Result = {parser.Result}"); #endif var node = new LogicalQueryNode(); node.Kind = KindOfLogicalQueryNode.Value; node.Value = parser.Result; _lastLogicalQueryNode.ParamsList.Add(node); _state = State.GotPredicateParameter; } break; default: { var nextToken = _context.GetToken(); var terminatingTokenKindList = new List <TokenKind>() { TokenKind.CloseRoundBracket }; if (nextToken.TokenKind != TokenKind.OpenRoundBracket) { terminatingTokenKindList.Add(TokenKind.Comma); } #if DEBUG //if (_currToken.Content == "distance") //{ //throw new NotImplementedException(); //} #endif #if DEBUG //Log($"nextToken = {nextToken}"); #endif _context.Recovery(_currToken); _context.Recovery(nextToken); var parser = new LogicalExpressionParser(_context, terminatingTokenKindList); parser.Run(); #if DEBUG //Log($"parser.Result = {parser.Result}"); //if (_currToken.Content == "distance") //{ // //throw new NotImplementedException(); //} #endif _lastLogicalQueryNode.ParamsList.Add(parser.Result); _state = State.GotPredicateParameter; } break; } } break; case TokenKind.Number: { _context.Recovery(_currToken); var parser = new NumberParser(_context); parser.Run(); #if DEBUG //Log($"parser.Result = {parser.Result}"); #endif var node = new LogicalQueryNode(); node.Kind = KindOfLogicalQueryNode.Value; node.Value = parser.Result; _lastLogicalQueryNode.ParamsList.Add(node); _state = State.GotPredicateParameter; } break; default: throw new UnexpectedTokenException(_currToken); } break; case State.GotPredicateParameter: switch (_currToken.TokenKind) { case TokenKind.CloseRoundBracket: _state = State.GotPredicate; break; case TokenKind.Comma: _state = State.WaitForPredicateParameter; break; default: throw new UnexpectedTokenException(_currToken); } break; case State.GotPredicate: switch (_currToken.TokenKind) { case TokenKind.And: ProcessBinaryOperator(KindOfOperatorOfLogicalQueryNode.And); break; case TokenKind.Or: ProcessBinaryOperator(KindOfOperatorOfLogicalQueryNode.Or); break; case TokenKind.Comma: _state = State.WaitForPredicateParameter; break; case TokenKind.CloseRoundBracket: if (_isGroup) { Exit(); break; } throw new UnexpectedTokenException(_currToken); default: throw new UnexpectedTokenException(_currToken); } break; case State.GotConcept: switch (_currToken.TokenKind) { case TokenKind.Word: switch (_currToken.KeyWordTokenKind) { case KeyWordTokenKind.Is: ProcessBinaryOperator(KindOfOperatorOfLogicalQueryNode.Is); break; default: throw new UnexpectedTokenException(_currToken); } break; case TokenKind.More: ProcessBinaryOperator(KindOfOperatorOfLogicalQueryNode.More); break; case TokenKind.MoreOrEqual: ProcessBinaryOperator(KindOfOperatorOfLogicalQueryNode.MoreOrEqual); break; case TokenKind.Less: ProcessBinaryOperator(KindOfOperatorOfLogicalQueryNode.Less); break; case TokenKind.LessOrEqual: ProcessBinaryOperator(KindOfOperatorOfLogicalQueryNode.LessOrEqual); break; default: throw new UnexpectedTokenException(_currToken); } break; case State.GotOperator: switch (_currToken.TokenKind) { case TokenKind.Word: case TokenKind.Identifier: ProcessWord(); break; case TokenKind.OpenRoundBracket: ProcessGroup(); break; case TokenKind.Not: ProcessUnaryOperator(KindOfOperatorOfLogicalQueryNode.Not); break; case TokenKind.LogicalVar: { var value = NameHelper.CreateName(_currToken.Content); ProcessConceptOrQuestionVar(value); } break; case TokenKind.Number: { _context.Recovery(_currToken); var parser = new NumberParser(_context); parser.Run(); #if DEBUG //Log($"parser.Result = {parser.Result}"); #endif var node = new LogicalQueryNode(); node.Kind = KindOfLogicalQueryNode.Value; node.Value = parser.Result; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotConcept; } break; default: throw new UnexpectedTokenException(_currToken); } break; case State.GotFuzzyLogicNonNumericSequenceItem: switch (_currToken.TokenKind) { case TokenKind.Word: case TokenKind.Identifier: { var value = NameHelper.CreateName(_currToken.Content); #if DEBUG //Log($"value = {value}"); #endif _fuzzyLogicNonNumericSequenceValue.AddIdentifier(value); #if DEBUG //Log($"_fuzzyLogicNonNumericSequenceValue = {_fuzzyLogicNonNumericSequenceValue}"); #endif } break; case TokenKind.More: case TokenKind.MoreOrEqual: case TokenKind.Less: case TokenKind.LessOrEqual: _context.Recovery(_currToken); _state = State.GotConcept; break; default: throw new UnexpectedTokenException(_currToken); } break; default: throw new ArgumentOutOfRangeException(nameof(_state), _state, null); } }