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);
        }
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_state = {_state}");
            //Log($"_currToken = {_currToken}");
            //Log($"Result = {Result}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.KeyWordTokenKind)
                {
                case KeyWordTokenKind.LinguisticVariable:
                    _state = State.GotLinguisticVariableMark;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotLinguisticVariableMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.Identifier:
                    var name = ParseName(_currToken.Content);
                    Result.Name = name;
                    _linguisticVariable.Name = name;
                    _state = State.GotName;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.For:
                        _state = State.GotFor;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                case TokenKind.OpenFigureBracket:
                    _state = State.InContent;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFor:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Range:
                    {
                        _context.Recovery(_currToken);

                        var parser = new InlineRangeParser(_context);
                        parser.Run();

#if DEBUG
                        //Log($"parser.Result = {parser.Result}");
#endif

                        _linguisticVariable.Range = parser.Result;
                        _state = State.GotRange;
                    }
                    break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotRange:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                    _state = State.InContent;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.InContent:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Identifier:
                    _context.Recovery(_currToken);
                    _state = State.WaitTerm;
                    break;

                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Terms:
                    {
                        var nextToken = _context.GetToken();

#if DEBUG
                        //Log($"nextToken = {nextToken}");
#endif

                        if (nextToken.TokenKind == TokenKind.Colon)
                        {
                            _state = State.WaitTerm;
                            break;
                        }

                        _context.Recovery(_currToken);
                        _context.Recovery(nextToken);
                        _state = State.WaitTerm;
                    }
                    break;

                    case KeyWordTokenKind.Constraints:
                    {
                        var nextToken = _context.GetToken();

#if DEBUG
                        //Log($"nextToken = {nextToken}");
#endif

                        if (nextToken.TokenKind == TokenKind.Colon)
                        {
                            _state = State.WaitConstraint;
                            break;
                        }

                        _context.Recovery(_currToken);
                        _context.Recovery(nextToken);
                        _state = State.WaitTerm;
                    }
                    break;


                    default:
                        _context.Recovery(_currToken);
                        _state = State.WaitTerm;
                        break;
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitTerm:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Constraints:
                    {
                        var nextToken = _context.GetToken();

#if DEBUG
                        //Log($"nextToken = {nextToken}");
#endif

                        if (nextToken.TokenKind == TokenKind.Colon)
                        {
                            _state = State.WaitConstraint;
                            break;
                        }

                        _context.Recovery(_currToken);
                        _context.Recovery(nextToken);
                        _state = State.WaitTerm;
                    }
                    break;

                    default:
                        GetTermName();
                        break;
                    }
                    break;

                case TokenKind.Identifier:
                    GetTermName();
                    break;

                case TokenKind.CloseFigureBracket:
                    Exit();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotTermName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Assign:
                    _state = State.WaitPredefinedMembershipFunction;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitPredefinedMembershipFunction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.Identifier:
                    _nameOfPredefinedMembershipFunction = _currToken.Content;
                    _state = State.GotNameOfPredefinedMembershipFunction;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotNameOfPredefinedMembershipFunction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenRoundBracket:
                    _parametersOfPredefinedMembershipFunction = new List <NumberValue>();
                    _state = State.WaitForParameterOfMembershipFunction;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForParameterOfMembershipFunction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context);
                    parser.Run();

#if DEBUG
                    //Log($"parser.Result = {parser.Result}");
#endif

                    _parametersOfPredefinedMembershipFunction.Add(parser.Result.AsNumberValue);

                    _state = State.GotParameterOfMembershipFunction;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotParameterOfMembershipFunction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Comma:
                    _state = State.WaitForParameterOfMembershipFunction;
                    break;

                case TokenKind.CloseRoundBracket:
                    _currentFuzzyLogicNonNumericValue.Handler = CreateMembershipPredefinedHandler();

#if DEBUG
                    //Log($"_currentFuzzyLogicNonNumericValue = {_currentFuzzyLogicNonNumericValue}");
#endif

                    _state = State.GotPredefinedMembershipFunction;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotPredefinedMembershipFunction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Semicolon:
                    _nameOfPredefinedMembershipFunction       = string.Empty;
                    _parametersOfPredefinedMembershipFunction = null;
                    _currentFuzzyLogicNonNumericValue         = null;
                    _state = State.WaitTerm;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitConstraint:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.For:
                        _currentConstraintItem = new LinguisticVariableConstraintItem();
                        _linguisticVariable.Constraint.AddItem(_currentConstraintItem);
                        _state = State.GotConstraintFor;
                        break;

                    case KeyWordTokenKind.Terms:
                    {
                        var nextToken = _context.GetToken();

#if DEBUG
                        //Log($"nextToken = {nextToken}");
#endif

                        if (nextToken.TokenKind == TokenKind.Colon)
                        {
                            _state = State.WaitTerm;
                            break;
                        }

                        throw new UnexpectedTokenException(_currToken);
                    }

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                case TokenKind.CloseFigureBracket:
                    Exit();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotConstraintFor:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Relation:
                        _currentConstraintItem.Kind = KindOfLinguisticVariableConstraintItem.Relation;
                        _state = State.GotConstraintRelationMark;
                        break;

                    case KeyWordTokenKind.Inheritance:
                        _currentConstraintItem.Kind = KindOfLinguisticVariableConstraintItem.Inheritance;
                        _state = State.GotConstraintInheritanceMark;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotConstraintRelationMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    _currentConstraintItem.RelationName = ParseName(_currToken.Content);
                    _state = State.GotConstraintRelationName;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotConstraintRelationName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Semicolon:
                    _state = State.WaitConstraint;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotConstraintInheritanceMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Semicolon:
                    _state = State.WaitConstraint;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
예제 #3
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_state = {_state}");
            //Log($"_currToken = {_currToken}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.KeyWordTokenKind)
                {
                case KeyWordTokenKind.Range:
                    _state = State.GotRangeMark;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotRangeMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenSquareBracket:
                    _leftBoundary.Includes = true;
                    _state = State.GotLeftLimitationMark;
                    break;

                case TokenKind.OpenRoundBracket:
                    _leftBoundary.Includes = false;
                    _state = State.GotLeftLimitationMark;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotLeftLimitationMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context);
                    parser.Run();

#if DEBUG
                    //Log($"parser.Result = {parser.Result}");
#endif

                    _leftBoundary.Value = parser.Result.AsNumberValue;

                    _state = State.GotLeftValue;
                }
                break;

                case TokenKind.NegativeInfinity:
                case TokenKind.Multiplication:
                    _state = State.GotLeftValue;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotLeftValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Comma:
                    _state = State.WeitForRightValue;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WeitForRightValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context);
                    parser.Run();

#if DEBUG
                    //Log($"parser.Result = {parser.Result}");
#endif

                    _rightBoundary.Value = parser.Result.AsNumberValue;

                    _state = State.GotRightValue;
                }
                break;

                case TokenKind.PositiveInfinity:
                case TokenKind.Multiplication:
                    _state = State.GotRightValue;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotRightValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseSquareBracket:
                    _rightBoundary.Includes = true;
                    Exit();
                    break;

                case TokenKind.CloseRoundBracket:
                    _rightBoundary.Includes = false;
                    Exit();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_currToken = {_currToken}");
            //Log($"Result = {Result}");
            //Log($"_state = {_state}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.EntityCondition:
                {
                    var name = NameHelper.CreateName(_currToken.Content);

#if DEBUG
                    //Log($"name = {name}");
#endif

                    Result.Name = name;

                    _state = State.GotName;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenSquareBracket:
                    Result.KindOfEntityConditionAstExpression = KindOfEntityConditionAstExpression.Waypoint;
                    _state = State.WaitForFirstCoordinate;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForFirstCoordinate:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context);
                    parser.Run();

                    var node = new ConstValueAstExpression();
                    node.Value = parser.Result;

                    Result.FirstCoordinate = node;

                    _state = State.GotFirstCoordinate;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFirstCoordinate:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Comma:
                    _state = State.WaitForSecondCoordinate;
                    break;

                case TokenKind.CloseSquareBracket:
                    if (Result.KindOfEntityConditionAstExpression == KindOfEntityConditionAstExpression.Waypoint)
                    {
                        Exit();
                        break;
                    }
                    throw new UnexpectedTokenException(_currToken);

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForSecondCoordinate:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context);
                    parser.Run();

                    var node = new ConstValueAstExpression();
                    node.Value = parser.Result;

                    Result.SecondCoordinate = node;

                    _state = State.GotSecondCoordinate;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotSecondCoordinate:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseSquareBracket:
                    if (Result.KindOfEntityConditionAstExpression == KindOfEntityConditionAstExpression.Waypoint)
                    {
                        Exit();
                        break;
                    }
                    throw new UnexpectedTokenException(_currToken);

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"Result = {Result}");
            //Log($"_state = {_state}");
            //Log($"_currToken = {_currToken}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenRoundBracket:
                    _state = State.WaitForMainParameter;
                    break;

                case TokenKind.AsyncMarker:
                    if (Result.IsAsync)
                    {
                        throw new UnexpectedTokenException(_currToken);
                    }
                    Result.IsAsync = true;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForMainParameter:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Identifier:
                case TokenKind.Word:
                {
                    _currentParameter = new CallingParameter();
                    Result.Parameters.Add(_currentParameter);

                    var value = NameHelper.CreateName(_currToken.Content);

                    var node = new ConstValueAstExpression();
                    node.Value = value;

                    _currentParameter.Value = node;
                    _state = State.GotPositionedMainParameter;
                }
                break;

                case TokenKind.Number:
                {
                    _currentParameter = new CallingParameter();
                    Result.Parameters.Add(_currentParameter);

                    _context.Recovery(_currToken);

                    var parser = new NumberParser(_context);
                    parser.Run();

                    var node = new ConstValueAstExpression();
                    node.Value = parser.Result;

                    _currentParameter.Value = node;
                    _state = State.GotPositionedMainParameter;
                }
                break;

                case TokenKind.String:
                {
                    _currentParameter = new CallingParameter();
                    Result.Parameters.Add(_currentParameter);

                    var node = new ConstValueAstExpression();
                    node.Value = new StringValue(_currToken.Content);

                    _currentParameter.Value = node;
                    _state = State.GotPositionedMainParameter;
                }
                break;

                case TokenKind.Var:
                {
                    _currentParameter = new CallingParameter();
                    Result.Parameters.Add(_currentParameter);

                    var value = NameHelper.CreateName(_currToken.Content);

                    var node = new VarAstExpression();
                    node.Name = value;

                    _currentParameter.Value = node;

                    _state = State.GotPositionedMainParameter;
                }
                break;

                case TokenKind.CloseRoundBracket:
                    Exit();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotPositionedMainParameter:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Colon:
                    if (_currentParameter.Value != null)
                    {
                        _currentParameter.Name  = ConvertValueExprToNameExpr(_currentParameter.Value);
                        _currentParameter.Value = null;
                    }

                    _state = State.WaitForValueOfNamedMainParameter;
                    break;

                case TokenKind.CloseRoundBracket:
                    Exit();
                    break;

                case TokenKind.Comma:
                    _state = State.GotComma;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForValueOfNamedMainParameter:
                switch (_currToken.TokenKind)
                {
                case TokenKind.EntityCondition:
                {
                    _context.Recovery(_currToken);

                    var parser = new EntityConditionParser(_context);
                    parser.Run();

                    _currentParameter.Value = parser.Result;

                    _state = State.GotValueOfNamedMainParameter;
                }
                break;

                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);

                    var parser = new NumberParser(_context);
                    parser.Run();

                    var node = new ConstValueAstExpression();
                    node.Value = parser.Result;

                    _currentParameter.Value = node;

                    _state = State.GotValueOfNamedMainParameter;
                }
                break;

                case TokenKind.String:
                {
                    var node = new ConstValueAstExpression();
                    node.Value = new StringValue(_currToken.Content);

                    _currentParameter.Value = node;

                    _state = State.GotValueOfNamedMainParameter;
                }
                break;

                case TokenKind.Word:
                case TokenKind.Identifier:
                {
                    var value = NameHelper.CreateName(_currToken.Content);

                    var node = new ConstValueAstExpression();
                    node.Value = value;

                    _currentParameter.Value = node;

                    _state = State.GotValueOfNamedMainParameter;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotValueOfNamedMainParameter:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseRoundBracket:
                    Exit();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotComma:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                case TokenKind.Word:
                case TokenKind.EntityCondition:
                case TokenKind.Var:
                case TokenKind.String:
                    _context.Recovery(_currToken);
                    _state = State.WaitForMainParameter;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
예제 #6
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_state = {_state}");
            //Log($"_currToken = {_currToken}");
            //Log($"Result = {Result}");
            //Log($"_currentItem = {_currentItem}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Is:
                        _state = State.WaitForItem;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForItem:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    TryCreateCurrentItem();

                    _currentItem.Rank = new LogicalValue(1.0F);

                    _currentItem.SuperName = ParseName(_currToken.Content);
                    _state = State.GotSuperName;
                    break;

                case TokenKind.OpenSquareBracket:
                    _state = State.WaitForRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotSuperName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

                case TokenKind.Comma:
                    _currentItem = null;
                    _state       = State.WaitForItem;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    TryCreateCurrentItem();

                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context, true);
                    parser.Run();
                    _currentItem.Rank = parser.Result;
                    _state            = State.GotRankValue;
                }
                break;

                case TokenKind.Identifier:
                case TokenKind.Word:
                {
                    TryCreateCurrentItem();

                    var nextToken = _context.GetToken();

#if DEBUG
                    //Log($"nextToken = {nextToken}");
#endif

                    switch (nextToken.TokenKind)
                    {
                    case TokenKind.Word:
                    case TokenKind.Identifier:
                        _context.Recovery(nextToken);

                        _fuzzyLogicNonNumericSequenceValue = new FuzzyLogicNonNumericSequenceValue();
                        _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                        _state = State.GotFuzzyLogicNonNumericSequenceItem;
                        break;

                    default:
                        _context.Recovery(nextToken);

                        _currentItem.Rank = ParseName(_currToken.Content);

                        _state = State.GotRankValue;
                        break;
                    }
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFuzzyLogicNonNumericSequenceItem:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.Identifier:
                    _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                    _state = State.GotFuzzyLogicNonNumericSequenceItem;
                    break;

                case TokenKind.CloseSquareBracket:
                    _currentItem.Rank = _fuzzyLogicNonNumericSequenceValue;
                    _state            = State.GotRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotRankValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseSquareBracket:
                    _state = State.GotRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    TryCreateCurrentItem();

                    _currentItem.SuperName = ParseName(_currToken.Content);
                    _state = State.GotSuperName;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
예제 #7
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            Log($"_state = {_state}");
            Log($"_currToken = {_currToken}");
            //Log($"_rawStatement = {_rawStatement}");
            //Log($"Result = {Result}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Use:
                        _state = State.GotUse;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotUse:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.SystemVar:
                    _rawStatement.FirstName = ParseName(_currToken.Content);
                    _state = State.GotFirstName;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFirstName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Is:
                        _state = State.GotIs;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotIs:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenSquareBracket:
                    _state = State.WaitForInheritanceRank;
                    break;

                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Not:
                        _rawStatement.HasNot = true;
                        _state = State.GotIsNot;
                        break;

                    case KeyWordTokenKind.Unknown:
                    default:
                        ProcessGotUseInheritanceSecondName();
                        break;
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotIsNot:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenSquareBracket:
                    _state = State.WaitForInheritanceRank;
                    break;

                case TokenKind.Word:
                    ProcessGotUseInheritanceSecondName();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotSecondName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Semicolon:
                    Exit();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForInheritanceRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context, true);
                    parser.Run();
                    _rawStatement.Rank = parser.Result;
                    _state             = State.GotInheritanceRankValue;
                }
                break;

                case TokenKind.Identifier:
                case TokenKind.Word:
                {
                    var nextToken = _context.GetToken();

#if DEBUG
                    //Log($"nextToken = {nextToken}");
#endif
                    switch (nextToken.TokenKind)
                    {
                    case TokenKind.Word:
                    case TokenKind.Identifier:
                        _context.Recovery(nextToken);

                        _fuzzyLogicNonNumericSequenceValue = new FuzzyLogicNonNumericSequenceValue();
                        _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                        _state = State.GotFuzzyLogicNonNumericSequenceItem;
                        break;

                    default:
                        _context.Recovery(nextToken);

                        _rawStatement.Rank = ParseName(_currToken.Content);

                        _state = State.GotInheritanceRankValue;
                        break;
                    }
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFuzzyLogicNonNumericSequenceItem:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.Identifier:
                    _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                    _state = State.GotFuzzyLogicNonNumericSequenceItem;
                    break;

                case TokenKind.CloseSquareBracket:
                    _rawStatement.Rank = _fuzzyLogicNonNumericSequenceValue;
                    _state             = State.GotInheritanceRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotInheritanceRankValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseSquareBracket:
                    _state = State.GotInheritanceRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotInheritanceRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    ProcessGotUseInheritanceSecondName();
                    break;

                //case TokenKind.Semicolon:
                //    Exit();
                //    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
예제 #8
0
        /// <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);
            }
        }
예제 #9
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_state = {_state}");
            //Log($"_currToken = {_currToken}");
            //Log($"Result = {Result.WriteListToString()}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenRoundBracket:
                    _state = State.WaitForParameter;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForParameter:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseRoundBracket:
                    Exit();
                    break;

                case TokenKind.Var:
                {
                    _curentFunctionArgumentInfo = new FunctionArgumentInfo();
                    Result.Add(_curentFunctionArgumentInfo);

                    _curentFunctionArgumentInfo.Name = ParseName(_currToken.Content);

                    _state = State.GotParameterName;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotParameterName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseRoundBracket:
                    Exit();
                    break;

                case TokenKind.Comma:
                    _state = State.GotComma;
                    break;

                case TokenKind.Assign:
                    _state = State.WaitForDefaultValue;
                    break;

                case TokenKind.Colon:
                    _state = State.WaitForParameterType;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForParameterType:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Identifier:
                case TokenKind.Word:
                {
                    var nextToken = _context.GetToken();

#if DEBUG
                    //Log($"nextToken = {nextToken}");
#endif

                    if (nextToken.TokenKind == TokenKind.Or)
                    {
                        _context.Recovery(_currToken);
                        _context.Recovery(nextToken);

                        var paser = new TupleOfTypesParser(_context, false);
                        paser.Run();

                        _curentFunctionArgumentInfo.TypesList = paser.Result;
                    }
                    else
                    {
                        _context.Recovery(nextToken);

                        _curentFunctionArgumentInfo.TypesList.Add(ParseName(_currToken.Content));
                    }

                    _state = State.GotParameterType;
                }
                break;

                case TokenKind.OpenRoundBracket:
                {
                    _context.Recovery(_currToken);

                    var paser = new TupleOfTypesParser(_context, true);
                    paser.Run();

                    _curentFunctionArgumentInfo.TypesList = paser.Result;

                    _state = State.GotParameterType;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotParameterType:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseRoundBracket:
                    Exit();
                    break;

                case TokenKind.Assign:
                    _state = State.WaitForDefaultValue;
                    break;

                case TokenKind.Comma:
                    _state = State.GotComma;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForDefaultValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.String:
                {
                    _curentFunctionArgumentInfo.DefaultValue    = new StringValue(_currToken.Content);
                    _curentFunctionArgumentInfo.HasDefaultValue = true;
                    _state = State.GotDefaultValue;
                }
                break;

                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);

                    var parser = new NumberParser(_context);
                    parser.Run();

                    _curentFunctionArgumentInfo.DefaultValue = parser.Result;

                    _curentFunctionArgumentInfo.HasDefaultValue = true;
                    _state = State.GotDefaultValue;
                }
                break;

                case TokenKind.Identifier:
                case TokenKind.Word:
                {
                    _curentFunctionArgumentInfo.DefaultValue = ParseName(_currToken.Content);

                    _curentFunctionArgumentInfo.HasDefaultValue = true;
                    _state = State.GotDefaultValue;
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotDefaultValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseRoundBracket:
                    Exit();
                    break;

                case TokenKind.Comma:
                    _state = State.GotComma;
                    break;

                case TokenKind.Identifier:
                case TokenKind.Word:
                    throw new NotImplementedException();

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotComma:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Var:
                    _context.Recovery(_currToken);
                    _state = State.WaitForParameter;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }