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>()); }
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(); }
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)); }
public CommandIfElse(LanguageScope parentScope, ILanguageExpression condExpr, ILanguageExpression trueExpr, ILanguageExpression falseExpr) : base(parentScope) { ConditionExpression = condExpr; TrueExpression = trueExpr; FalseExpression = falseExpr; }
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); }
///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); }
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); }
public ILanguageExpression Generate_BinaryScalarProduct(GMacOpInfo opInfo, ILanguageExpression expr1, ILanguageExpression expr2) { SetOperands(expr1, expr2); VerifyOperation_ScalarProduct(); return(Generate_OrthogonalScalarProduct(opInfo)); }
public ILanguageExpressionBasic Generate_BinaryProduct(GMacOpInfo opInfo, ILanguageExpression expr1, ILanguageExpression expr2) { SetOperands(expr1, expr2); VerifyOperation_MultivectorProduct(); return(Generate_OrthogonalBinaryProduct(opInfo)); }
public ILanguageExpressionBasic Generate_UnaryGradeInversion(ILanguageExpression expr) { SetOperands(expr); VerifyOperation_UnaryOperation(); return(BasicUnary.CreatePrimitive(_resultType, GMacOpInfo.UnaryGradeInvolution.OpName, _atomicOperand1)); }
public ILanguageExpressionBasic Generate_UnaryNorm(GMacOpInfo opInfo, ILanguageExpression expr) { SetOperands(expr); VerifyOperation_UnaryNorm(); return(BasicUnary.CreatePrimitive(_resultType, opInfo.OpName, _atomicOperand1)); }
public ILanguageExpressionBasic Generate_Diff(ILanguageExpression expr1, ILanguageExpression expr2) { SetOperands(expr1, expr2); VerifyOperation_Diff(); return(BasicBinary.CreatePrimitive(_resultType, GMacOpInfo.BinaryDiff.OpName, _atomicOperand1, _atomicOperand2)); }
public ILanguageExpressionBasic Generate_UnaryCliffordConjugate(ILanguageExpression expr) { SetOperands(expr); VerifyOperation_UnaryOperation(); return(BasicUnary.CreatePrimitive(_resultType, GMacOpInfo.UnaryCliffordConjugate.OpName, _atomicOperand1)); }
private TreeNode Visit(string lhsName, ILanguageExpression rhsExpr) { var node = new TreeNode("<ASSIGN> " + lhsName) { Tag = lhsName }; node.Nodes.Add(rhsExpr.AcceptVisitor(this)); return(node); }
public void SetRhsExpression(ILanguageExpression rhsExpr) { if (RhsExpression.ExpressionType.IsSameType(rhsExpr.ExpressionType)) { RhsExpression = rhsExpr; } else { throw new InvalidOperationException(); } }
public void SetCommandSides(LanguageValueAccess lhsValueAccess, ILanguageExpression rhsExpr) { if (lhsValueAccess.ExpressionType.IsSameType(rhsExpr.ExpressionType)) { LhsValueAccess = lhsValueAccess; RhsExpression = rhsExpr; } else { throw new InvalidOperationException(); } }
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); }
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"); }
/// <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); }
//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; } }
private void SetOperands(ILanguageExpression expr) { _operand1 = expr; _operand2 = null; }
/// <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)); }
/// <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)); }
public virtual LanguageCommand AddCommand_Assign(LanguageValueAccess lhsValue, ILanguageExpression rhsExpr) { return(AddCommand(new CommandAssign(ChildCommandBlockScope, lhsValue, rhsExpr))); }
/// <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; }
/// <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); }
public ILanguageExpressionBasic Generate_TransformApplication(GMacMultivectorTransform transform, ILanguageExpression expr) { SetOperands(expr); VerifyOperation_TransformApplication(transform); return(BasicUnary.Create(_resultType, transform, _atomicOperand1)); }
public CommandAssign(LanguageScope parentScope, LanguageValueAccess lhsValue, ILanguageExpression rhsExpr) : base(parentScope) { LhsValueAccess = lhsValue; RhsExpression = rhsExpr; }
protected override void Translate() { _generatedExpression = translate_Expression_Function(Context.ActiveParseNode); }
protected SymbolNamedExpression(string symbolName, LanguageScope parentScope, string symbolRoleName, ILanguageExpression rhsExpr) : base(symbolName, rhsExpr.ExpressionType, parentScope, symbolRoleName) { RhsExpression = rhsExpr; }