Beispiel #1
0
        static void Lexer(List <String> Token_Holder, StreamWriter sw, List <String> Token_Eval_Holder)
        {
            bool comment = false;

            foreach (string s in Token_Holder)
            {
                MachineState = 0;
                while (MachineState == 0)
                {
                    string word = s.Trim();
                    if (word == "!")
                    {
                        comment = !comment; break;
                    }
                    if (comment)
                    {
                        break;
                    }
                    if (word == " " || word == "" || word == "  ")
                    {
                        if (s == "\n" || s == "\r" || s == "\r\n")
                        {
                            TheNumber++;
                        }
                        break;
                    }

                    LineNumber.Add(TheNumber);
                    Main_Token_Holder.Add(word);
                    if (Keywords.Contains(word))
                    {
                        MachineState = DFATable[2, MachineState];
                    }
                    else if (Seperators.Contains(word))
                    {
                        MachineState = DFATable[3, MachineState];
                    }
                    else if (Operators.Contains(word))
                    {
                        MachineState = DFATable[1, MachineState];
                    }
                    else
                    {
                        MachineState = DFATable[0, MachineState];
                    }


                    switch (MachineState)
                    {
                    case 1:
                        Console.Write("\t\t\t SEPARATOR");

                        Token_Eval_Holder.Add("SEPARATOR");
                        break;

                    case 2:
                        Console.Write("\t\t\t KEYWORDS");

                        Token_Eval_Holder.Add("KEYWORDS");
                        break;

                    case 3:
                        Console.Write("\t\t\t OPERATORS");

                        Token_Eval_Holder.Add("OPERATORS");
                        break;

                    case 4:
                        int intstate = 1;
                        //Seperate check for int vs. float
                        if (Integers.Contains(word[0]))
                        {
                            foreach (char c in word)
                            {
                                if (Integers.Contains(c))
                                {
                                    intstate = DFAFloatIntTable[intstate - 1, 0];
                                }
                                else if (c == '.')
                                {
                                    intstate = DFAFloatIntTable[intstate - 1, 1];
                                }
                                else
                                {
                                    intstate = DFAFloatIntTable[intstate - 1, 2];
                                }
                            }
                            if (intstate == 3)
                            {
                                Console.Write("\t\t\t FLOAT");

                                Token_Eval_Holder.Add("FLOAT");
                                break;
                            }
                            Console.Write("\t\t\t INT");

                            Token_Eval_Holder.Add("INT");
                            break;
                        }
                        Console.Write("\t\t\t IDENTIFIERS");

                        Token_Eval_Holder.Add("IDENTIFIERS");
                        break;

                    default:
                        break;
                    }

                    Console.Write("\n");
                }
            }
        }