Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Write("\n  testing Semi");
            Console.Write("\n ==============");

            // Access Semi through interface and object factory.
            // That isolates client from any changes that may occur to Semi
            // as long as ITokenCollection doesn't change.

            ITokenCollection semi = Factory.create();

            string source = "../../semi.cs";
            if (!semi.open(source))
            {
                Console.Write("\n  Can't { 0}\n", source);
              return;
            }
            while (!semi.isDone())
            {
                semi.get();
                semi.show();
            }
            Console.Write("\n");

            Console.Write("\n  demonstrating semi operations");
            Console.Write("\n -------------------------------");

            ITokenCollection test = Factory.create();
            checkSemiTest(test);

            Console.Write("\n\n");
        }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     Console.Write("\n  testing Semi");
     Console.Write("\n ==============");
     ITokenCollection semi = Factory.create();
     TestOperation(semi);
     Console.Write("\n  demonstrating semi operations\n");
     ITokenCollection test = Factory.create();
     test.add("one").add("two").add("three");
     test.show();
     if (test.hasSequence("one", "three"))
         Console.Write("\n  semi has token \"one\" followed by token \"three\"");
     if (!test.hasSequence("foo", "two"))
         Console.Write("\n  semi does not have token \"foo\" followed by token \"two\"");
     if (!test.hasTerminator())
         Console.Write("\n  semi does not have terminator");
     Console.Write("\n  demonstrate changing semi with insert and add");
     test.insert(0, "#");
     test.add("\n");
     test.show();
     DemoSemiTst(test);
     int index; Token tok = "two";
     if (test.find(tok, out index))
         Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
     else
         Console.Write("\n  did not find token \"{0}\"", tok);
     tok = "foo";
     if (test.find(tok, out index))
         Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
     else
         Console.Write("\n  did not find token \"{0}\"", tok);
     tok = "one";
     Token tok2 = test.predecessor(tok);
     Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);
     tok = "bar";tok2 = test.predecessor(tok);
     Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);
     Console.Write("\n  indexing semi\n  ");
     for (int i = 0; i < test.size(); ++i)
         Console.Write("{0} ", test[i]);
     Console.Write("\n  using foreach:\n  ");
     foreach (var tk in test)
         Console.Write("{0} ", tk);
 }
Ejemplo n.º 3
0
    static void Main(string[] args)
    {
      Console.Write("\n  testing Semi");
      Console.Write("\n ==============");

      

      ITokenCollection semi = Factory.create();

      string source = "../../semi.cs";
      if (!semi.open(source))
      {
        Console.Write("\n  Can't open {0}\n", source);
        return;
      }
      while (!semi.isDone())
      {
        semi.get();
        semi.show();
      }
      Console.Write("\n");

      Console.Write("\n  demonstrating semi operations");
      Console.Write("\n -------------------------------");

      ITokenCollection test = Factory.create();

      test.add("one").add("two").add("three");
      test.show();
      if (test.hasSequence("one", "three"))
        Console.Write("\n  semi has token \"one\" followed by token \"three\"");
      if (!test.hasSequence("foo", "two"))
        Console.Write("\n  semi does not have token \"foo\" followed by token \"two\"");
      if (!test.hasTerminator())
        Console.Write("\n  semi does not have terminator");

      Console.Write("\n  demonstrate changing semi with insert and add");
      test.insert(0, "#");
      test.add("\n");
      test.show();

      Console.Write("\n  demonstrate semi tests");
      if (test.hasTerminator())
        Console.Write("\n  semi has terminator");
      else
        Console.Write("\n  semi does not have terminator");

      int index;
      Token tok = "two";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);
      tok = "foo";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);

      tok = "one";
      Token tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);
      tok = "bar";
      tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);

      Console.Write("\n  indexing semi\n  ");
      for (int i = 0; i < test.size(); ++i)
        Console.Write("{0} ", test[i]);
      Console.Write("\n  using foreach:\n  ");
      foreach (var tk in test)
        Console.Write("{0} ", tk);

      Console.Write("\n\n");
    }
Ejemplo n.º 4
0
    static void Main(string[] args)
    {
      Console.Write("\n  testing Semi");
      Console.Write("\n ==============");

      // Access Semi through interface and object factory.
      // That isolates client from any changes that may occur to Semi
      // as long as ITokenCollection doesn't change.

      ITokenCollection semi = Factory.create();

      string source = "C:\\Project2\\TestTypeAnaylyzer\\RulesAndActions.cs";
      if (!semi.open(source))
      {
        Console.Write("\n  Can't open {0}\n", source);
        return;
      }
      while (!semi.isDone())
      {
        semi.get();
        semi.show();
      }
      Console.Write("\n");

      Console.Write("\n  demonstrating semi operations");
      Console.Write("\n -------------------------------");

      ITokenCollection test = Factory.create();

      test.add("one").add("two").add("three");
      test.show();
      if (test.hasSequence("one", "three"))
        Console.Write("\n  semi has token \"one\" followed by token \"three\"");
      if (!test.hasSequence("foo", "two"))
        Console.Write("\n  semi does not have token \"foo\" followed by token \"two\"");
      if (!test.hasTerminator())
        Console.Write("\n  semi does not have terminator");

      Console.Write("\n  demonstrate changing semi with insert and add");
      test.insert(0, "#");
      test.add("\n");
      test.show();

      Console.Write("\n  demonstrate semi tests");
      if (test.hasTerminator())
        Console.Write("\n  semi has terminator");
      else
        Console.Write("\n  semi does not have terminator");

      int index;
      Token tok = "two";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);
      tok = "foo";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);

      tok = "one";
      Token tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);
      tok = "bar";
      tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);

      Console.Write("\n  indexing semi\n  ");
      for (int i = 0; i < test.size(); ++i)
        Console.Write("{0} ", test[i]);
      Console.Write("\n  using foreach:\n  ");
      foreach (var tk in test)
        Console.Write("{0} ", tk);

      Console.Write("\n\n");
            Console.ReadKey();
    }