コード例 #1
0
ファイル: Form1.cs プロジェクト: vorsters/MyLanguage
        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;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: vorsters/MyLanguage
        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;
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: vorsters/MyLanguage
        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;
        }