public IdentifierNode(IdentifierNode node) { Name = node.Name; AtmarkPrefix = node.AtmarkPrefix; ExpressionPrefix = node.ExpressionPrefix; TypePrefix = node.TypePrefix; }
/// <summary> /// Recursively parse the expression and try to find local variables /// </summary> /// <param name="expr">Expression to parse</param> /// <param name="emitter">Emitter</param> private void ProcessR(SyntaxTreeNode expr, Emitter.Emitter emitter) { if (expr == null) return; // traverse all children var children = expr.Children(); if (children != null) { foreach (var child in children) ProcessR(child, emitter); } // check current expression for being a local variable if(expr is IdentifierGetNode) { var name = expr.ClosuredName(emitter); if (name != null) Variables.Add(name, expr.GetExpressionType(emitter)); } }
public override void Compile(Emitter.Emitter emitter) { // check if there's an expression prefix and back it up if (Left.ExpressionPrefix != null) { // save to tmp variable var tmpVarName = emitter.CurrentMethod.Scope.CreateNewName(); var tmpVar = Expr.Var(tmpVarName, Left.ExpressionPrefix); tmpVar.Compile(emitter); Left.ExpressionPrefix = Expr.IdentifierGet(tmpVarName); } if (Right.ExpressionPrefix != null) { // save to tmp variable var tmpVarName = emitter.CurrentMethod.Scope.CreateNewName(); var tmpVar = Expr.Var(tmpVarName, Right.ExpressionPrefix); tmpVar.Compile(emitter); Right.ExpressionPrefix = Expr.IdentifierGet(tmpVarName); } // create temp variable var exchgVarName = emitter.CurrentMethod.Scope.CreateNewName(); var exchgNode = new IdentifierGetNode(exchgVarName); // create three assignable nodes var assignNodes = new SyntaxTreeNode[3]; assignNodes[0] = Expr.Var(exchgVarName, Left); assignNodes[1] = GetAssignableNode(Left, Right); assignNodes[2] = GetAssignableNode(Right, exchgNode); // affix them to the lexem and compile foreach(var curr in assignNodes) { curr.Lexem = Lexem; curr.Compile(emitter); } }
/// <summary> /// Convert the IdentifierGet node to an IdentifierInvoke node with two dummy parameters /// </summary> /// <param name="emitter"></param> public void AppendActionParameters(Emitter.Emitter emitter) { // make sure it's a proper getter var act = Action as IdentifierGetNode; if (act == null || act.AtmarkPrefix) Error(Resources.errPlannerExpression); var node = Expr.IdentifierInvoke(act, Expr.Dummy("flow[]"), Expr.Dummy("symbol")); string type = ""; try { // checking if it compiles properly type = node.GetExpressionType(emitter); } catch { Error(Resources.errPlannerArgsMismatch); } if (type != "symbol") Error(Resources.errPlannerTypeMismatch); Action = node; }
public ArrayGetNode(SyntaxTreeNode index = null) { Index = index; }
/// <summary> /// assignable = matrix | expr /// </summary> /// <param name="curr"></param> /// <returns></returns> public SyntaxTreeNode ParseAssignable(SyntaxTreeNode curr) { // ? "[[" SyntaxTreeNode expr; if (PeekLexem(LexemType.DoubleSquareOpen)) expr = ParseMatrix(); else expr = ParseExpr(); // "a" -> "a=" if (curr is IdentifierGetNode) return Expr.IdentifierSet(curr as IdentifierGetNode, expr); // "a[...]" -> "a[...]=" else if (curr is ArrayGetNode) return Expr.ArraySet(curr as ArrayGetNode, expr); // "a[...,...]" -> "a[...,...]=" else return Expr.MatrixSet(curr as MatrixGetNode, expr); }
public OperatorNegateNode(SyntaxTreeNode expr) { Expression = expr; }
public OperatorInvertNode(SyntaxTreeNode expr) { Expression = expr; }
public IdentifierNode(string name, SyntaxTreeNode expPrefix) { Name = name; ExpressionPrefix = expPrefix; }
public ArraySetNode(SyntaxTreeNode index = null, SyntaxTreeNode expr = null) { Index = index; Expression = expr; }
public AsNode(SyntaxTreeNode expr, string to) { Expression = expr; ToType = to; }
/// <summary> /// Create the list of bound variables /// </summary> /// <param name="expr">Expression to parse</param> /// <param name="emitter">Emitter</param> /// <returns></returns> public Dictionary<string, string> Process(SyntaxTreeNode expr, Emitter.Emitter emitter) { Variables = new Dictionary<string, string>(); ProcessR(expr, emitter); return Variables; }
public IfNode(SyntaxTreeNode condition = null, SyntaxTreeNode trueBlock = null, SyntaxTreeNode falseBlock = null) { Condition = condition; TrueBlock = trueBlock; FalseBlock = falseBlock; }