示例#1
0
        public static void PrintDoWhileLoop(ADDoWhileLoop loop, string tab)
        {
            Console.WriteLine($"{tab}|- Do-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");
                }
            }
        }
        public static IADNode DoWhileLoop()
        {
            MainFSM.GetNextToken();

            var result = new ADDoWhileLoop();

            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();

            if (MainFSM.GetNextToken().Type != TokenType.whileType)
            {
                ParserFunctions.SyntaxError("Bylo ocekavano klicove slovo while");
            }

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

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

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

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

            return(result);
        }
示例#3
0
        public static void PrintDoWhileLoop(ADDoWhileLoop doWhileLoop, string returnLabel)
        {
            var bodyLabel      = GenerateLabel();
            var endLabel       = GenerateLabel();
            var conditionLabel = GenerateLabel();

            Console.WriteLine($"{bodyLabel}:");
            foreach (var item in doWhileLoop.Body)
            {
                PrintNode(item, endLabel, conditionLabel, returnLabel);
            }

            Console.WriteLine("#Podminka cyklu do-while");
            Console.WriteLine($"{conditionLabel}:");
            Console.WriteLine(PrintExpression(doWhileLoop.Condition));
            EvalCondition(endLabel);

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