public string Visit(Do_ node, int modo) { Console.WriteLine("aqui12"); //var label1 = GenerateLabel(); var body = Visit((dynamic)node[0], 3); var condition = Visit((dynamic)node[1][0]); var label1 = lastLabelsStack.Peek(); var label2 = GenerateLabel(); firstLabelsLoopStack.Push(label2); // lastLabelStack.Push(label2); //dice que last label stack no existe return(String.Format( "\t'{0}:'\n{1}{2}" + "\t\tbrtrue'{0}'\n" + "\t\t'{3}':\n", label1, body, condition, label2 )); }
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); } }
public void Visit(Do_ node, int modo) { number_of_loops = number_of_loops + 1; VisitChildren(node, modo); number_of_loops = number_of_loops - 1; }