public object VisitFormParsAST([NotNull] FormParsASTContext context) { WhiteLine(); string instruction = "PUSH_"; if (context.Parent is ProgramASTContext) { instruction += "GLOBAL"; } else { instruction += "LOCAL"; } for (int i = 0; i < context.type().Length; i++) { string type = Visit(context.type(i)) as string; AddLine($"{instruction}_{type} {context.ident(i).GetText()}"); } WhiteLine(); return(null); }
public object VisitFormParsAST([NotNull] FormParsASTContext context) { var typesList = new List <TypeASTContext>(context.type().ToList().Cast <TypeASTContext>()); var idents = new List <IdentASTContext>(context.ident().ToList().Cast <IdentASTContext>()); for (int i = 0; i < typesList.Count; i++) { var type = Visit(typesList[i]) as string; if (type != null) { if (idents[i].IDENT() != null) { if (!ExistIdent(idents[i].IDENT().Symbol.Text, true)) { if (types.IndexOf(type) > 10) { ClassIdentifier classIdentifier = identificationTable.FindClass(type); List <Identifier> instanceIdentifiers = GetIdentifiersFromClass(classIdentifier); InstanceIdentifier instanceIdentifier = new InstanceIdentifier(idents[i].IDENT().Symbol.Text, idents[i].IDENT().Symbol, identificationTable.getLevel(), type, context, classIdentifier, instanceIdentifiers); identificationTable.Insert(instanceIdentifier); } else { var ident = idents[i].IDENT(); Identifier identifier = new VarIdentifier(ident.Symbol.Text, ident.Symbol, identificationTable.getLevel(), type, context); if (typesList[i].SQUAREBL() != null && typesList[i].SQUAREBR() != null) { if (types.IndexOf(type) <= 10) { List <Identifier> identifiers = new List <Identifier>(); identifier.Id = "0"; identifiers.Add(identifier); identifier.Type = type.Replace("[]", ""); ArrayIdentifier arrayIdentifier = new ArrayIdentifier(ident.Symbol.Text, ident.Symbol, identificationTable.getLevel(), type, context, 1, identifiers); identificationTable.Insert(arrayIdentifier); } } else { identificationTable.Insert(identifier); } } } else { InsertError(idents[i].IDENT().Symbol, "El identificador " + idents[i].IDENT().Symbol.Text + " ya fue declarado en los parámetros"); } } } } return(context); }
public object VisitActParsAST([NotNull] ActParsASTContext context) { var callFactor = context.Parent is IdentOrCallFactorASTContext ? (IdentOrCallFactorASTContext)context.Parent : null; var callStatement = context.Parent is CallStatementASTContext ? (CallStatementASTContext)context.Parent : null; MethodIdentifier methodIdentifier = null; if (callFactor != null) { methodIdentifier = (MethodIdentifier)Visit(callFactor.designator()); } else if (callStatement != null) { methodIdentifier = (MethodIdentifier)Visit(callStatement.designator()); } if (methodIdentifier == null) { return(null); } FormParsASTContext originalPars = methodIdentifier.FormPars; if (originalPars == null) { if (methodIdentifier.DefaultMethod) { if (methodIdentifier.DefaulMethodParams == null) { InsertError(context.Start, "El método '" + methodIdentifier.Id + "' no recibe parámetros, y se recibieron " + context.expr().Length); } else if (context.expr().Length != methodIdentifier.DefaulMethodParams.Count) { InsertError(context.Start, "El método '" + methodIdentifier.Id + "' recibe " + methodIdentifier.DefaulMethodParams.Count + " parámetros, y se recibieron " + context.expr().Length); } else { for (int i = 0; i < methodIdentifier.DefaulMethodParams.Count; i++) { string exprType = (string)Visit(context.expr()[i]); if (exprType == null) { return(null); } else if (exprType != "none" && ((methodIdentifier.DefaulMethodParams[i] == "array" && !exprType.Contains("[]")) && exprType != methodIdentifier.DefaulMethodParams[i])) { InsertError(context.expr()[i].Start, $"El tipo de la expresión '{ context.expr()[i].GetText()}' es '" + exprType + "', y se esperaba el tipo '" + methodIdentifier.DefaulMethodParams[i] + "'"); } } } } else { InsertError(context.Start, "El método '" + methodIdentifier.Id + "' no recibe parámetros, y se recibieron " + context.expr().Length); } } else if (context.expr().Length != originalPars.ident().Length) { InsertError(context.Start, "El método '" + methodIdentifier.Id + "' recibe " + originalPars.ident().Length + " parámetros, y se recibieron " + context.expr().Length); } else { for (int i = 0; i < originalPars.ident().Length; i++) { string exprType = (string)Visit(context.expr()[i]); if (exprType == null) { return(null); } else if (exprType != "none" && exprType != originalPars.type()[i].GetText()) { InsertError(context.expr()[i].Start, $"El tipo de la expresión '{ context.expr()[i].GetText()}' es '" + exprType + "', y se esperaba el tipo '" + originalPars.type()[i].GetText() + "'"); } } } return(null); }