Exemplo n.º 1
0
        public string Visit(Let_In node)
        {
            List <string> attrs = new List <string>();

            foreach (var attr in node.attrs.list_Node)
            {
                var a = "";
                if (attr.exp == null)
                {
                    if (attr.type.s == "Int")
                    {
                        a = new Const("0").Visit(this);
                    }
                    else if (attr.type.s == "String")
                    {
                        a = method.Add_local("expr", true);
                        method.Add_Instruction(new CIL_Load(a, Data[""]));
                    }
                    else if (attr.type.s == "Bool")
                    {
                        a = new Const("false").Visit(this);
                    }
                    else
                    {
                        a = "void";
                    }
                }
                else
                {
                    a = attr.exp.Visit(this);
                }
                attrs.Add(a);
            }

            method.Add_scope("let");

            for (int i = 0; i < attrs.Count; i++)
            {
                string name = method.Add_local(node.attrs.list_Node[i].name.name);
                if (attrs[i] != null)
                {
                    method.Add_Instruction(new CIL_Assig(name, attrs[i]));
                }
            }
            var exp = node.exp.Visit(this);
            var ret = method.Add_local("expr", true);

            method.Add_Instruction(new CIL_Assig(ret, exp));
            method.End_scope();
            return(ret);
        }
Exemplo n.º 2
0
        public string Visit(Let_In node)
        {
            List <string> attrs = new List <string>();

            foreach (var attr in node.attrs.list_Node)
            {
                if (attr.exp != null)
                {
                    attrs.Add(Visit(attr.exp));
                }
                else
                {
                    attrs.Add(null);
                }
            }

            method.Add_scope("let");

            for (int i = 0; i < attrs.Count; i++)
            {
                string name = method.Add_local(node.attrs.list_Node[i].name.name);
                if (attrs[i] != null)
                {
                    method.Add_Instruction(new CIL_Assig(name, attrs[i]));
                }
            }

            var exp = Visit(node.exp);
            var ret = method.Add_local("expr", true);

            method.Add_Instruction(new CIL_Assig(ret, exp));
            method.End_scope();
            return(ret);
        }