//jsjdnfJDDDDDDDDDDDDDDDDDDDDDDDDWIOFEWFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF public Node else_if_list() { //Console.WriteLine("else_if_list"); var Else_ = new Else_(); while (CurrentToken == TokenCategory.ELSE) { var r = Expect(TokenCategory.ELSE); Else_.AnchorToken = r; if (CurrentToken == TokenCategory.IF) { var If = new If_(); var m = Expect(TokenCategory.IF); If.AnchorToken = m; Else_.Add(If); Expect(TokenCategory.OPENP); If.Add(expr()); Expect(TokenCategory.CLOSEP); Expect(TokenCategory.OPENB); If.Add(stmt_list()); //Console.WriteLine("CLOSEB7"); Expect(TokenCategory.CLOSEB); } else if (CurrentToken == TokenCategory.OPENB) { //Console.WriteLine("else_"); if (CurrentToken == TokenCategory.OPENB) { Expect(TokenCategory.OPENB); Else_.Add(stmt_list()); //Console.WriteLine("CLOSEB9"); Expect(TokenCategory.CLOSEB); } } } return(Else_); }
public string Visit(If_ node, int modo) { Console.WriteLine("Entra IF"); var i = 2; var text = ""; var ExtraLabels = new List <string>(); var condition = Visit((dynamic)node[0], 3); var thenPart = Visit((dynamic)node[1], 3); Console.WriteLine("TIENE COND Y THENPART"); try{ if (node[2].AnchorToken.lexeme != null && node[2].AnchorToken.lexeme == "else") { Console.WriteLine(node[2].AnchorToken.lexeme); foreach (Node nodo in node[2]) { var label = GenerateLabel(); ExtraLabels.Add(label); i++; } } } catch (Exception ex) { if (ex is System.NullReferenceException || ex is System.ArgumentOutOfRangeException) { } else { throw; } } Console.WriteLine("NODOS = " + i); var label1 = GenerateLabel(); lastLabelsStack.Push(label1.ToString()); for (var n = 0; n < i - 2; n++) { if (n < i - 3) { Console.WriteLine("HIJO IF"); var cond = Visit((dynamic)node[2][n][0], 3); var thenPartt = Visit((dynamic)node[2][n][1], 3); Console.WriteLine("HIJO END"); text += String.Format("\t '{0}':\n{1}\t\tbrfalse '{2}'\n{3}\t\tbr'{4}'\n", ExtraLabels[n], cond, ExtraLabels[n + 1], thenPartt, label1); } else { Console.WriteLine("HIJO ELSE"); var thenParttt = Visit((dynamic)node[2][n], 3); text += String.Format("\t '{0}':\n {1}", ExtraLabels[n], thenParttt); } } if (i == 2) { Console.WriteLine("SOLO HABIA UN IF"); return(String.Format( "{1}\t\tbrfalse '{0}'\n" + "{2}" + "\t\tbr'{0}'\n", label1, condition, thenPart )); } else { Console.WriteLine("ENCONTRO MUCHOS ELSE IF"); return(String.Format( "{1}\t\tbrfalse '{0}'\n" + "{2}" + "\t\tbr'{3}'\n" + ExtraLabels[0], condition, thenPart, label1) + text + "\t'" + label1 + "':\n"); } return(""); }
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(If_ node, int modo) { VisitChildren(node, modo); }