コード例 #1
0
        private BaseAst GetWhileAST(WhileAst cmd)
        {
            if (cmd == null)
            {
                return(BaseAst.GetErrorAstNode("Chybne volana funkce 'GetWhileAST(WhileAst cmd)', parametr 'cmd' je null"));
            }

            BaseAst cond;
            BaseAst tmp = GetCondAST(out cond);

            if (tmp.IsError)
            {
                return(tmp);
            }
            cmd.Condition = cond;

            BaseAst st = StatementOrBlock();

            if (st.IsError)
            {
                return(st);
            }
            cmd.WhileBody = st;

            return(cmd);
        }
コード例 #2
0
        private void WriteWhile(WhileAst ast, List<string> vars, string p, bool writeLE)
        {
            file.WriteLine("{0}while ({1})", p, GetExpr(ast.Condition));
            if (writeLE)
                WriteLinearEquations(ast.ConvertCondition.Node, vars, p);

            WriteBody(ast.WhileBody, vars, p, writeLE);
            if (writeLE)
                WriteLinearEquations(ast.ConvertWhileEndBody.Node, vars, p);
        }
コード例 #3
0
        private IEnumerable <BaseAst> ConvertWhile(WhileAst node)
        {
            List <BaseAst> block = new List <BaseAst>();

            internalLabelIdx++;
            int idx = internalLabelIdx;

            block.Add(new BaseAst {
                Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$WhileBegin{0}", idx)
            });

            ConditionAst cond = ConvertTo <ConditionAst>(node, AstNodeTypes.Condition);

            cond.Condition = NegateCondition(node.Condition);
            block.Add(cond);
            node.ConvertCondition = cond;

            GotoAst gt = new GotoAst {
                Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$WhileEnd{0}", idx)
            };

            block.Add(gt);
            node.ConvertWhileEndBody = gt;

            block.Add(new BaseAst {
                Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$WhileTrue{0}", idx)
            });
            block.AddRange(ConvertStatement(node.WhileBody));
            block.Add(new GotoAst {
                Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$WhileBegin{0}", idx)
            });

            block.Add(new BaseAst {
                Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$WhileEnd{0}", idx)
            });

            return(block);
        }
コード例 #4
0
 private BaseAst CheckFunctionCallsInWhileAST(ProgramAst program, WhileAst cmd)
 {
     return(CheckFunctionCallsInStatementAST(program, cmd.WhileBody));
 }