Ejemplo n.º 1
0
        internal bool ParseSubject(TokenSet tokens, TokenCommand cmd)
        {
            var tokenObject = new TokenObject();

            var result = false;

            if (tokens.Current.MorphType == MorphType.Adjective)
            {
                ParseAdjectiveList(tokens, tokenObject);
                if (tokens.Current == null)
                {
                    return(result);
                }
            }

            switch (tokens.Current.MorphType)
            {
            case MorphType.Noun:
                tokenObject.Noun = tokens.Current.Value;
                tokens.MoveNext();
                cmd.Subjects.Add(tokenObject);
                result = true;
                break;

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

            return(result);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        internal void ParseAdjectiveList(TokenSet tokens, TokenObject tokenObject)
        {
            if (tokens.Current.MorphType != MorphType.Adjective)
            {
                return;
            }

            var finished = false;

            while (!finished)
            {
                switch (tokens.Current.MorphType)
                {
                case MorphType.Adjective:
                    tokenObject.Adjectives.Add(tokens.Current);
                    finished = !tokens.MoveNext();
                    break;

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

                default:
                    finished = true;
                    break;
                }
            }
        }
Ejemplo n.º 4
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;
                }
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        internal void ParseSubjectList(TokenSet tokens, TokenCommand cmd)
        {
            var finished = false;

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

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

                default:
                    finished = true;
                    break;
                }
            }
        }
Ejemplo n.º 7
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);
        }