Example #1
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            switch (op)
            {
            case "<":
                var less = new Lt((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(less);
                return(less);

            case "<=":
                var lesseq = new Leq((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(lesseq);
                return(lesseq);

            case "=":
                var eq = new Eq((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(eq);
                return(eq);

            case ">":
                var greater = new Lt((MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), Line);
                SetGeneratorType(greater);
                return(greater);

            case ">=":
                var greaterEq = new Leq((MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), Line);
                SetGeneratorType(greaterEq);
                return(greaterEq);

            default: throw new InvalidOperationException();
            }
        }
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            switch (op)
            {
            case "+":
                var plus = new Plus((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(plus);
                return(plus);

            case "-":
                var sub = new Sub((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(sub);
                return(sub);

            case "*":
                var mul = new Mul((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(mul);
                return(mul);

            case "/":
                var div = new Divide((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(div);
                return(div);

            default: throw new InvalidOperationException();
            }
        }