Пример #1
0
        private void rightSideVarConst(GrammarParser.AssignmentContext context)
        {
            String       rightSideName = context.Identifier(1).GetText();
            VarConstItem rightSideVar  = null;

            if (localSymbolTable.ContainsVarConstItem(rightSideName))
            {
                rightSideVar = localSymbolTable.GetVarConstItemByName(rightSideName);
            }
            else if (globalSymbolTable.ContainsVarConstItem(rightSideName))
            {
                rightSideVar = globalSymbolTable.GetVarConstItemByName(rightSideName);
            }
            else
            {
                Console.WriteLine("Promena na prave strane neexistuje");
            }

            int varLevel    = rightSideVar.GetLevel();
            int levelToMove = Math.Abs(level - varLevel);

            AddLOD(levelToMove, rightSideVar.GetAddress());

            /*varLevel = retValTo.GetLevel();
             * levelToMove = Math.Abs(level - varLevel);
             * AddSTO(levelToMove, retValTo.GetAddress());*/
        }
Пример #2
0
        public override int VisitAssignment([NotNull] GrammarParser.AssignmentContext context)
        {
            String retValToName = context.Identifier(0).GetText();

            if (localSymbolTable.ContainsVarConstItem(retValToName))
            {
                retValTo = localSymbolTable.GetVarConstItemByName(retValToName);
            }
            else if (globalSymbolTable.ContainsVarConstItem(retValToName))
            {
                retValTo = globalSymbolTable.GetVarConstItemByName(retValToName);
            }
            else
            {
                Console.WriteLine("Promena na levy strane neexistuje");
            }

            if (context.function_call() != null)
            {
                Console.WriteLine("PRAVA strana: function");
            }
            else if (context.expression() != null)
            {
                Console.WriteLine("PRAVA strana: expression");
            }
            else if (context.Identifier(1) != null)
            {
                Console.WriteLine("PRAVA strana: identifier");
                rightSideVarConst(context);
            }
            else  // jinak je na pravo nejaka hodnota int, double, bool
            {
                Console.WriteLine("PRAVA strana: int, double, bool hodnota");
                rightSideValue(context);
            }

            base.VisitAssignment(context);

            // pokud se neco returnuje, tady muzu resit kam to dat
            // z VisitFunction_return bude navrcholu zasobniku nejaky cislo, pokud teda bude
            // tyhle radky maj vsechny prirazeni spolecny, vsechny nechaj na vrcholu neco, co se potom musi storenout nekam (krome kdyz se jen vola fce)
            // funkce se jeste musi udelat pres tu specialni misto v pameti asi
            if (retValTo != null)
            {
                int varLevel    = retValTo.GetLevel();
                int varAddress  = retValTo.GetAddress();
                int levelToMove = Math.Abs(level - varLevel);
                AddSTO(levelToMove, varAddress);
            }

            /*int varLevel = retValTo.GetLevel();
             * int levelToMove = Math.Abs(level - varLevel);
             * AddSTO(levelToMove, retValTo.GetAddress());*/

            retValTo = null;

            return(0);
        }