예제 #1
0
        public Node ElseIfList()
        {
            var elseIfList = new ListElseIf();

            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var elseIfToken = new ElseIf()
                {
                    AnchorToken = Expect(TokenCategory.ELSEIF)
                };
                Expect(TokenCategory.PARENTHESIS_OPEN);
                elseIfToken.Add(Expression());
                Expect(TokenCategory.PARENTHESIS_CLOSE);
                var n1 = new ListStatements();
                Expect(TokenCategory.BRACE_OPEN);
                while (firstOfStatement.Contains(CurrentToken))
                {
                    n1.Add(Statement());
                }
                elseIfToken.Add(n1);
                Expect(TokenCategory.BRACE_CLOSE);
                elseIfList.Add(elseIfToken);
            }
            return(elseIfList);
        }
예제 #2
0
        public Node If()
        {
            var n1 = new If();

            n1.AnchorToken = Expect(TokenType.IF);
            Expect(TokenType.PARENTHESIS_OPEN);
            n1.Add(Expression());
            Expect(TokenType.PARENTHESIS_CLOSE);
            Expect(TokenType.BLOCK_BEGIN);
            var n2 = new StatementList();

            while (firstOfStatement.Contains(CurrentToken))
            {
                n2.Add(Statement());
            }
            n1.Add(n2);
            var n3 = new ElseIfList();

            Expect(TokenType.BLOCK_END);
            while (CurrentToken == TokenType.ELSEIF)
            {
                var nelsif = new ElseIf();
                nelsif.AnchorToken = Expect(TokenType.ELSEIF);
                Expect(TokenType.PARENTHESIS_OPEN);
                nelsif.Add(Expression());
                Expect(TokenType.PARENTHESIS_CLOSE);
                Expect(TokenType.BLOCK_BEGIN);
                var stmtList = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtList.Add(Statement());
                }
                nelsif.Add(stmtList);
                n3.Add(nelsif);
                Expect(TokenType.BLOCK_END);
            }
            n1.Add(n3);
            var els = new Else();

            if (CurrentToken == TokenType.ELSE)
            {
                els.AnchorToken = Expect(TokenType.ELSE);
                Expect(TokenType.BLOCK_BEGIN);
                var stmtList = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtList.Add(Statement());
                }
                els.Add(stmtList);
                Expect(TokenType.BLOCK_END);
            }
            n1.Add(els);
            return(n1);
        }
예제 #3
0
        public Node If()
        {
            var result = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            result.Add(Expression());
            var thenstatement = new Then()
            {
                AnchorToken = Expect(TokenCategory.THEN)
            };

            while (firstOfStatement.Contains(CurrentToken))
            {
                thenstatement.Add(Statement());
            }
            result.Add(thenstatement);
            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var elif = new ElseIf()
                {
                    AnchorToken = Expect(TokenCategory.ELSEIF)
                };
                elif.Add(Expression());
                var thenst = new Then()
                {
                    AnchorToken = Expect(TokenCategory.THEN)
                };
                while (firstOfStatement.Contains(CurrentToken))
                {
                    thenst.Add(Statement());
                }
                elif.Add(thenst);
                result.Add(elif);
            }
            if (CurrentToken == TokenCategory.ELSE)
            {
                var elsestatement = new Else()
                {
                    AnchorToken = Expect(TokenCategory.ELSE)
                };
                while (firstOfStatement.Contains(CurrentToken))
                {
                    elsestatement.Add(Statement());
                }
            }
            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOL);
            return(result);
        }
예제 #4
0
        public Node ElseIf()
        {
            var node = new ElseIfList();

            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var node_elseif = new ElseIf();
                Expect(TokenCategory.ELSEIF);
                Expect(TokenCategory.OPENEDPAR);
                node_elseif.Add(Expr());
                Expect(TokenCategory.CLOSEDPAR);
                Expect(TokenCategory.OPENEDCURLY);
                node_elseif.Add(StmtList());
                Expect(TokenCategory.CLOSEDCURLY);
                node.Add(node_elseif);
            }
            return(node);
        }
예제 #5
0
        public Node ElseIf(Token elseToken)
        {
            var statementElseIf = new ElseIf()
            {
                AnchorToken = elseToken
            };

            Expect(TokenCategory.IF);

            Expect(TokenCategory.PARENTHESIS_OPEN);
            statementElseIf.Add(Expr());
            Expect(TokenCategory.PARENTHESIS_CLOSE);

            Expect(TokenCategory.BRACKETS_OPEN);
            statementElseIf.Add(StmtList());
            Expect(TokenCategory.BRACKETS_CLOSE);

            return(statementElseIf);
        }
예제 #6
0
        public Node ElseIf()
        {
            //elseif(‹expr›){‹stmt-list›} *
            var n = new ElseIfList();

            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var n1 = new ElseIf();
                Expect(TokenCategory.ELSEIF);
                Expect(TokenCategory.OPENEDPAR);
                n1.Add(Expr());
                Expect(TokenCategory.CLOSEDPAR);
                Expect(TokenCategory.OPENEDCURLY);
                n1.Add(StmtList());
                Expect(TokenCategory.CLOSEDCURLY);
                n.Add(n1);
            }
            return(n);
        }
        public Node ElseIfList()
        {
            var elseIfList = new ElseIfList();

            while (Current == TokenCategory.ELSEIF)
            {
                var elseIf = new ElseIf()
                {
                    AnchorToken = Expect(TokenCategory.ELSEIF)
                };
                Expect(TokenCategory.OPEN_PARENTHESIS);
                elseIf.Add(Expr());
                Expect(TokenCategory.CLOSE_PARENTHESIS);
                Expect(TokenCategory.OPEN_BRACKET);
                elseIf.Add(StmtList());
                Expect(TokenCategory.CLOSE_BRACKET);
                elseIfList.Add(elseIf);
            }
            return(elseIfList);
        }
예제 #8
0
        //elseif side function//
        public Node elseif()
        {
            var result = new ElseIf()
            {
                AnchorToken = Expect(TokenCategory.ELSEIF)
            };

            Expect(TokenCategory.PARENTHESIS_OPEN);

            result.Add(Expression());

            Expect(TokenCategory.PARENTHESIS_CLOSE);

            Expect(TokenCategory.CURLY_BRACKET_OPEN);

            result.Add(StmtList());

            Expect(TokenCategory.CURLY_BRACKET_CLOSE);

            return(result);
        }
예제 #9
0
        public Node ElseIfList()
        {
            var result = new ElseIfList();

            while (CurrentToken == TokenCategory.ELIF)
            {
                var elifNode = new ElseIf();
                var elif     = Expect(TokenCategory.ELIF);
                Expect(TokenCategory.PARENTHESIS_OPEN);
                var expr = Expression();
                elifNode.Add(expr);
                Expect(TokenCategory.PARENTHESIS_CLOSE);
                Expect(TokenCategory.BRACKET_OPEN);
                var stmtList = StmtList();
                elifNode.Add(stmtList);
                Expect(TokenCategory.BRACKET_CLOSE);

                elifNode.AnchorToken = elif;
                result.Add(elifNode);
            }
            return(result);
        }
예제 #10
0
파일: Parser.cs 프로젝트: BetoVas97/chimera
        public Node If()
        {
            var result = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            result.Add(Expression());
            Expect(TokenCategory.THEN);
            if (firstOfStatement.Contains(CurrentToken))
            {
                var statementList = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    statementList.Add(Statement());
                }
                result.Add(statementList);
            }

            var elseIfList = new ElseIfList();

            if (CurrentToken == TokenCategory.ELSEIF)
            {
                while (CurrentToken == TokenCategory.ELSEIF)
                {
                    var elseIf = new ElseIf()
                    {
                        AnchorToken = Expect(TokenCategory.ELSEIF)
                    };

                    elseIf.Add(Expression());
                    Expect(TokenCategory.THEN);
                    if (firstOfStatement.Contains(CurrentToken))
                    {
                        var statementList = new StatementList();
                        while (firstOfStatement.Contains(CurrentToken))
                        {
                            statementList.Add(Statement());
                        }
                        elseIf.Add(statementList);
                    }
                    elseIfList.Add(elseIf);
                }
            }
            result.Add(elseIfList);

            var els = new Else();

            if (CurrentToken == TokenCategory.ELSE)
            {
                els.AnchorToken = Expect(TokenCategory.ELSE);
                if (firstOfStatement.Contains(CurrentToken))
                {
                    var statementList = new StatementList();
                    while (firstOfStatement.Contains(CurrentToken))
                    {
                        statementList.Add(Statement());
                    }
                    els.Add(statementList);
                }
            }
            result.Add(els);

            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOLON);
            return(result);
        }
예제 #11
0
        public Node If()
        {
            var ifToken = Expect(TokenCategory.IF);
            var nodeIf  = new If()
            {
                AnchorToken = ifToken
            };

            nodeIf.Add(Expression());
            Expect(TokenCategory.THEN);
            var stmtList = new StatementList();

            while (firstOfStatement.Contains(CurrentToken))
            {
                stmtList.Add(Statement());
            }

            nodeIf.Add(stmtList);

            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var nodeElseIf = new ElseIf()
                {
                    AnchorToken = Expect(TokenCategory.ELSEIF)
                };

                nodeElseIf.Add(Expression());
                Expect(TokenCategory.THEN);

                var stmtListElseIf = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtListElseIf.Add(Statement());
                }

                nodeElseIf.Add(stmtListElseIf);
                nodeIf.Add(nodeElseIf);
            }

            while (CurrentToken == TokenCategory.ELSE)
            {
                var nodeElse = new Else()
                {
                    AnchorToken = Expect(TokenCategory.ELSE)
                };

                var stmtListElse = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtListElse.Add(Statement());
                }

                nodeElse.Add(stmtListElse);
                nodeIf.Add(nodeElse);
            }

            Expect(TokenCategory.END);
            Expect(TokenCategory.ENDLINE);

            return(nodeIf);


            // var ifToken = Expect(TokenCategory.IF);
            // var exprList = new ExpressionList();
            // exprList.Add(Expression());
            // var thenNode = new Then() {
            //     AnchorToken = Expect(TokenCategory.THEN)
            // };
            // var stmtList = new StatementList();
            // while (firstOfStatement.Contains(CurrentToken)) {
            //     stmtList.Add(Statement());
            // }
            // if(CurrentToken == TokenCategory.ELSEIF) {
            //     while (CurrentToken == TokenCategory.ELSEIF) {
            //         var elseIf = new ElseIf() {
            //             AnchorToken = Expect(TokenCategory.ELSEIF)
            //         };
            //         exprList.Add(Expression());
            //         Console.WriteLine("Revisa then");
            //         var thenNodetwo = new Then() {
            //             AnchorToken = Expect(TokenCategory.THEN)
            //         };
            //         while (firstOfStatement.Contains(CurrentToken)) {
            //             stmtList.Add(Statement());
            //         }
            //     }
            // }
            // if(CurrentToken == TokenCategory.ELSE) {
            //     Expect(TokenCategory.ELSE);
            //     while (firstOfStatement.Contains(CurrentToken)) {
            //         stmtList.Add(Statement());

            //     }
            // }
            // Expect(TokenCategory.END);
            // Expect(TokenCategory.ENDLINE);
            // var result = new If() { exprList, stmtList };
            // result.AnchorToken = ifToken;
            // return result;
        }