Exemplo n.º 1
0
        public bool testToker2(string path)
        {
            Toker toker = new Toker();

            string fqf = System.IO.Path.GetFullPath(path);

            if (!toker.open(fqf))
            {
                Console.Write("\n can't open {0}\n", fqf);
                return(false);
            }
            toker.setSpecialSingleChars(new List <string> {
                "<", ">"
            });
            toker.setSpecialCharPairs(new List <string> {
                "<<", "=="
            });

            while (!toker.isDone())
            {
                Token tok = toker.getTok();
                Console.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok);
            }
            toker.close();

            return(true);
        }
        //----< test for each tokenizer case by index>---
        static private bool testTokenizer(int testIndex)
        {
            Toker        toker = new Toker();
            StreamWriter file  = new StreamWriter("../../" + testCaseResult + testIndex + ".txt");    // read from the testcase cs file

            string fqf = System.IO.Path.GetFullPath("../../" + testCaseFileName + testIndex + ".cs"); // open the write to file

            if (!toker.open(fqf))
            {
                file.Close();
                Console.Write("\n can't open {0}\n", fqf);
                return(false);
            }
            else
            {
                Console.Write("\n  processing file: {0}", fqf);
            }

            // write token into the output file untill eof
            while (!toker.isDone())
            {
                StringBuilder tok = toker.getTok();
                file.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok);
            }
            toker.close();
            file.Close();

            return(compareTwoFiles("../../" + testCaseResult + testIndex + ".txt", "../../" + testCaseResultStandard + testIndex + ".txt"));
        }
Exemplo n.º 3
0
            //----< methods that used to initiate the tokenizer tester>-----------
            public bool testToken(string path)
            {
                string fqf = System.IO.Path.GetFullPath(path);

                if (!toker.open(fqf))
                {
                    Console.Write("\n can't open {0}\n", fqf);
                    return(false);
                }
                while (!toker.isDone())
                {
                    Token tok = toker.getTok();
                    Console.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok);
                }
                toker.close();
                return(true);
            }
Exemplo n.º 4
0
        static bool Requirement4(string file)
        {
            Console.Write("\n\n  Demonstrate requirement 4: ");
            Console.Write("\n ============================\n");

            Console.Write(" The file content: \n\n");
            fs_ = new System.IO.StreamReader("../../" + file, true);
            int ch;

            while (!fs_.EndOfStream)
            {
                ch = fs_.Read();
                Console.Write("{0}", (char)ch);
            }
            fs_.Close();
            Console.Write("\n ============================\n");
            Console.Write("The output: \n");

            Toker toker = new Toker();

            string fqf = System.IO.Path.GetFullPath("../../" + file);

            if (!toker.open(fqf))
            {
                Console.Write("\n can't open {0}\n", fqf);
                return(false);
            }
            else
            {
                Console.Write("\n  processing file: {0}", fqf);
            }
            while (!toker.isDone())
            {
                StringBuilder tok = toker.getTok();
                Console.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok);
            }
            toker.close();

            return(true);
        }
            //----< get next token, saving previous token >----------------------

            public string get()
            {
                try
                {
                    prevTok = currTok;
                    if (!toker.isDone())
                    {
                        currTok   = toker.getTok().ToString();
                        linecount = toker.lineCount();
                    }
                    else
                    {
                        currTok = null;
                        return(null);//no token
                    }
                    return(null);
                }
                catch
                {
                    Console.WriteLine("fail to get Token");
                }
                return(null);
            }