Example #1
0
 String getOutput(int line, String nowWord, WordCode w)
 {
     return("line " + line + "\t" + nowWord + "\t( " + w.getWord() + ", " + w.getId() + ", " + w.getDecri() + ")\r\n");
 }
Example #2
0
        //词法分析类构造方法
        public CFFX()
        {
            // identify 标识符

            identify = new WordCode("IDN", 1, "identify");   //根据 (名称,编号,描述)来初始化,符合WordCode类的构造方法

            // const 各类常量

            intConst    = new WordCode("INT", 2, "int");
            charConst   = new WordCode("CHAR", 3, "char");
            floatConst  = new WordCode("FLOAT", 4, "float");
            stringConst = new WordCode("STRING", 5, "string");

            // keyword 关键字
            // 从文件keyword.txt中读取关键字列表,共32个
            StreamReader r = new StreamReader(@"..\\..\\code\\keyword.txt");
            String       temp;

            for (int i = 0; i < 50; i++)
            {
                temp = r.ReadLine();
                if (temp == null || temp.Equals(""))
                {
                    break;
                }
                keyword[i] = new WordCode(temp, 10 + i, temp); //加入关键字数组keyword[]
            }
            r.Close();

            // single delimiters 单个符号 如 + - * / = 等
            // 从code文件夹中的singleDelimiters.txt读取单个符号表,共22个
            r = new StreamReader(@"..\\..\\code\\singleDelimiters.txt");
            String[] s;
            for (int i = 0; i < 30; i++)
            {
                temp = r.ReadLine();
                if (temp == null || temp.Equals(""))
                {
                    break;
                }
                //由于在文件存储的符号后面有对应的解释,故只提取\t前的符号
                s = temp.Split(new char[] { '\t' });
                singleDelimiters[i] = new WordCode(s[0], 60 + i, s[1]); //加入单个符号数组singleDelimiters[]
            }
            r.Close();

            // dual delimiters 双符号
            //从code文件夹中的dualDelimiters.txt文件中读取,共15个
            r = new StreamReader(@"..\\..\\code\\dualDelimiters.txt");
            for (int i = 0; i < 50; i++)
            {
                temp = r.ReadLine();
                if (temp == null || temp.Equals(""))
                {
                    break;
                }
                //由于在文件存储的符号后面有对应的解释,故只提取\t前的符号
                s = temp.Split(new char[] { '\t' });
                dualDelimiters[i] = new WordCode(s[0], 90 + i, s[1]);
            }
            r.Close();
        }