Beispiel #1
0
 public string Visit(AST_FormalDec node)
 {
     foreach (var item in node.Children)
     {
         item?.Visit(this);
     }
     return("");
 }
 public bool Visit(AST_FormalDec node)
 {
     if (CurrContext.IsDefineInMe(node.id.Id))
     {
         CurrErrorLoger.LogError(node.row, node.col, "Variable " + node.id.Id + " previamente definida");
         return(false);
     }
     CurrContext.Define(node.id.Id);
     return(true);
 }
Beispiel #3
0
        public override AST_Node VisitCaseof([NotNull] CoolParser.CaseofContext context)
        {
            var exp = (AST_Expresion)Visit(context.expr());
            List <AST_ClassProperty> props = new List <AST_ClassProperty>();

            foreach (var item in context.branch())
            {
                var s = new AST_FormalDec(item.formal(), new AST_Id(item.formal().ID(), item.formal().ID().GetText()),
                                          new AST_Type_Node(item.formal().TYPE(), item.formal().TYPE().GetText()));
                AST_ClassProperty x = new AST_ClassProperty(item, s, (AST_Expresion)Visit(item.expr()));
                props.Add(x);
            }

            return(new AST_CaseOf(context, new AST_ListProp(context, props), exp));
        }
Beispiel #4
0
        public override AST_Node VisitFeatureprop([NotNull] CoolParser.FeaturepropContext context)
        {
            var           v      = context.property();
            var           formal = v.formal();
            AST_Id        id     = new AST_Id(formal.ID(), formal.ID().GetText());
            AST_Type_Node type   = new AST_Type_Node(formal.TYPE(), formal.TYPE().GetText());
            AST_Expresion exp    = null;

            if (v.expr() != null)
            {
                exp = (AST_Expresion)Visit(v.expr());
            }
            var formald = new AST_FormalDec(v.formal(), id, type);

            return(new AST_ClassProperty(context, formald, exp));
        }
Beispiel #5
0
        public override AST_Node VisitMethod([NotNull] CoolParser.MethodContext context)
        {
            AST_Id                   id     = new AST_Id(context.ID(), context.ID().GetText());
            AST_Type_Node            type   = new AST_Type_Node(context.TYPE(), context.TYPE().GetText());
            List <AST_ClassProperty> param  = new List <AST_ClassProperty>();
            AST_Expresion            corpus = (AST_Expresion)Visit(context.expr());

            foreach (var item in context.formal())
            {
                var iid             = new AST_Id(item.ID(), item.ID().GetText());
                var ity             = new AST_Type_Node(item.TYPE(), item.TYPE().GetText());
                var formald         = new AST_FormalDec(item, iid, ity);
                AST_ClassProperty i = new AST_ClassProperty(item, formald, null);
                param.Add(i);
            }
            return(new AST_MethodDef(context, id, type, new AST_ListProp(context, param), corpus));
        }
Beispiel #6
0
 public bool Visit(AST_FormalDec node)
 {
     if (ReservedWords.Contains(node.id.Id))
     {
         CurrErrorLoger.LogError(node.id.row, node.id.col, "El id de la variable es una palabra reservada");
         return(false);
     }
     if (Types.Contains(node.id.Id))
     {
         CurrErrorLoger.LogError(node.id.row, node.id.col, "El id de la variable es un tipo definido");
         return(false);
     }
     if (!Types.Contains(node.type.Type))
     {
         CurrErrorLoger.LogError(node.id.row, node.id.col, "El tipo de la variable no esta definido");
         return(false);
     }
     return(true);
 }
Beispiel #7
0
        public override AST_Node VisitLet([NotNull] CoolParser.LetContext context)
        {
            List <AST_ClassProperty> param  = new List <AST_ClassProperty>();
            AST_Expresion            corpus = (AST_Expresion)Visit(context.expr());

            foreach (var item in context.property())
            {
                var           iid     = new AST_Id(item.formal().ID(), item.formal().ID().GetText());
                var           ity     = new AST_Type_Node(item.formal().TYPE(), item.formal().TYPE().GetText());
                var           formald = new AST_FormalDec(item, iid, ity);
                AST_Expresion subexp  = null;
                if (item.expr() != null)
                {
                    subexp = (AST_Expresion)Visit(item.expr());
                }
                AST_ClassProperty i = new AST_ClassProperty(item, formald, subexp);
                param.Add(i);
            }
            return(new AST_Let(context, new AST_ListProp(context, param), corpus));
        }
Beispiel #8
0
        public bool Visit(AST_FormalDec node)
        {
            bool solve = true;

            if (CurrContext.GetTypeInMe(node.id.Id) != null)
            {
                CurrErrorLoger.LogError(node.row, node.col, "La variable ya es otro tipo");
                return(false);
            }
            //if (node.type.Type == "int")
            //    node.type.Type = "Int";
            //if (node.type.Type == "string")
            //    node.type.Type = "String";
            //if (node.type.Type == "bool")
            //    node.type.Type = "Bool";
            if (!All_Types.ContainsKey(node.type.Type))
            {
                CurrErrorLoger.LogError(node.row, node.col, "El tipo de la variable no existe");
                return(false);
            }
            CurrContext.SetType(node.id.Id, All_Types[node.type.Type]);
            return(true);
        }
Beispiel #9
0
 public bool Visit(AST_FormalDec node)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 public Base_Object_Value Visit(AST_FormalDec node)
 {
     throw new NotImplementedException();
 }