static void Main()
        {
            Console.Write("\n  Test ScopeStack");
            Console.Write("\n =================\n");

            ScopeStack <Elem> mystack = new ScopeStack <Elem>();

            Test.Elem e;
            e.type  = "namespace";
            e.name  = "foobar";
            e.place = 14;
            mystack.push(e);
            e.make("class", "feebar", 21);
            mystack.push(e);
            e.make("function", "doTest", 44);
            mystack.push(e);
            e.make("control", "for", 56);
            mystack.push(e);

            mystack.display();
            Console.WriteLine();

            Elem test = mystack.lastPopped();

            Console.Write("\n  last popped:\n  {0}\n", test);

            e = mystack.pop();
            Console.Write("\n  popped:\n  {0}", e);
            e = mystack.pop();
            Console.Write("\n  popped:\n  {0}\n", e);
            Console.Write("\n  last popped:\n  {0}\n", mystack.lastPopped());

            mystack.display();

            Console.Write("\n\n");
        }
Ejemplo n.º 2
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem;

            try
            {
                elem = repo_.stack.pop();

                //reverse for loop for anonymous scope

                if (elem.type.Equals("control"))
                {
                    for (int i = repo_.locations.Count - 1; i >= 0; --i)
                    {
                        Elem temp = repo_.locations[i];
                        if (elem.type == temp.type)
                        {
                            if (elem.name == temp.name)
                            {
                                if ((repo_.locations[i]).end == 0)
                                {
                                    (repo_.locations[i]).end = repo_.semi.lineCount;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < repo_.locations.Count; ++i)
                    {
                        Elem temp = repo_.locations[i];
                        if (elem.type == temp.type)
                        {
                            if (elem.name == temp.name)
                            {
                                if ((repo_.locations[i]).end == 0)
                                {
                                    (repo_.locations[i]).end = repo_.semi.lineCount;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(elem.type).Add(elem.name);
            //if(local[0] == "control")
            // return;

            if (AAction.displaySemi)
            {
                Console.Write("\n  line# {0,-5}", repo_.semi.lineCount);
                Console.Write("leaving  ");
                string indent = new string(' ', 2 * (repo_.stack.count + 1));
                Console.Write("{0}", indent);
                this.display(local); // defined in abstract action
            }
        }