public Node fun_def() { //Console.WriteLine("fun_def"); var fun = new Fun_(); var r = Expect(TokenCategory.IDENTIFIER); fun.AnchorToken = r; Expect(TokenCategory.OPENP); if (CurrentToken != TokenCategory.CLOSEP) { fun.Add(param_list()); } Expect(TokenCategory.CLOSEP); Expect(TokenCategory.OPENB); if (CurrentToken == TokenCategory.VAR) { //Console.WriteLine("fun_def2"); fun.Add(var_def_list()); } //Console.WriteLine("aqui estoy"); fun.Add(stmt_list()); //Console.WriteLine("fun_def3"); Expect(TokenCategory.CLOSEB); //Console.WriteLine("fun_def4"); return(fun); }
public Node stmt_() { //Console.WriteLine("stmt"); Token r; switch (CurrentToken) { case TokenCategory.IF: //Console.WriteLine("stmt1"); Node If = new If_(); r = Expect(TokenCategory.IF); If.AnchorToken = r; Expect(TokenCategory.OPENP); If.Add(expr()); Expect(TokenCategory.CLOSEP); Expect(TokenCategory.OPENB); If.Add(stmt_list()); //Console.WriteLine("CLOSEB3"); Expect(TokenCategory.CLOSEB); If.Add(else_if_list()); If.Add(else_()); return(If); case TokenCategory.SWITCH: //Console.WriteLine("stmt2"); var Switch = new Switch_(); r = Expect(TokenCategory.SWITCH); Switch.AnchorToken = r; Expect(TokenCategory.OPENP); Switch.Add(expr()); Expect(TokenCategory.CLOSEP); Expect(TokenCategory.OPENB); Switch.Add(case_list()); Switch.Add(default_()); //Console.WriteLine("CLOSEB4"); Expect(TokenCategory.CLOSEB); return(Switch); case TokenCategory.WHILE: //Console.WriteLine("stmt3"); var While = new While_(); r = Expect(TokenCategory.WHILE); While.AnchorToken = r; Expect(TokenCategory.OPENP); While.Add(expr()); Expect(TokenCategory.CLOSEP); Expect(TokenCategory.OPENB); While.Add(stmt_list()); //Console.WriteLine("CLOSEB11"); Expect(TokenCategory.CLOSEB); return(While); /* case TokenCategory.OPENP: * Expect(TokenCategory.OPENP); * expr(); * Expect(TokenCategory.CLOSEP); * break;*/ case TokenCategory.DO: //OYE AQUI NO ES DO_WHILE??? //Console.WriteLine("stmt4"); var Do = new Do_(); r = Expect(TokenCategory.DO); Do.AnchorToken = r; Expect(TokenCategory.OPENB); Do.Add(stmt_list()); //Console.WriteLine("CLOSEB5"); Expect(TokenCategory.CLOSEB); var While_ = new While_(); var m = Expect(TokenCategory.WHILE); While_.AnchorToken = m; Expect(TokenCategory.OPENP); While_.Add(expr()); Do.Add(While_); Expect(TokenCategory.CLOSEP); //Console.WriteLine("semi4"); Expect(TokenCategory.SEMICOLON); return(Do); case TokenCategory.FOR: //Console.WriteLine("stmt5"); var For = new For_(); r = Expect(TokenCategory.FOR); For.AnchorToken = r; Expect(TokenCategory.OPENP); var Id = new Id_(); var n = Expect(TokenCategory.IDENTIFIER); Id.AnchorToken = n; For.Add(Id); Expect(TokenCategory.IN); For.Add(expr()); Expect(TokenCategory.CLOSEP); Expect(TokenCategory.OPENB); For.Add(stmt_list()); //Console.WriteLine("CLOSEB6"); Expect(TokenCategory.CLOSEB); return(For); case TokenCategory.BREAK: //Console.WriteLine("stmt6"); var Break = new Break_(); r = Expect(TokenCategory.BREAK); Break.AnchorToken = r; //Console.WriteLine("semi5"); Expect(TokenCategory.SEMICOLON); return(Break); case TokenCategory.CONTINUE: //Console.WriteLine("stmt7"); var Continue = new Continue_(); r = Expect(TokenCategory.CONTINUE); Continue.AnchorToken = r; //Console.WriteLine("semi6"); Expect(TokenCategory.SEMICOLON); return(Continue); case TokenCategory.RETURN: //Console.WriteLine("stmt8"); var Return = new Return_(); r = Expect(TokenCategory.RETURN); Return.AnchorToken = r; Return.Add(expr()); //Console.WriteLine("semi7"); Expect(TokenCategory.SEMICOLON); return(Return); case TokenCategory.SEMICOLON: //Console.WriteLine("stmt9"); var empty = new Empty_(); //Console.WriteLine("semi8"); r = Expect(TokenCategory.SEMICOLON); empty.AnchorToken = r; return(empty); case TokenCategory.IDENTIFIER: //Console.WriteLine("stmt10"); r = Expect(TokenCategory.IDENTIFIER); if (CurrentToken == TokenCategory.ASIGNATION) { //Console.WriteLine("stmt11"); var id = new Id_(); id.AnchorToken = r; Expect(TokenCategory.ASIGNATION); id.Add(expr()); //Console.WriteLine("semi2"); Expect(TokenCategory.SEMICOLON); return(id); } else if (CurrentToken == TokenCategory.OPENP) { //Console.WriteLine("stmt12"); var Fun = new Fun_(); Fun.AnchorToken = r; Expect(TokenCategory.OPENP); if (CurrentToken != TokenCategory.CLOSEP) { //Console.WriteLine("stmt13");////////////MODIFICADO////////////////////////////////////////// Fun.Add(expr_list()); } //Console.WriteLine("stmt14"); Expect(TokenCategory.CLOSEP); //Console.WriteLine("semi3"); Expect(TokenCategory.SEMICOLON); return(Fun); } else { throw new SyntaxError(TokenCategory.EQUAL, tokenStream.Current); } default: throw new SyntaxError(TokenCategory.IDENTIFIER, tokenStream.Current); } }