public static StringBuilder Test_inter(String path)
        {
            Token   s  = new Token();
            SemiExp se = new SemiExp();

            s.Append("\n   - Semiexpression : " + se.getSemi(path)).Append(' ', 40 - se.getSemi(path).Length).Append("One SemiExpression.");
            return(s);
        }
Example #2
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);
        }
Example #3
0
 public bool getSemi()
 {
     semiExp.RemoveRange(0, semiExp.Count);  // empty container
     do
     {
         get();
         if (currTok == "")
         {
             break;
         }                               // end of linea
         // check if comment
         if (!discardComments && isComment(currTok))
         {
             semiExp.Add(currTok);
         }
         else if (discardComments && isComment(currTok))
         {
             return(true);
         }
         else if ((currTok == "\r\n") && semiExp.Count > 0)
         {
             if (semiExp[0].StartsWith("#"))
             {
                 semiExp.Add(currTok); break;
             }
         }
         else if (returnNewLines || currTok != "\n")
         {
             semiExp.Add(currTok);
         }
         else
         {
             break;
         }
     } while (!isTerminator(currTok) || count == 0);
     trim();
     if (semiExp.Contains("for"))
     {
         SemiExp se = clone();       // make a copy of the semiExp
         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);
 }
Example #4
0
        public void trim()
        {
            SemiExp temp = new SemiExp();

            foreach (string tok in semiExp)
            {
                if (isWhiteSpace(tok))
                {
                    continue;
                }
                temp.Add(tok);
            }
            semiExp = temp.semiExp;
        }
Example #5
0
        //----< test for equality >------------------------------------------

        override public bool Equals(Object semi)
        {
            SemiExp temp = (SemiExp)semi;

            if (temp.count != this.count)
            {
                return(false);
            }
            for (int i = 0; i < temp.count && i < this.count; ++i)
            {
                if (this[i] != temp[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Example #6
0
            static bool TestSemi(string path)
            {
                SemiExp test = new SemiExp();

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

                if (!test.open(path))
                {
                    Console.Write("\n  Can't open file {0}", path);
                }
                while (test.GetSemi())
                {
                    test.display();
                }
                test.close();
                return(true);
            }
Example #7
0
        //---------< get a set of a semi >------------------------------------
        public bool GetSemi()
        {
            semiExp.RemoveRange(0, semiExp.Count);  // empty container

            do
            {
                strb = toker.getTok();
                if (strb != null)
                {
                    semi = strb.ToString();
                }
                if (isComment(semi))    //throw the comment
                {
                    continue;
                }
                if (strb == null)    //end of file
                {
                    return(false);
                }
                if (returnNewLines || !semi.Equals("\n"))
                {
                    semiExp.Add(semi);
                }
            } while (!isTerminator(semi) || count == 0);

            trim();

            if (semiExp.Contains("for"))
            {
                SemiExp se = clone();
                GetSemi();              //recursively
                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);
        }
        public static StringBuilder Test_semi(String path)
        {
            StringBuilder         str   = new StringBuilder();
            SemiExp               s     = new SemiExp();
            int                   count = 0;
            List <List <string> > s_ex  = s.WholeSemi(path);

            foreach (List <String> t in s_ex)
            {
                if (count > 7)
                {
                    continue;
                }
                StringBuilder msg = new Token();
                for (int i = 0; i < t.Count(); i++)
                {
                    if (!t[i].Equals("\n"))
                    {
                        msg.Append(t[i]);
                        msg.Append(" ");
                    }
                }
                count++;
                str.Append("\n   -  " + msg).Append(' ', 60 - msg.Length);
                if (msg.ToString().Contains("#"))
                {
                    str.Append("| # condition satisfied");
                }
                if (msg.ToString().Contains("for"))
                {
                    str.Append("| for condition satisfied");
                }
                if (msg.ToString().Contains("{") || msg.ToString().Contains("}") || msg.ToString().Contains(";") && !msg.ToString().Contains("for"))
                {
                    str.Append("| end condition satisfied");
                }
            }
            return(str);
        }
        public static StringBuilder Test_semi_here(String path)
        {
            StringBuilder         str   = new StringBuilder();
            SemiExp               s     = new SemiExp();
            int                   count = 0;
            List <List <string> > s_ex  = s.WholeSemi(path);

            foreach (List <String> t in s_ex)
            {
                StringBuilder msg = new Token();
                for (int i = 0; i < t.Count(); i++)
                {
                    if (!t[i].Equals("\n"))
                    {
                        msg.Append(t[i]);
                        msg.Append(" ");
                    }
                }
                count++;
                str.Append("\n   -  " + msg);
            }
            return(str);
        }
Example #10
0
        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 = "../../Dev_SemiExpTest.cs";

            //string testFile = "../../test3.cs";
            if (!test.open(testFile))
            {
                Console.Write("\n  Can't open file {0}", testFile);
            }
            while (test.getSemi())
            {
                if (test.gotCollection() != "")
                {
                    //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();
        }