コード例 #1
0
        public static ILanguageExpression Translate(GMacExpressionBasicGenerator langExprGen, ParseTreeNode node)
        {
            var context = langExprGen.Context;

            context.PushState(node);

            var translator = new GMacExpressionAtomicGenerator();// new GMacExpressionAtomicGenerator(langExprGen);

            translator.SetContext(langExprGen);
            translator.Translate();

            context.PopState();

            var result = translator._generatedExpression;

            //MasterPool.Release(translator);

            return(result);
        }
コード例 #2
0
        private ILanguageExpression translate_Expression_Product(ParseTreeNode node)
        {
            var subNode = node.ChildNodes[0];

            if (subNode.ToString() == GMacParseNodeNames.ExpressionAtomic)
            {
                //A 'Expression_Atomic' node
                return(GMacExpressionAtomicGenerator.Translate(BasicExpressionGenerator, subNode));
            }


            //A 'Expression_Product + GA_Binary_Product + Expression_Atomic' node
            var gaBinaryProductNode = node.ChildNodes[1];
            var biOp = gaBinaryProductNode.ChildNodes[0].Term.ToString();

            var expr1 = translate_Expression_Product(node.ChildNodes[0]);
            var expr2 = GMacExpressionAtomicGenerator.Translate(BasicExpressionGenerator, node.ChildNodes[2]);

            Context.PushState(node);

            ILanguageExpression finalExpr;

            switch (biOp)
            {
            case "/":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryDivideByScalar(expr1, expr2);
                break;

            case "*":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryTimesWithScalar(expr1, expr2);
                break;

            case "^":
            case "op":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryOp, expr1, expr2);
                break;

            case "sp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryScalarProduct(GMacOpInfo.BinarySp, expr1, expr2);
                break;

            case "gp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryProduct(GMacOpInfo.BinaryGp, expr1, expr2);
                break;

            case "lcp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryProduct(GMacOpInfo.BinaryLcp, expr1, expr2);
                break;

            case "rcp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryProduct(GMacOpInfo.BinaryRcp, expr1, expr2);
                break;

            case "fdp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryProduct(GMacOpInfo.BinaryFdp, expr1, expr2);
                break;

            case "hip":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryProduct(GMacOpInfo.BinaryHip, expr1, expr2);
                break;

            case "cp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryProduct(GMacOpInfo.BinaryCp, expr1, expr2);
                break;

            case "acp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryProduct(GMacOpInfo.BinaryAcp, expr1, expr2);
                break;

            case "esp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanScalarProduct(GMacOpInfo.BinaryESp, expr1, expr2);
                break;

            case "egp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryEGp, expr1, expr2);
                break;

            case "elcp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryELcp, expr1, expr2);
                break;

            case "ercp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryERcp, expr1, expr2);
                break;

            case "efdp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryEFdp, expr1, expr2);
                break;

            case "ehip":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryEHip, expr1, expr2);
                break;

            case "ecp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryECp, expr1, expr2);
                break;

            case "eacp":
                finalExpr =
                    BasicExpressionGenerator
                    .Generate_BinaryEuclideanProduct(GMacOpInfo.BinaryEAcp, expr1, expr2);
                break;

            default:
                return(CompilationLog.RaiseGeneratorError <ILanguageExpression>("Binary product not recognized", gaBinaryProductNode.ChildNodes[0]));
            }

            Context.PopState();

            return(finalExpr);
        }