예제 #1
0
        public string GetWhileInt(int count, checkMethods check, char[] array, string startStr)
        {
            checkMethods checkDeleget = check;
            string       temp         = "";

            temp += startStr;
            count++;
            count++;
            //if doesnt reach to the end of arr of characters and this char is number
            while (count < array.Length && checkDeleget(array[count].ToString()))
            {
                temp += array[count];
                count++;
            }
            currentCharCount = count;
            return(temp);
        }
예제 #2
0
        public string GetWhileKeyword(int count, checkMethods check, char[] array, char startChar)
        {
            checkMethods checkDeleget = check;
            string       temp         = "";

            temp += startChar;
            count++;

            while (count < array.Length && checkRestOfKeyWordOrIdentOrNo(array[count].ToString()))
            {
                temp += array[count];
                count++;
                if (checkDeleget(temp) == true)
                {
                    break;
                }
            }


            currentCharCount = count;
            return(temp);
        }
예제 #3
0
        void get_tokens(string[] strArray)
        {
            int           _currentLine = 0;
            List <string> Code         = Comment.IgnoreComments(strArray);

            //traverse each line
            foreach (string item in Code)
            {
                List <string> splitedLine = ClearWhiteSpaceInLine(item);


                //traverse each token in a specific line
                for (int i = 0; i < splitedLine.Count; i++)
                {
                    char[] charToken = splitedLine[i].ToCharArray();
                    currentCharCount = 0;
                    //traverse each char in a specific token
                    for (int j = 0; j < charToken.Length; j++)
                    {
                        if (currentCharCount >= charToken.Length)
                        {
                            break;
                        }
                        char currentChar = CurrentChar(charToken, currentCharCount);


                        if (checkIsStartOfKeyWordOrIdentOrNo(currentChar.ToString()) == true)
                        {
                            //MessageBox.Show("keyOrident : " + currentChar.ToString() + " count " + currentCharCount);

                            string       keywordOrIdentOrNumber = "";
                            checkMethods keywordCheck           = new checkMethods(checkReservedWord);
                            keywordOrIdentOrNumber += GetWhileKeyword(currentCharCount, keywordCheck, charToken, currentChar);

                            if (checkReservedWord(keywordOrIdentOrNumber))
                            {
                                if (keywordOrIdentOrNumber == "using")
                                {
                                    usingKeyWord(splitedLine);
                                    reservedWordResult.Add(keywordOrIdentOrNumber);
                                    T_Desc    = "ReverseWord";
                                    T_Content = keywordOrIdentOrNumber;

                                    if (resultUsingFlag)
                                    {
                                        // x = (splitedLine.Count - 1) - i;
                                        i = splitedLine.Count - 1;
                                    }
                                }
                                else
                                {
                                    reservedWordResult.Add(keywordOrIdentOrNumber);
                                    T_Desc = "ReverseWord";
                                }
                            }
                            else if (checkDigits(keywordOrIdentOrNumber))
                            {
                                DigitsResult.Add(keywordOrIdentOrNumber);
                                T_Desc = "Constant";
                            }


                            else if (checkValidIdentifier(keywordOrIdentOrNumber))
                            {
                                if ((new[] { "and", "or", "not" }.Contains(keywordOrIdentOrNumber)))
                                {
                                    specialCharactersResult.Add(keywordOrIdentOrNumber);
                                    T_Desc = "Symbol";
                                }
                                else
                                {
                                    IdentifiersResult.Add(keywordOrIdentOrNumber);
                                    T_Desc = "Identifier";
                                }
                            }
                            else
                            {
                                T_Desc = "lexical Errors";
                                MessageBox.Show("lexical Errors '" + keywordOrIdentOrNumber + "'! at line:" + _currentLine);
                            }


                            T_Content = keywordOrIdentOrNumber;
                        }//end checkIsStartOfKeyWordOrIdentOrNo


                        else if (checkSpecialCharacters(currentChar.ToString()) == true)
                        {
                            if ((new[] { '<', '>', '=', '!' }.Contains(currentChar)) && NextChar(charToken, currentCharCount) == '=')
                            {
                                currentCharCount++;
                                currentCharCount++;
                                specialCharactersResult.Add(currentChar.ToString() + "=");
                                T_Desc    = "Symbol";
                                T_Content = currentChar.ToString();
                            }

                            else if ((new[] { '+', '-' }.Contains(currentChar)) && (char.IsDigit(NextChar(charToken, currentCharCount))))
                            {
                                string       AssignAndStartNo = currentChar.ToString() + NextChar(charToken, currentCharCount);
                                string       intNumber        = "";
                                checkMethods numberCheck      = new checkMethods(checkDigits);
                                intNumber += GetWhileInt(currentCharCount, numberCheck, charToken, AssignAndStartNo);
                                DigitsResult.Add(intNumber);

                                T_Desc    = "Constant";
                                T_Content = intNumber;
                            }

                            /*   else if ((currentChar == '.') && (char.IsLetter(PrevChar(charToken, currentCharCount))))
                             * {
                             *     currentCharCount++;
                             *     specialCharactersResult.Add(currentChar.ToString());
                             *     T_Desc = "Symbol";
                             *     T_Content = currentChar.ToString();
                             * }
                             */
                            else
                            {
                                currentCharCount++;
                                specialCharactersResult.Add(currentChar.ToString());
                                T_Desc    = "Symbol";
                                T_Content = currentChar.ToString();
                            }
                        }//check special symbols

                        else
                        {
                            T_Desc    = "Illegal characters";
                            T_Content = currentChar.ToString();
                            MessageBox.Show("Illegal characters '" + currentChar.ToString() + "' ! at line:" + _currentLine);
                        }


                        ListViewItem List_item = new ListViewItem(_currentLine.ToString());
                        List_item.SubItems.Add(T_Desc);
                        List_item.SubItems.Add(T_Content);
                        ListViewDetails.Items.Add(List_item);
                    } //end for char
                }     //end for token


                _currentLine++;
            } //end foreach lines
        }     //end get_tokens() fun