Exemplo n.º 1
0
Arquivo: Lex.cs Projeto: kd97/Compile
        String printdfa(int line, String nowWord, TokenStruct w)
        {
            String df = "";
            int    id = w.getId();

            if (id == -88)
            {
                df = "< 0,0,7 >< 7,1 - 7,8 >< 8,0 - 7,8 >";
            }
            else if (id == -66)
            {
                df = "< 0,0,7 >< 7,x,9 >< 9,1 - 9a - f,10 >< 10,0 - 9a - f,10 >";
            }
            else if (id == 0)
            {
                df = "< 0,/,3 >< 3,*,4 >< 4,其他,4 >< 4,*,5 >< 5,其他,4 >< 5,*,5 >< 5,/,6 >";
            }
            else if (id == 1 || ((id >= 10) && (id <= 59)))
            {
                df = "< 0,letter_,1 >< 1,letter_,1 >< 1,digit,1 >";
            }
            else if (id >= 90 && id <= 139)
            {
                df = "< 0,op,20 >< 1,op,21 >";
            }
            else if (id >= 60 && id <= 89)
            {
                int iso = 0;
                iso = isOperate(nowWord);
                if (iso != -1)
                {
                    df = "< 0,op,20 >< 1,op,21 >";
                }
                else
                {
                    df = "< 0,界符,2 >";
                }
            }
            else if (id == 2 || id == 4)
            {
                df = "<0,digit,11><11,digit,11><11,.,12><11,E,14><12,digit,13><13,digit,13><13,E,14><14,+-,15><14,digit,16><15,digit,16><16,digit,16>";
            }
            else if (id == 3)
            {
                df = "<0,',17><17,letter_,18><18,',19>";
            }
            else
            {
                df = "";
            }
            String dfa = "line " + line + "\t" + nowWord + "\t" + df + "\r\n";

            return(dfa);
        }
Exemplo n.º 2
0
Arquivo: Lex.cs Projeto: kd97/Compile
        String getTokenOut(int line, String nowWord, TokenStruct w)
        {
            if (w.getId() == -88 || w.getId() == -66)
            {
                return("line " + line + "\t" + nowWord + "\t( " + w.getWord() + ", " + w.getId() + ", " + w.getDecri() + ")\r\n");
            }

            else if (w.getId() == 0)
            {
                return("line " + line + "\t" + "注释" + "\t( " + w.getWord() + ", " + w.getId() + ", " + w.getDecri() + ")\r\n");
            }
            else if (w.getId() <= 5)
            {
                return("line " + line + "\t" + nowWord + "\t( " + w.getWord() + ", " + w.getId() + ", " + w.getDecri() + ")\r\n");
            }
            else
            {
                return("line " + line + "\t" + nowWord + "\t( " + w.getWord() + ", " + w.getId() + ", " + w.getDecri() + ")\r\n");
            }
        }
Exemplo n.º 3
0
Arquivo: Lex.cs Projeto: kd97/Compile
        TokenStruct intConst;                        //整型常量



        //词法分析类构造方法
        public Lex()
        {
            identify  = new TokenStruct("IDN", 1, "identify");
            intConst  = new TokenStruct("INT", 2, "int");
            charConst = new TokenStruct("CHAR", 3, "char");


            floatConst  = new TokenStruct("FLOAT", 4, "float");
            stringConst = new TokenStruct("STRING", 5, "string");
            note        = new TokenStruct("Note", 0, "注释");


            eighth = new TokenStruct("Eight", -88, "八进制");
            sixth  = new TokenStruct("Six", -66, "十六进制");
            help   = new Help();


            StreamReader r = new StreamReader(@"..\\..\\tool\\keyword.txt");

            String temp;

            for (int i = 0; i < 50; i++)
            {
                temp = r.ReadLine();
                if (temp == null || temp.Equals(""))
                {
                    break;
                }
                keyword[i] = new TokenStruct(temp, 10 + i, temp);
            }
            r.Close();



            r = new StreamReader(@"..\\..\\tool\\singleDelimiters.txt");
            String[] s;
            for (int i = 0; i < 30; i++)
            {
                temp = r.ReadLine();
                if (temp == null || temp.Equals(""))
                {
                    break;
                }

                s = temp.Split(new char[] { '\t' });
                singleDelimiters[i] = new TokenStruct(s[0], 60 + i, s[1]);
            }
            r.Close();



            r = new StreamReader(@"..\\..\\tool\\dualDelimiters.txt");
            for (int i = 0; i < 50; i++)
            {
                temp = r.ReadLine();
                if (temp == null || temp.Equals(""))
                {
                    break;
                }

                s = temp.Split(new char[] { '\t' });
                dualDelimiters[i] = new TokenStruct(s[0], 90 + i, s[1]);
            }
            r.Close();
        }