public List <Identifier> GetIdentifiersFromClass(ClassIdentifier classIdentifier) { List <Identifier> identifiers = new List <Identifier>(); classIdentifier.VarDecl.ForEach(context => { string type = (string)Visit(context.type()); if (type != null) { context.ident().ToList().ForEach((IdentContext identC) => { if (identC.GetText() == "") { return; } ITerminalNode ident = ((IdentASTContext)identC).IDENT(); if (types.IndexOf(type) > 10) { ClassIdentifier classIdentifier1 = identificationTable.FindClass(type); List <Identifier> instanceIdentifiers = GetIdentifiersFromClass(classIdentifier1); InstanceIdentifier instanceIdentifier = new InstanceIdentifier(ident.Symbol.Text, ident.Symbol, identificationTable.getLevel(), type, context, classIdentifier, instanceIdentifiers); identifiers.Add(instanceIdentifier); } else { Identifier identifier = new VarIdentifier(ident.Symbol.Text, ident.Symbol, identificationTable.getLevel(), type, context); identifiers.Add(identifier); } }); } }); return(identifiers); }
public object VisitVarDeclAST([NotNull] VarDeclASTContext context) { string type = (string)Visit(context.type()); if (type != null) { context.ident().ToList().ForEach((IdentContext identC) => { if (identC.GetText() == "") { return; } ITerminalNode ident = ((IdentASTContext)identC).IDENT(); if (ident != null && !ExistIdent(ident.Symbol.Text, true)) { if (types.IndexOf(type) > 10) { if ((context.type() as TypeASTContext).SQUAREBL() == null) { ClassIdentifier classIdentifier = identificationTable.FindClass(type); List <Identifier> instanceIdentifiers = GetIdentifiersFromClass(classIdentifier); InstanceIdentifier instanceIdentifier = new InstanceIdentifier(ident.Symbol.Text, ident.Symbol, identificationTable.getLevel(), type, context, classIdentifier, instanceIdentifiers); identificationTable.Insert(instanceIdentifier); } } else { Identifier identifier = new VarIdentifier(ident.Symbol.Text, ident.Symbol, identificationTable.getLevel(), type, context); if ((context.type() as TypeASTContext).SQUAREBL() != null && (context.type() as TypeASTContext).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(ident.Symbol, "El identificador " + ident.Symbol.Text + " ya fue declarado en este scope"); } }); } 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); }