Ejemplo n.º 1
0
 public void AddFunctionRVD(string name, MyFunctionDecleration func)
 {
     functionsRVD.Add(name, func);
 }
Ejemplo n.º 2
0
        private static MyFunctionDecleration GetMyFuncDecl_fibonaci()
        {
            /*
             * fib(n)
                {
                    if (n == 0 || n == 1)
                    {
                      return n;
                    }
                    else
                    {
                      return fib(n - 1) + fib(n - 2);
                    }
                }
             */

            MyIfStatement ifStatement =
                new MyIfStatement(
                    new MyLogicalOrNode(
                        new MyIsEqualsNode(
                            new MyParamValue("n"),
                            new MyValueNode(0)
                            ),
                        new MyIsEqualsNode(
                            new MyParamValue("n"),
                            new MyValueNode(1)
                            )
                        ),
                    new MyStatementListNode(
                        ).AddStatement(
                            new MyReturnStatement(
                                new MyParamValue("n")
                                )
                        ),
                    new MyStatementListNode(
                        ).AddStatement(
                            new MyReturnStatement(
                                new MyAddNode(
                                    new MyFunctionCallNode("fib",
                                        new List<MyAbstractNode>()
                                            {
                                                new MyMinusNode(
                                                    new MyParamValue("n"),
                                                    new MyValueNode(1))
                                            }
                                        ),
                                     new MyFunctionCallNode("fib",
                                        new List<MyAbstractNode>()
                                            {
                                                new MyMinusNode(
                                                    new MyParamValue("n"),
                                                    new MyValueNode(2))
                                            }
                                        )
                                    )
                                )
                        )
                );

            MyFunctionDecleration fib =
                new MyFunctionDecleration(
                    "fib",
                    new List<string>() { "n" }
                    );

            MyStatementListNode fibonaciStmtList = new MyStatementListNode();

            fibonaciStmtList.AddStatement(ifStatement);

            fib.Statements = fibonaciStmtList;
            return fib;
        }
Ejemplo n.º 3
0
        private static MyFunctionDecleration GetMyFuncDecl_func2()
        {
            MyStatementListNode stmtlist2t = new MyStatementListNode()
                .AddStatement(
                    new MyReturnStatement(
                        new MyMultiplyNode(
                            new MyParamValue("p1"),
                            new MyParamValue("p1")
                            )
                         )
                    );

            MyStatementListNode stmtlist2e = new MyStatementListNode()
                .AddStatement(
                    new MyReturnStatement(
                        new MyDivideNode(
                            new MyParamValue("p1"),
                            new MyValueNode(2)
                            )
                         )
                );

            MyIfStatement if2 = new MyIfStatement(
                new MyIsGreaterThanNode(
                    new MyParamValue("p1"),
                    new MyValueNode(100)),
                stmtlist2t,
                stmtlist2e
                );

            ////////////////////////////////////////////////////////////////////////////////

            MyStatementListNode stmtlist1t = new MyStatementListNode()
                .AddStatement(
                    new MyReturnStatement(
                        new MyParamValue("p1")
                        )
                    );

            MyStatementListNode stmtlist1e = new MyStatementListNode()
                .AddStatement(
                    if2
                );

            MyIfStatement if1 =
            new MyIfStatement(
                new MyIsLessThanOrEqualNode(
                    new MyParamValue("p1"),
                    new MyValueNode(0)
                    ),
                    stmtlist1t,
                    stmtlist1e
                );

            MyReturnStatement defaultReturnStmt = new MyReturnStatement(
                new MyValueNode(-1)
                );

            MyStatementListNode func2Stmts = new MyStatementListNode()
                 .AddStatement(if1)
                 .AddStatement(defaultReturnStmt);

            var func2 = new MyFunctionDecleration(
                "func2",
                new List<string>() { "p1" }
                );

            func2.Statements = func2Stmts;

            return func2;
        }
Ejemplo n.º 4
0
        private static MyFunctionDecleration GetMyFuncDecl_func3()
        {
            MyIfStatement if1 = new MyIfStatement(
                new MyIsLessThanNode(
                    new MyParamValue("p1"),
                    new MyValueNode(0)),
                new MyStatementListNode().AddStatement(
                    new MyReturnStatement(
                        new MyValueNode(0)
                        )
                    ),
                    null
                );

            MyAssignmentNode VV = new MyAssignmentNode(
                new MyVariableNode("VV"),
                new MyValueNode(0)
                );

            MyStatementListNode while1Body = new MyStatementListNode()
                .AddStatement(
                    new MyAssignmentNode(
                            new MyVariableNode("VV"),
                            new MyAddNode(
                                new MyVariableNode("VV"),
                                new MyValueNode(1)
                                )
                            )
                        );

            MyWhileStatement while1 =
            new MyWhileStatement(
                new MyIsLessThanOrEqualNode(
                    new MyVariableNode("VV"),
                    new MyParamValue("p1")
                    ),
                    while1Body
                );

            MyReturnStatement defaultReturnStmt = new MyReturnStatement(
                new MyVariableNode("VV")
                );

            MyStatementListNode func3Stmts = new MyStatementListNode()
                 .AddStatement(if1)
                 .AddStatement(VV)
                 .AddStatement(while1)
                 .AddStatement(defaultReturnStmt);

            var func3 = new MyFunctionDecleration(
                "func3",
                new List<string>() { "p1" }
                );

            func3.Statements = func3Stmts;

            return func3;
        }
Ejemplo n.º 5
0
        private static MyFunctionDecleration GetMyFuncDecl_func1()
        {
            MyAssignmentNode assignmentNodeF1 =
                new MyAssignmentNode(
                    new MyVariableNode("XX"),
                    new MyAddNode(
                        new MyParamValue("p1"),
                        new MyValueNode(15)
                        )
                    );

            MyAssignmentNode assignmentNodeF2 =
                new MyAssignmentNode(
                    new MyVariableNode("B"),
                    new MyAddNode(
                        new MyParamValue("p3"),
                        new MyParamValue("p2")
                        )
                    );

            MyReturnStatement func1ReturnStatement =
                new MyReturnStatement(
                    new MyAddNode(
                        new MyVariableNode("B"),
                        new MyVariableNode("XX")
                        )
                    );

            MyFunctionDecleration func1Decl =
                new MyFunctionDecleration(
                    "func1",
                    new List<string>() { "p1", "p2", "p3" }
                    );

            MyStatementListNode func1StmtList = new MyStatementListNode();

            func1StmtList.AddStatement(assignmentNodeF1);
            func1StmtList.AddStatement(assignmentNodeF2);
            func1StmtList.AddStatement(func1ReturnStatement);

            func1Decl.Statements = func1StmtList;
            return func1Decl;
        }