コード例 #1
0
        public virtual IEnumerable <SymbolLValue> GetLValues(ILanguageExpression expr)
        {
            var t1 = expr as LanguageValueAccess;

            if (t1 != null)
            {
                return(GetLValues(t1));
            }

            var t2 = expr as BasicUnary;

            if (t2 != null)
            {
                return(GetLValues(t2));
            }

            var t3 = expr as BasicBinary;

            if (t3 != null)
            {
                return(GetLValues(t3));
            }

            var t4 = expr as BasicPolyadic;

            return
                (t4 != null
                ? GetLValues(t4)
                : Enumerable.Empty <SymbolLValue>());
        }
コード例 #2
0
        protected override void Translate()
        {
            if (Context.ActiveParentCommandBlock != null)
            {
                //If a parent command block is already present, just translate the expression and return it
                _generatedExpression = translate_Expression(RootParseNode);

                return;
            }

            //If there is no parent command block yet, create a composite expression command block
            var newCompositeExpr = CompositeExpression.Create(Context.ActiveParentScope);

            Context.PushState(newCompositeExpr.ChildCommandBlockScope);

            //Begin translation of the expression
            var finalExpr = translate_Expression(RootParseNode);

            //If there is any command in the composite expression, create and set the output local variable
            newCompositeExpr.OutputVariable = newCompositeExpr.ExpressionToLocalVariable(finalExpr);

            //Return the whole composite expression as the translated language expression
            _generatedExpression = newCompositeExpr;

            Context.PopState();
        }
コード例 #3
0
        public virtual ILanguageExpression ReplaceLValueByExpression(ILanguageExpression oldExpr, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            var t1 = oldExpr as LanguageValueAccess;

            if (t1 != null)
            {
                return(ReplaceLValueByExpression(t1, oldLvalue, newExpr));
            }

            var t2 = oldExpr as BasicUnary;

            if (t2 != null)
            {
                return(ReplaceLValueByExpression(t2, oldLvalue, newExpr));
            }

            var t3 = oldExpr as BasicBinary;

            if (t3 != null)
            {
                return(ReplaceLValueByExpression(t3, oldLvalue, newExpr));
            }

            var t4 = oldExpr as BasicPolyadic;

            return
                (t4 == null
                ? oldExpr
                : ReplaceLValueByExpression(t4, oldLvalue, newExpr));
        }
コード例 #4
0
 public CommandIfElse(LanguageScope parentScope, ILanguageExpression condExpr, ILanguageExpression trueExpr, ILanguageExpression falseExpr)
     : base(parentScope)
 {
     ConditionExpression = condExpr;
     TrueExpression      = trueExpr;
     FalseExpression     = falseExpr;
 }
コード例 #5
0
        internal static AstExpression ToAstExpression(this ILanguageExpression expr)
        {
            var s1 = expr as LanguageValueAccess;

            if (ReferenceEquals(s1, null) == false)
            {
                return(new AstDatastoreValueAccess(s1));
            }

            var s2 = expr as ValuePrimitive <MathematicaScalar>;

            if (ReferenceEquals(s2, null) == false)
            {
                return(new AstValueScalar(s2));
            }

            var s3 = expr as GMacValueMultivector;

            if (ReferenceEquals(s3, null) == false)
            {
                return(new AstValueMultivector(s3));
            }

            var s4 = expr as ValueStructureSparse;

            if (ReferenceEquals(s4, null) == false)
            {
                return(new AstValueStructure(s4));
            }

            var s5 = expr as BasicUnary;

            if (ReferenceEquals(s5, null) == false)
            {
                return(s5.ToAstExpression());
            }

            var s6 = expr as BasicBinary;

            if (ReferenceEquals(s6, null) == false)
            {
                return(new AstBinaryExpression(s6));
            }

            var s7 = expr as BasicPolyadic;

            if (ReferenceEquals(s7, null) == false)
            {
                return(s7.ToAstExpression());
            }

            var s8 = expr as CompositeExpression;

            if (ReferenceEquals(s8, null) == false)
            {
                return(new AstCompositeExpression(s8));
            }

            return(null);
        }
コード例 #6
0
        ///node is 'Expression_Function_Inputs'
        private void translate_Expression_Function_Inputs_2(ParseTreeNode node, out ILanguageExpression expr1, out ILanguageExpression expr2)
        {
            node.Assert(GMacParseNodeNames.ExpressionFunctionInputs);

            expr1 = null;
            expr2 = null;

            var subNode = node.ChildNodes[0];

            if (subNode.Term.ToString() == GMacParseNodeNames.ExpressionFunctionInputsExpressions)
            {
                var expressionFunctionInputsExpressionsNode = subNode;

                if (expressionFunctionInputsExpressionsNode.ChildNodes.Count == 2)
                {
                    expr1 =
                        GMacExpressionGenerator.Translate(BasicExpressionGenerator, subNode.ChildNodes[0]);

                    expr2 =
                        GMacExpressionGenerator.Translate(BasicExpressionGenerator, subNode.ChildNodes[1]);

                    return;
                }

                CompilationLog.RaiseGeneratorError <ILanguageExpression>("Expecting a single expression as input", node);
            }

            CompilationLog.RaiseGeneratorError <ILanguageExpression>("Expecting a single expression as input", node);
        }
コード例 #7
0
        protected override void Translate()
        {
            var expressionText = GenUtils.Translate_StringLiteral(RootParseNode);

            if (
                expressionText.First() == '$' &&
                expressionText.Last() == '$' &&
                expressionText.Count(c => c == '$') == 2
                )
            {
                //If the expression is on the form '$ anything $' convert it into a normal multivector expression
                //based on (anything) alone; not a symbolic expression
                expressionText = expressionText.Substring(1, expressionText.Length - 2).Trim();

                _generatedExpression = translate_LanguageExpression(expressionText);

                return;
            }

            MathematicaScalar scalar;

            OperandsByName operands;

            translate_Dependency_List(expressionText, out scalar, out operands);

            _generatedExpression = BasicExpressionGenerator.Generate_SymbolicExpression(scalar, operands);
        }
コード例 #8
0
        public ILanguageExpression Generate_BinaryScalarProduct(GMacOpInfo opInfo, ILanguageExpression expr1, ILanguageExpression expr2)
        {
            SetOperands(expr1, expr2);

            VerifyOperation_ScalarProduct();

            return(Generate_OrthogonalScalarProduct(opInfo));
        }
コード例 #9
0
        public ILanguageExpressionBasic Generate_BinaryProduct(GMacOpInfo opInfo, ILanguageExpression expr1, ILanguageExpression expr2)
        {
            SetOperands(expr1, expr2);

            VerifyOperation_MultivectorProduct();

            return(Generate_OrthogonalBinaryProduct(opInfo));
        }
コード例 #10
0
        public ILanguageExpressionBasic Generate_UnaryGradeInversion(ILanguageExpression expr)
        {
            SetOperands(expr);

            VerifyOperation_UnaryOperation();

            return(BasicUnary.CreatePrimitive(_resultType, GMacOpInfo.UnaryGradeInvolution.OpName, _atomicOperand1));
        }
コード例 #11
0
        public ILanguageExpressionBasic Generate_UnaryNorm(GMacOpInfo opInfo, ILanguageExpression expr)
        {
            SetOperands(expr);

            VerifyOperation_UnaryNorm();

            return(BasicUnary.CreatePrimitive(_resultType, opInfo.OpName, _atomicOperand1));
        }
コード例 #12
0
        public ILanguageExpressionBasic Generate_Diff(ILanguageExpression expr1, ILanguageExpression expr2)
        {
            SetOperands(expr1, expr2);

            VerifyOperation_Diff();

            return(BasicBinary.CreatePrimitive(_resultType, GMacOpInfo.BinaryDiff.OpName, _atomicOperand1, _atomicOperand2));
        }
コード例 #13
0
        public ILanguageExpressionBasic Generate_UnaryCliffordConjugate(ILanguageExpression expr)
        {
            SetOperands(expr);

            VerifyOperation_UnaryOperation();

            return(BasicUnary.CreatePrimitive(_resultType, GMacOpInfo.UnaryCliffordConjugate.OpName, _atomicOperand1));
        }
コード例 #14
0
        private TreeNode Visit(string lhsName, ILanguageExpression rhsExpr)
        {
            var node = new TreeNode("<ASSIGN> " + lhsName)
            {
                Tag = lhsName
            };

            node.Nodes.Add(rhsExpr.AcceptVisitor(this));

            return(node);
        }
コード例 #15
0
ファイル: CommandAssign.cs プロジェクト: phreed/GMac
 public void SetRhsExpression(ILanguageExpression rhsExpr)
 {
     if (RhsExpression.ExpressionType.IsSameType(rhsExpr.ExpressionType))
     {
         RhsExpression = rhsExpr;
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
コード例 #16
0
ファイル: CommandAssign.cs プロジェクト: phreed/GMac
 public void SetCommandSides(LanguageValueAccess lhsValueAccess, ILanguageExpression rhsExpr)
 {
     if (lhsValueAccess.ExpressionType.IsSameType(rhsExpr.ExpressionType))
     {
         LhsValueAccess = lhsValueAccess;
         RhsExpression  = rhsExpr;
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
コード例 #17
0
        private TreeNode Visit(GMacFrameMultivector mvType, int lhsId, ILanguageExpression rhsExpr)
        {
            var lhsName = "#" + mvType.ParentFrame.BasisBladeName(lhsId) + "#";

            var node = new TreeNode("<ASSIGN> " + lhsName)
            {
                Tag = lhsId
            };

            node.Nodes.Add(rhsExpr.AcceptVisitor(this));

            return(node);
        }
コード例 #18
0
        private ILanguageExpression CompileExpression(ILanguageExpression expr)
        {
            var value = expr as ILanguageValue;

            if (value != null)
            {
                return(value.DuplicateValue(true));
            }

            var valueAccess = expr as LanguageValueAccess;

            if (valueAccess != null)
            {
                return(CompileRhsValueAccess(valueAccess));
            }

            var basicUnary = expr as BasicUnary;

            if (basicUnary != null)
            {
                return(CompileBasicUnary(basicUnary));
            }

            var basicBinary = expr as BasicBinary;

            if (basicBinary != null)
            {
                return(CompileBasicBinary(basicBinary));
            }

            var basicPolyadic = expr as BasicPolyadic;

            if (basicPolyadic != null)
            {
                return(CompileBasicPolyadic(basicPolyadic));
            }

            var compositeExpression = expr as CompositeExpression;

            if (compositeExpression != null)
            {
                return(CompileCompositeExpression(compositeExpression));
            }

            throw new InvalidOperationException("Expression not recognized");
        }
コード例 #19
0
        /// <summary>
        /// Create a copy of the given expression. If the expression is not a value access or a basic expression the
        /// original expression is returned
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public static ILanguageExpression Duplicate(this ILanguageExpression expr)
        {
            var e1 = expr as LanguageValueAccess;

            if (e1 != null)
            {
                return(e1.Duplicate());
            }

            var e2 = expr as LanguageExpressionBasic;

            if (e2 != null)
            {
                return(e2.Duplicate());
            }

            return(expr);
        }
コード例 #20
0
        //private ILanguageExpression translate_Expression_Cast(ParseTreeNode node)
        //{
        //    var langType = GMacValueAccessGenerator.Translate_Direct_LanguageType(this.Context, node.ChildNodes[0]);

        //    var expr = GMacExpressionGenerator.Translate(this.BasicExpressionGenerator, node.ChildNodes[0]);

        //    return this.BasicExpressionGenerator.Generate_TypeCast(langType, expr);
        //}

        protected override void Translate()
        {
            var subNode = RootParseNode.ChildNodes[0];

            switch (subNode.Term.Name)
            {
            case GMacParseNodeNames.ConstantNumber:
                _generatedExpression = translate_Constant_Number(subNode);
                break;

            case GMacParseNodeNames.ExpressionScoped:
                _generatedExpression = translate_Expression_Scoped(subNode);
                break;

            case GMacParseNodeNames.QualifiedItem:
                _generatedExpression = GMacValueAccessGenerator.Translate(Context, subNode.ChildNodes[0], false);
                break;

            case GMacParseNodeNames.ExpressionBracketed:
                _generatedExpression = GMacExpressionGenerator.Translate(BasicExpressionGenerator, subNode.ChildNodes[0]);
                break;

            case GMacParseNodeNames.StringLiteral:
                _generatedExpression = GMacExpressionAtomicSymbolicGenerator.Translate(Context, subNode);
                break;

            case GMacParseNodeNames.ExpressionComposite:
                _generatedExpression = GMacExpressionCompositeGenerator.Translate(Context, subNode);
                break;

            case GMacParseNodeNames.ExpressionFunction:
                _generatedExpression = GMacExpressionAtomicFunctionGenerator.Translate(BasicExpressionGenerator, subNode);
                break;

            default:
                CompilationLog.RaiseGeneratorError <ILanguageExpression>("Expression not recognized", RootParseNode);
                break;
            }
        }
コード例 #21
0
        private void SetOperands(ILanguageExpression expr)
        {
            _operand1 = expr;

            _operand2 = null;
        }
コード例 #22
0
        /// <summary>
        /// Evaluates the given expression if it's a simple expression else it returns null
        /// </summary>
        /// <param name="rootScope"></param>
        /// <param name="expr"></param>
        /// <returns></returns>
        internal static ILanguageValue EvaluateExpressionIfSimple(LanguageScope rootScope, ILanguageExpression expr)
        {
            if (!expr.IsSimpleExpression)
            {
                return(null);
            }

            var evaluator = new GMacExpressionEvaluator(rootScope);

            return(expr.AcceptVisitor(evaluator));
        }
コード例 #23
0
        /// <summary>
        /// Evaluate the given expression inside the given scope
        /// </summary>
        /// <param name="rootScope"></param>
        /// <param name="expr"></param>
        /// <returns></returns>
        internal static ILanguageValue EvaluateExpression(LanguageScope rootScope, ILanguageExpression expr)
        {
            var evaluator = new GMacExpressionEvaluator(rootScope);

            return(expr.AcceptVisitor(evaluator));
        }
コード例 #24
0
 public virtual LanguageCommand AddCommand_Assign(LanguageValueAccess lhsValue, ILanguageExpression rhsExpr)
 {
     return(AddCommand(new CommandAssign(ChildCommandBlockScope, lhsValue, rhsExpr)));
 }
コード例 #25
0
ファイル: CommandIfElseIf.cs プロジェクト: phreed/GMac
 /// <summary>
 /// Set the Else part of the command
 /// </summary>
 /// <param name="falseExpr">The expression of the Else part</param>
 public void SetFalseExpression(ILanguageExpression falseExpr)
 {
     _falseExpression = falseExpr;
 }
コード例 #26
0
ファイル: CommandIfElseIf.cs プロジェクト: phreed/GMac
 /// <summary>
 /// Add a new If or IfElse part of the command
 /// </summary>
 /// <param name="condExpr">The conditional expression for the added part</param>
 /// <param name="trueExpr">The True expression for the added part</param>
 public void AddIfBlock(ILanguageExpression condExpr, ILanguageExpression trueExpr)
 {
     _conditionExpressions.Add(condExpr);
     _trueExpressions.Add(trueExpr);
 }
コード例 #27
0
        public ILanguageExpressionBasic Generate_TransformApplication(GMacMultivectorTransform transform, ILanguageExpression expr)
        {
            SetOperands(expr);

            VerifyOperation_TransformApplication(transform);

            return(BasicUnary.Create(_resultType, transform, _atomicOperand1));
        }
コード例 #28
0
ファイル: CommandAssign.cs プロジェクト: phreed/GMac
 public CommandAssign(LanguageScope parentScope, LanguageValueAccess lhsValue, ILanguageExpression rhsExpr)
     : base(parentScope)
 {
     LhsValueAccess = lhsValue;
     RhsExpression  = rhsExpr;
 }
コード例 #29
0
 protected override void Translate()
 {
     _generatedExpression = translate_Expression_Function(Context.ActiveParseNode);
 }
コード例 #30
0
ファイル: SymbolNamedExpression.cs プロジェクト: phreed/GMac
 protected SymbolNamedExpression(string symbolName, LanguageScope parentScope, string symbolRoleName, ILanguageExpression rhsExpr)
     : base(symbolName, rhsExpr.ExpressionType, parentScope, symbolRoleName)
 {
     RhsExpression = rhsExpr;
 }