public bool getSemi()
        {
            semiExp.RemoveRange(0, semiExp.Count);  // empty container
            do
            {
                get();
                if (currTok == "")
                {
                    return(false);  // end of file
                }
                //if (returnNewLines || currTok != "\n")
                semiExp.Add(currTok);
            } while (!isTerminator(currTok) || count == 0);

            // if for then append next two semiExps, e.g., for(int i=0; i<se.count; ++i) {

            trim();

            if (semiExp.Contains("for"))
            {
                SemiExp se = clone();
                getSemi();                  // note recursive call
                se.Add(semiExp.ToArray());
                getSemi();
                se.Add(semiExp.ToArray());
                semiExp.Clear();
                for (int i = 0; i < se.count; ++i)
                {
                    semiExp.Add(se[i]);
                }
            }
            return(semiExp.Count > 0);
        }
Beispiel #2
0
        public bool getSemi()
        {
            semiExp.RemoveRange(0, semiExp.Count);
            do
            {
                get();
                if (currTok == "")
                    return false;

                semiExp.Add(currTok);
            } while (!isTerminator(currTok) || count == 0);

            trim();

            if (semiExp.Contains("for"))
            {
                SemiExp se = clone();
                getSemi();
                se.Add(semiExp.ToArray());
                getSemi();
                se.Add(semiExp.ToArray());
                semiExp.Clear();
                for (int i = 0; i < se.count; ++i)
                    semiExp.Add(se[i]);
            }
            return (semiExp.Count > 0);
        }
Beispiel #3
0
        //----< make a copy of semiEpression >-------------------------------

        public SemiExp clone()
        {
            SemiExp copy = new SemiExp();
            for (int i = 0; i < count; ++i)
            {
                copy.Add(this[i]);
            }
            return copy;
        }
Beispiel #4
0
 public void trim()
 {
     SemiExp temp = new SemiExp();
     foreach (string tok in semiExp)
     {
         if (isWhiteSpace(tok))
             continue;
         temp.Add(tok);
     }
     semiExp = temp.semiExp;
 }
Beispiel #5
0
            public bool testSemi(string path)
            {
                SemiExp Semitest = new SemiExp();

                SemiExp test = new SemiExp();
                string testFile = path;
                if (!test.open(testFile))
                    Console.Write("\n  Can't open file {0}", testFile);
                while (test.getSemi())
                    test.display();
                return true;
            }
        static void Main(string[] args)
        {
            Console.Write("\n  Testing semiExp Operations");
            Console.Write("\n ============================\n");

            SemiExp test = new SemiExp();

            test.returnNewLines  = true;
            test.displayNewLines = true;

            //string testFile = "../../testSemi.txt";
            string testFile = "../../testSemi.txt";

            if (!test.open(testFile))
            {
                Console.Write("\n  Can't open file {0}", testFile);
            }
            Console.Write("\n  processing file: {0}\n", testFile);
            while (test.getSemi())
            {
                test.display();
            }

            test.initialize();
            test.insert(0, "this");
            test.insert(1, "is");
            test.insert(2, "a");
            test.insert(3, "test");
            test.display();

            Console.Write("\n  2nd token = \"{0}\"\n", test[1]);

            Console.Write("\n  removing first token:");
            test.remove(0);
            test.display();
            Console.Write("\n");

            Console.Write("\n  removing token \"test\":");
            test.remove("test");
            test.display();
            Console.Write("\n");

            Console.Write("\n  making copy of semiExpression:");
            SemiExp copy = test.clone();

            copy.display();
            Console.Write("\n");

            if (args.Length == 0)
            {
                Console.Write("\n  Please enter name of file to analyze\n\n");
                return;
            }
            SemiExp semi = new SemiExp();

            semi.returnNewLines = false;
            if (!semi.open(args[0]))
            {
                Console.Write("\n  can't open file {0}\n\n", args[0]);
                return;
            }

            Console.Write("\n  Analyzing file {0}", args[0]);
            Console.Write("\n ----------------------------------\n");

            while (semi.getSemi())
            {
                semi.display();
            }
            semi.close();
        }