예제 #1
0
        private static void DoTest(List <Item> testData, ISymbolTable symbolTable)
        {
            Stack <Item> inserted = new Stack <Item>(testData.Count);
            Random       r        = new Random(DateTime.Now.Millisecond);
            DateTime     start    = DateTime.Now;

            foreach (Item item in testData)
            {
                symbolTable.Insert(item);
                inserted.Push(item);
            }
            foreach (Item item in inserted.Reverse())
            {
                Item found = symbolTable.Search(item.Key);
                if (!found.Value.Equals(item.Value))
                {
                    throw new Exception();
                }
            }
            for (int i = 0; i < testData.Count; i++)
            {
                int  randomIndex = r.Next(testData.Count);
                Item searched    = testData[randomIndex];
                Item found       = symbolTable.Search(searched.Key);
                if (!found.Value.Equals(searched.Value))
                {
                    throw new Exception();
                }
            }
            DateTime finish = DateTime.Now;
            TimeSpan span   = finish - start;

            Console.WriteLine("Timing for {0}: {1} ms", symbolTable.GetType(), span.TotalMilliseconds);
        }
예제 #2
0
 private static void DoTest(List<Item> testData, ISymbolTable symbolTable)
 {
     Stack<Item> inserted = new Stack<Item>(testData.Count);
     Random r = new Random(DateTime.Now.Millisecond);
     DateTime start = DateTime.Now;
     foreach (Item item in testData)
     {
         symbolTable.Insert(item);
         inserted.Push(item);
     }
     foreach (Item item in inserted.Reverse())
     {
         Item found = symbolTable.Search(item.Key);
         if (!found.Value.Equals(item.Value))
         {
             throw new Exception();
         }
     }
     for (int i = 0; i < testData.Count; i++)
     {
         int randomIndex = r.Next(testData.Count);
         Item searched = testData[randomIndex];
         Item found = symbolTable.Search(searched.Key);
         if (!found.Value.Equals(searched.Value))
         {
             throw new Exception();
         }
     }
     DateTime finish = DateTime.Now;
     TimeSpan span = finish - start;
     Console.WriteLine("Timing for {0}: {1} ms", symbolTable.GetType(), span.TotalMilliseconds);
 }
예제 #3
0
        private void MainClass()
        {
            Match(Tokens.FinalT);
            Match(Tokens.ClassT);
            _symTab.Insert(Globals.Lexeme, Globals.Token, Globals.Depth, EntryType.ClassType);
            var type = _symTab.Lookup(Globals.Lexeme);

            type.TypeOfEntry = new Union <EntryType>(new ClassType(), EntryType.ClassType);
            _tacWriter.PrintLine("proc main");
            _asmWriter.MainProc = "main";
            _asmWriter.AddFunction(new TableNode
            {
                Depth       = Globals.Depth,
                Lexeme      = new Lexeme("main"),
                Token       = Tokens.MainT,
                TypeOfEntry = new Union <EntryType>(new FunctionType(), EntryType.FunctionType)
            });
            Match(Tokens.IdT);
            //Globals.Depth++;
            Match(Tokens.LBraceT);
            Match(Tokens.PublicT);
            Match(Tokens.StaticT);
            Match(Tokens.VoidT);
            //_symTab.Insert("Main", Tokens.IdT, Globals.Depth, EntryType.FunctionType);
            Match(Tokens.MainT);
            //Globals.Depth++;
            Match(Tokens.LParenT);
            Match(Tokens.StringT);
            Match(Tokens.LBrackT);
            Match(Tokens.RBrackT);
            // _symTab.Insert(Globals.Lexeme, Globals.Token, Globals.Depth, EntryType.VarType);
            Match(Tokens.IdT);
            Match(Tokens.RParenT);
            //Globals.Depth--;
            Match(Tokens.LBraceT);
            SeqOfStatements();
            Match(Tokens.RBraceT);
            Match(Tokens.RBraceT);
            _tacWriter.PrintLine("endp main");

            //Globals.Depth--;
        }