public void Visit(FunctionCall node) { var functionName = node.AnchorToken.Lexeme; if (!Functions.Contains(functionName)) { throw new SemanticError( "Unknown Function: " + functionName, node.AnchorToken); } int argsCount = 0; if (node.Lenght() > 0) { argsCount = node[0].Lenght(); } var realArgsCount = Functions[functionName].Item2; if (argsCount != realArgsCount) { throw new SemanticError( "Wrong number of arguments calling function: " + functionName, node.AnchorToken); } VisitChildren(node); }
//check public string Visit(FunctionCall node) { switch (node.AnchorToken.Lexeme) { case "printi": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Printi'(int32)") + putS(Indentar() + "pop")); case "printc": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Printc'(int32)") + putS(Indentar() + "pop")); case "prints": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Prints'(int32)") + putS(Indentar() + "pop")); case "println": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Println'()") + putS(Indentar() + "pop")); case "readi": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Readi'()")); case "reads": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Reads'()")); case "new": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'New'(int32)")); case "size": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Size'(int32)")); case "add": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Add'(int32,int32)") + putS(Indentar() + "pop")); case "get": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Get'(int32,int32)")); case "set": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Set'(int32,int32,int32)") + putS(Indentar() + "pop")); case "pow": return(VisitChildren(node) + putS(Indentar() + "call int32 class ['deeplingolib']'DeepLingo'.'Utils'::'Pow'(int32,int32)")); } //default -> es una funcion definida por el usuario var assi = ""; if (false) { assi = putS(Indentar() + "pop"); } isAssigment = false; var temp = ""; var temp2 = ""; var result = ""; var t = ""; //si la funcion tiene argumentos if (node.Lenght() > 0) { foreach (var n in node[0]) { temp2 += "int32,"; result += Visit((dynamic)n); } temp += result + putS(Indentar() + "call int32 class 'DeepLingoProgram'::'" + node.AnchorToken.Lexeme + "'(" + temp2.Substring(0, temp2.Length - 1) + ")") + assi; return(temp); } t = result + putS(Indentar() + "call int32 class 'DeepLingoProgram'::'" + node.AnchorToken.Lexeme + "'()") + assi; return(t); }