Ejemplo n.º 1
0
        public static IADNode WhileLoop()
        {
            MainFSM.GetNextToken();

            if (MainFSM.GetNextToken().Type != TokenType.leftRBType)
            {
                ParserFunctions.SyntaxError("Byl ocekavan znak \'(\'");
            }

            var result = new ADWhileLoop();

            result.Condition = PrecedenceSyntaxAnalysis.Precedence(TokenType.rightRBType);

            if (MainFSM.GetNextToken().Type != TokenType.rightRBType)
            {
                ParserFunctions.SyntaxError("Byl ocekavan znak \')\'");
            }

            if (MainFSM.GetNextToken().Type != TokenType.leftCBType)
            {
                ParserFunctions.SyntaxError("Byl ocekavan znak \'{\'");
            }

            ParserFunctions.STablesStack.Push(new STable());
            result.Body = ParserFunctions.statement_list();

            if (MainFSM.GetNextToken().Type != TokenType.rightCBType)
            {
                ParserFunctions.SyntaxError("Byl ocekavan znak \'}\'");
            }

            ParserFunctions.STablesStack.Pop();

            return(result);
        }
Ejemplo n.º 2
0
        public static void PrintWhileLoop(ADWhileLoop loop, string tab)
        {
            Console.WriteLine($"{tab}|- While loop");

            Console.WriteLine($"{tab}|\tCondition:");
            PrintExpression(loop.Condition, tab + "\t\t");

            if (loop.Body.Count() > 0)
            {
                Console.WriteLine($"{tab}|\tBody:");
                foreach (var node in loop.Body)
                {
                    PrintNode(node, tab + "\t\t");
                }
            }
        }
Ejemplo n.º 3
0
        public static void PrintWhileLoop(ADWhileLoop whileLoop, string returnLabel)
        {
            var conditionLabel = GenerateLabel();
            var endLabel       = GenerateLabel();

            Console.WriteLine($"{conditionLabel}:");

            Console.WriteLine("# podminkova cast");
            Console.WriteLine(PrintExpression(whileLoop.Condition));


            Console.WriteLine("# Vyhodnoceni podminky");
            EvalCondition(endLabel);

            Console.WriteLine("# telo cyklu");
            foreach (var item in whileLoop.Body)
            {
                PrintNode(item, endLabel, conditionLabel, returnLabel);
            }

            Console.WriteLine($"jmp {conditionLabel}");
            Console.WriteLine($"{endLabel}:");
        }