예제 #1
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            var codeName = t.AddString(this.Name);
            var codeType = t.AddString(this.Type);

            return(new Formal(codeName, codeType, Line));
        }
예제 #2
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            var name     = t.AddString(this.Name);
            var typeDecl = t.AddString(this.Type);
            var codeExpr = (MIPSCodeGenerator.Expression)expr?.GetAstCodeGenerator(t);

            return(new MIPSCodeGenerator.Attr(name, typeDecl, codeExpr));
        }
예제 #3
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            var           name     = t.AddString(this.Name);
            var           retType  = t.AddString(ReturnType);
            List <Formal> paramss  = new List <Formal>();
            var           codebody = (MIPSCodeGenerator.Expression)Body.GetAstCodeGenerator(t);

            for (int i = 0; i < arguments.Count; i++)
            {
                paramss.Add((Formal)Arguments[i].GetAstCodeGenerator(t));
            }
            return(new MIPSCodeGenerator.Method(name, retType, paramss, codebody));
        }
예제 #4
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            var codename = t.AddString(name);
            var assing   = new Assign(codename, (MIPSCodeGenerator.Expression)Expr.GetAstCodeGenerator(t), Line);

            SetGeneratorType(assing);
            return(assing);
        }
예제 #5
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            List <MIPSCodeGenerator.Feature> f = new List <MIPSCodeGenerator.Feature>();
            var parent = t.AddString(typeInherited);

            if (typeInherited == null)
            {
                parent = "Object";
            }
            var name = t.AddString(this.Type);

            for (int i = 0; i < Attributes.Count; i++)
            {
                f.Add((MIPSCodeGenerator.Attr)Attributes[i].GetAstCodeGenerator(t));
            }
            for (int i = 0; i < Methods.Count; i++)
            {
                f.Add((MIPSCodeGenerator.Method)Methods[i].GetAstCodeGenerator(t));
            }

            return(new Class(name, parent, "", f, Line));
        }
예제 #6
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            List <MIPSCodeGenerator.Expression> codeExpr = new List <MIPSCodeGenerator.Expression>();

            for (int i = 0; i < arg.Count; i++)
            {
                codeExpr.Add((MIPSCodeGenerator.Expression)Arg[i].GetAstCodeGenerator(t));
                //Arg[i].SetGeneratorType(codeExpr[i]);
            }
            MIPSCodeGenerator.Expression obj = null;
            if (name != null && name != "")
            {
                obj      = new MIPSCodeGenerator.Object(t.AddString(name));
                obj.Type = typeName;
            }
            else if (exprDispatched != null)
            {
                obj = (MIPSCodeGenerator.Expression)exprDispatched.GetAstCodeGenerator(t);
                exprDispatched.SetGeneratorType(obj);
            }
            else
            {
                obj = new MIPSCodeGenerator.Object(t.AddString("self"), Line); obj.Type = typeName;
            }


            if (Type == null || Type == "")
            {
                MIPSCodeGenerator.Dispatch d = new MIPSCodeGenerator.Dispatch(t.AddString(methodName), obj, codeExpr, Line);
                SetGeneratorType(d);
                return(d);
            }
            else
            {
                StaticDispatch sd = new StaticDispatch(t.AddString(methodName), t.AddString(Type), obj, codeExpr, Line);
                SetGeneratorType(sd);
                return(sd);
            }
        }
예제 #7
0
 public override TreeNode GetAstCodeGenerator(SymbolTable t)
 {
     MIPSCodeGenerator.Let firstLet = null;
     for (int i = initializers.Count - 1; i >= 0; i--)
     {
         var item = initializers[i];
         if (firstLet == null)
         {
             firstLet = new MIPSCodeGenerator.Let(t.AddString(item.Name), t.AddString(item.Type), (MIPSCodeGenerator.Expression)item.Expr?.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)body.GetAstCodeGenerator(t));
             SetGeneratorType(firstLet);
         }
         else
         {
             firstLet = new MIPSCodeGenerator.Let(t.AddString(item.Name), t.AddString(item.Type), (MIPSCodeGenerator.Expression)item.Expr?.GetAstCodeGenerator(t), firstLet);
             SetGeneratorType(firstLet);
         }
     }
     //var initsCodeGen = new MIPSCodeGenerator.Block(assGen);
     //var let= new MIPSCodeGenerator.Let(t.AddString(initializers[0].Name), t.AddString(initializers[0].Type), (MIPSCodeGenerator.Expression)initializers[0].Expr.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)body.GetAstCodeGenerator(t));
     //SetGeneratorType(let);
     return(firstLet);
     //throw new NotImplementedException();
 }
예제 #8
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            List <MIPSCodeGenerator.Case> branches = new List <MIPSCodeGenerator.Case>();

            for (int i = 0; i < paramlist.Count; i++)
            {
                branches.Add(new MIPSCodeGenerator.Case(t.AddString(paramlist[i].Name), t.AddString(paramlist[i].Type), (MIPSCodeGenerator.Expression)Exprs[i].GetAstCodeGenerator(t), Exprs[i].Line));
                exprs[i].SetGeneratorType(branches[i].Expression);
            }

            Typcase c = new MIPSCodeGenerator.Typcase((MIPSCodeGenerator.Expression)expr.GetAstCodeGenerator(t), branches);

            SetGeneratorType(c);
            return(c);
        }
예제 #9
0
 public override TreeNode GetAstCodeGenerator(SymbolTable t)
 {
     MIPSCodeGenerator.New nw = new MIPSCodeGenerator.New(t.AddString(Type));
     SetGeneratorType(nw);
     return(nw);
 }
예제 #10
0
 public override TreeNode GetAstCodeGenerator(SymbolTable t)
 {
     MIPSCodeGenerator.Object obj = new MIPSCodeGenerator.Object(t.AddString(name));
     SetGeneratorType(obj);
     return(obj);
 }