Пример #1
0
        //--------------------------------------
        // OBJECT      = [ADJECTIVE LIST] <NOUN>
        // OBJECT      = <PRONOUN>
        internal bool ParseObject(TokenSet tokens, TokenCommand cmd)
        {
            var finished    = false;
            var tokenObject = new TokenObject();

            if (tokens.Current.MorphType == MorphType.Adjective)
            {
                ParseAdjectiveList(tokens, tokenObject);
                finished = tokens.IsFinished;
            }

            if (!finished)
            {
                switch (tokens.Current.MorphType)
                {
                case MorphType.Noun:
                    tokenObject.Noun = tokens.Current.Value;
                    tokens.MoveNext();
                    cmd.Objects.Add(tokenObject);
                    finished = true;
                    break;

                case MorphType.Pronoun:
                    finished = ParseObjectPronoun(tokens.Current, tokenObject, cmd);
                    tokens.MoveNext();
                    break;
                }
            }

            return(finished);
        }
Пример #2
0
        internal void ParseObjectList(TokenSet tokens, TokenCommand cmd)
        {
            var finished = false;

            while (!finished)
            {
                switch (tokens.Current.MorphType)
                {
                case MorphType.Adjective:
                case MorphType.Noun:
                case MorphType.Pronoun:
                    ParseObject(tokens, cmd);
                    finished = tokens.IsFinished;
                    break;

                case MorphType.Conjunction:
                case MorphType.Article:
                    finished = !tokens.MoveNext();
                    break;

                default:
                    finished = true;
                    break;
                }
            }
        }
Пример #3
0
        internal void ParseAdverbList(TokenSet tokens, TokenCommand cmd)
        {
            var finished = false;

            if (tokens.Current.MorphType != MorphType.Adverb)
            {
                return;
            }

            while (!finished)
            {
                switch (tokens.Current.MorphType)
                {
                case MorphType.Adverb:
                    cmd.Adverbs.Add(tokens.Current);
                    finished = !tokens.MoveNext();
                    break;

                case MorphType.Conjunction:
                    finished = !tokens.MoveNext();
                    break;

                default:
                    finished = true;
                    break;
                }
            }
        }
Пример #4
0
        //==============================================
        // Language definition
        // SENTENCE = [SAY [TO] [OBJECT] "] COMMAND <CONJUNCTION> COMMAND ["]
        //
        // COMMAND     = [ADVERB LIST] <VERB> [PREPOSITION] [<OBJECT LIST> [ADVERB LIST] [<PREPOSITION> <OBJECT LIST>] [ADVERB LIST]]
        //
        // ADVERB LIST = ADVERB [[<CONJUNCTION>] ADVERB LIST]
        //
        // OBJECT LIST = OBJECT [[<CONJUNCTION>] OBJECT LIST]
        //
        // OBJECT      = [ADJECTIVE LIST] <NOUN>
        //
        // OBJECT      = <PRONOUN>
        //
        // ADJECTIVE LIST = ADJECTIVE [[<CONJUNCTION>] ADJECTIVE LIST]
        //
        //-----------------------------------------------
        internal TokenCommand ParseSentence(TokenSet tokens)
        {
            var cmd = new TokenCommand();

            tokens.Reset();

            if (!tokens.MoveNext())
            {
                return(null);
            }

            var token = tokens.Current;

            if (token.MorphType == MorphType.Verb)
            {
                var tokenVerb = token;

                if (tokenVerb.Value == _thesaurus.Keywords.VerbSay || tokenVerb.Value == _thesaurus.Keywords.VerbTalk)
                {
                    cmd.Verb = tokenVerb;
                    if (!tokens.MoveNext())
                    {
                        return(null);
                    }

                    if (tokens.Current.MorphType == MorphType.Preposition)
                    {
                        cmd.Preposition = tokens.Current.Value;
                        if (!tokens.MoveNext())
                        {
                            return(null);
                        }
                    }

                    ParseSubject(tokens, cmd);

                    do
                    {
                        cmd.NpcTokens.Add(tokens.Current);
                    } while (tokens.MoveNext());

                    return(cmd);
                }
            }

            ParseCommand(tokens, cmd);

            while (!tokens.IsFinished && tokens.Current.MorphType == MorphType.Conjunction)
            {
                ParseCommand(tokens, cmd);
            }

            return(cmd);
        }
Пример #5
0
        internal bool ParseSubjectPronoun(Token pronoun, TokenObject tokenObject, TokenCommand cmd)
        {
            var result = false;

            if (pronoun.Value == _thesaurus.Keywords.PronounAll || pronoun.Value == _thesaurus.Keywords.PronounEverything)
            {
                tokenObject.Noun = _thesaurus.Keywords.NounAll;
                cmd.Subjects.Add(tokenObject);
                result = true;
            }
            else if (pronoun.Value == _thesaurus.Keywords.PronounMe)
            {
                tokenObject.Noun = _thesaurus.Keywords.NounMyName;
                cmd.Subjects.Add(tokenObject);
                result = true;
            }

            return(result);
        }
Пример #6
0
        internal void ParseCommand(TokenSet tokens, TokenCommand cmd)
        {
            if (tokens.Current.MorphType == MorphType.Adverb)
            {
                ParseAdverbList(tokens, cmd);
            }

            if (tokens.Current.MorphType == MorphType.Verb)
            {
                cmd.Verb = tokens.Current;
                tokens.MoveNext();
            }

            if (tokens.IsFinished)
            {
                return;
            }

            if (tokens.Current.MorphType == MorphType.Preposition)
            {
                cmd.Preposition = tokens.Current.Value;
            }

            while (tokens.Current.MorphType == MorphType.Preposition && tokens.MoveNext())
            {
            }

            if (tokens.IsFinished)
            {
                return;
            }

            ParseSubjectList(tokens, cmd);

            if (tokens.IsFinished)
            {
                return;
            }

            ParseAdverbList(tokens, cmd);

            if (tokens.IsFinished)
            {
                return;
            }

            while (tokens.Current.MorphType == MorphType.Preposition)
            {
                if (cmd.Preposition == null)
                {
                    cmd.Preposition = tokens.Current.Value;
                }
                if (!tokens.MoveNext())
                {
                    break;
                }
            }

            if (tokens.IsFinished)
            {
                return;
            }

            ParseObjectList(tokens, cmd);

            if (tokens.IsFinished)
            {
                return;
            }

            ParseAdverbList(tokens, cmd);
        }