예제 #1
0
        public object VisitVarDeclAST([NotNull] VarDeclASTContext context)
        {
            string instruction = "PUSH_";

            if (context.Parent is ProgramASTContext)
            {
                instruction += "GLOBAL_";
            }
            else
            {
                instruction += "LOCAL_";
            }

            string type = Visit(context.type()) as string;

            instruction += type;

            context.ident().ToList().ForEach(ident =>
            {
                AddLine($"{instruction} {ident.GetText()}");
            });

            WhiteLine();
            return(null);
        }
예제 #2
0
        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);
        }