Пример #1
0
 private NextStateRec(Type ofType, string name, TokenRef token, string identifier, ParseResponse response)
 {
     Name       = name;
     Identifier = identifier;
     OfType     = ofType;
     Token      = token;
     Sequence   = null;          // end of list by default
     Alternate  = null;          // no alternate by default
     Response   = response;
 }
Пример #2
0
        public static NextStateRec CreateTokenRef(string name, TokenRef.Type type, ParseResponse response)
        {
            NextStateRec nsRec;

            switch (type)
            {
            case TokenRef.Type.Null:
                throw new FormatException($"SourceObject Type {type.ToString()} is valid BUT NOT in the context as a Next State Token Ref!");

            case TokenRef.Type.Empty:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateEmpty(), null, response);
                break;

            case TokenRef.Type.Identifier:
                if (!(name is null))
                {
                    throw new ArgumentNullException(nameof(name), $"NextStateRecords can not contain Identifier Tokens with predefined names -{nameof(name)} must be set to 'null', not '{name}'!");
                }

                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateIdentifier(), response);
                break;

            case TokenRef.Type.Keyword:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateKeyword(name), name, response);
                break;

            case TokenRef.Type.Operator:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateOperator(name), name, response);
                break;

            case TokenRef.Type.Error:
                throw new NotImplementedException("Error types yet to be implemented!");

            default:
                throw InvalidEnumValueException.InvalidArgument(typeof(TokenRef.Type), type, nameof(name));
            }

            return(nsRec);
        }
Пример #3
0
 public static NextStateRec CreateGrammaRef(string name)
 {
     return(new NextStateRec(Type.GrammaRef, name, TokenRef.CreateNonToken(), ParseResponse.Next));
 }
Пример #4
0
 public static NextStateRec CreateEmpty(ParseResponse response)
 {
     return(new NextStateRec(Type.TokenRef, "Empty", TokenRef.CreateEmpty(), "&Empty", response));
 }
Пример #5
0
        public ParseResponse GoToNextState(SourceObject next)
        {
            ParseResponse response = ParseResponse.Null;
            NextStateRec  state    = CurrentState;
            TokenRef      token    = TokenRef.Create(next.OfType, next.Text);

            do
            {
                Debug.WriteIf(state != null, $"{{{token}}} against {{{state.Token}}}", "Check");

                if (state == null)
                {
                    response = ParseResponse.Reject;
                    Debug.WriteLine(" -Match! Response = Reject");
                }

                else if (token == state.Token)
                {
                    response = state.Response;
                    Debug.WriteLine(" -Match! Response = " + response);
                }

                else if (state.Token.OfType == TokenRef.Type.Empty)
                {
                    response = state.Response;
                    Debug.WriteLine(" -Match on Empty! Response = " + response);
                }

                else if (state.Token.OfType == TokenRef.Type.Null)
                {
                    if (state.Response == ParseResponse.Next)
                    {
                        state    = state.Sequence;
                        response = ParseResponse.Null;
                    }
                    else
                    {
                        response = state.Response;
                    }

                    Debug.WriteLine(" -Special Response = " + response);
                }

                else
                {
                    Debug.WriteLine(" -NO Match! Check Next");
                    state = state.Sequence;
                }
            } while (response == ParseResponse.Null);

            // Determine next state based on response
            Debug.Write($"{{{state.Token }}} -> ", "Result");
            switch (response)
            {
            case ParseResponse.Next:
                CurrentState = state.Sequence;
                break;

            default:
                throw new InvalidEnumValueException(typeof(ParseResponse), response);
            }

            Debug.WriteLine($"{{{CurrentState.Token}}} -Response {response}!");

            return(response);
        }