コード例 #1
0
        //IS ENDS
        public Boolean isEnd(char c, LexicalConstants.ReservedWordsDelims rwd)
        {
            Boolean result = false;

            foreach (var item in rwd.delim_end)
            {
                if (item == c)
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
コード例 #2
0
        //GET CTRS
        private int GetCtr(string txt)
        {
            LexicalConstants.ReservedWordsDelims rwd = new LexicalConstants.ReservedWordsDelims();
            Boolean ifEnd = false;
            int     ctr   = 0;

            foreach (var item in rwd.delim_end)
            {
                if (txt.ElementAt(ctr - 1) == item)
                {
                    ifEnd = true;
                }
            }
            while (ifEnd != true)
            {
                foreach (var item in rwd.delim_end)
                {
                    if ((txt.Length) > ctr)
                    {
                        if (txt.ElementAt(ctr) == item)
                        {
                            ifEnd = true;
                            break;
                        }
                    }
                    else
                    {
                        ifEnd = true;
                    }
                }
                if (ifEnd != true)
                {
                    ctr++;
                }
            }

            if (!(txt.Length >= ctr))
            {
                ctr--;
            }
            return(ctr);
        }
コード例 #3
0
        //GET TOKENS
        public Boolean GetReservedWords(string txt)
        {
            LexicalConstants.ReservedWordsDelims rwd = new LexicalConstants.ReservedWordsDelims();
            LexicalConstants.ReservedWords       rw  = new LexicalConstants.ReservedWords();
            Tokens t = new Tokens();

            List <String> words;
            List <char>   delims;
            List <String> temp;
            Boolean       found = false, hastoken = false, exitfor = false, ifEnd = false, nodelim = true;
            int           tempctr = 0, limit = 0;

            //rwd = td.AddRange(rwd);

            if (txt.Length != 1)
            {
                Boolean iscomment    = false;
                Boolean foundComment = false;
                int     commentctr   = 0;
                while ((txt.Length - 1) > tempctr && !isEnd(txt[tempctr + 1], rwd) && !foundComment)
                {
                    tempctr++;
                    if (commentctr == 0 && txt.ElementAt(0) == 'P')
                    {
                        iscomment = true;
                        commentctr++;
                    }
                    else if (iscomment && commentctr == 1 && txt.ElementAt(1) == 'S')
                    {
                        iscomment = true;
                        commentctr++;
                        tempctr      = 1;
                        foundComment = true;
                    }
                }
                tempctr++;
            }

            for (int i = 0; i < 7; i++)
            {
                ctr    = 0;
                words  = new List <String>();
                delims = new List <char>();
                found  = true;
                switch (i)
                {
                case 0:
                    words  = rw.rw_whitespace;
                    delims = rwd.whitespace;
                    break;

                case 1:
                    words  = rw.rw_1;
                    delims = rwd.delim_1;
                    break;

                case 2:
                    words  = rw.rw_2;
                    delims = rwd.delim_2;
                    break;

                case 3:
                    words  = rw.rw_3;
                    delims = rwd.delim_3;
                    break;

                case 4:
                    words  = rw.rw_dtype;
                    delims = rwd.delim_dtype;
                    break;

                case 5:
                    words  = rw.rw_bool;
                    delims = rwd.delim_bool;
                    break;

                case 6:
                    words.Add("PS");
                    break;
                }
                //Check Reserved Words
                foreach (char c in txt)
                {
                    limit = words.Count - 1;
                    temp  = new List <string>();
                    found = false;
                    foreach (string w in words)
                    {
                        //IF NOT OUT OF RANGE
                        if ((w.Length - 1) >= ctr)
                        {
                            //IF LETTER MATCHED
                            if (c == w.ElementAt(ctr))
                            {
                                found = true;
                                //CHECK SIZE OF WORD AND INPUT
                                if (w.Length == tempctr)
                                {
                                    //CHECK DELIMITER
                                    if ((tempctr - 1) == ctr)
                                    {
                                        if (i != 6)
                                        {
                                            foreach (char delim in delims)
                                            {
                                                //IF NOT OUT OF RANGE
                                                if ((txt.Length - 1) > ctr)
                                                {
                                                    //IF FOUND DELIMITER
                                                    if (txt[ctr + 1] == delim)
                                                    {
                                                        hastoken = true;
                                                        nodelim  = false;
                                                        if (w == "Yes" || w == "No")
                                                        {
                                                            t.setTokens("boollit");
                                                        }
                                                        else
                                                        {
                                                            t.setTokens(w);
                                                        }
                                                        t.setLexemes(w);
                                                        t.setAttributes(w);
                                                        token.Add(t);
                                                        valid++;
                                                        break;
                                                    }
                                                }
                                                else if (w == words[limit] && hastoken == false)
                                                {
                                                    found = false;
                                                }
                                            }

                                            if (hastoken == false)
                                            {
                                                hastoken = true;
                                                nodelim  = false;
                                                found    = true;
                                                t.setTokens("NODELIM");
                                                t.setLexemes(w);
                                                t.setAttributes(w);
                                                token.Add(t);
                                                invalid++;
                                            }
                                            else if (nodelim)
                                            {
                                                hastoken = true;
                                                found    = true;
                                                t.setTokens("INVALID");
                                                t.setLexemes(w);
                                                t.setAttributes(w);
                                                token.Add(t);
                                                invalid++;
                                                break;
                                            }

                                            if (hastoken)
                                            {
                                                break;
                                            }
                                        }
                                        //IF COMMENT
                                        else
                                        {
                                            Boolean endcomment = false;
                                            while (!endcomment)
                                            {
                                                if ((txt.Length - 1) > ctr)
                                                {
                                                    //IF FOUND NEWLINE
                                                    if (txt[ctr + 1] == '\n')
                                                    {
                                                        hastoken   = true;
                                                        nodelim    = false;
                                                        endcomment = true;
                                                    }
                                                }
                                                else
                                                {
                                                    hastoken   = true;
                                                    endcomment = true;
                                                }

                                                if (!endcomment)
                                                {
                                                    ctr++;
                                                }
                                            }

                                            if (hastoken)
                                            {
                                                break;
                                            }
                                            lines++;
                                        }
                                    }
                                    else
                                    {
                                        temp.Add(w);
                                    }
                                }
                            }
                        }
                    }
                    ctr++;
                    words = temp;
                    if (found == false)
                    {
                        break;
                    }
                    if (hastoken)
                    {
                        exitfor = true;
                        break;
                    }
                }
                if (exitfor)
                {
                    exitfor = false;
                    break;
                }
            }

            //IF NOTHING FOUND
            if (found == false)
            {
                hastoken = false;
                foreach (var item in rwd.delim_end)
                {
                    if (txt.ElementAt(ctr - 1) == item)
                    {
                        ifEnd = true;
                    }
                }
                while (ifEnd != true)
                {
                    foreach (var item in rwd.delim_end)
                    {
                        if ((txt.Length) > ctr)
                        {
                            if (txt.ElementAt(ctr) == item)
                            {
                                ifEnd = true;
                                break;
                            }
                        }
                        else
                        {
                            ifEnd = true;
                        }
                    }
                    if (ifEnd != true)
                    {
                        ctr++;
                    }
                }
            }

            if (!(txt.Length >= ctr))
            {
                ctr--;
            }

            return(hastoken);
        }