Ejemplo n.º 1
0
 public IdentifierNode(IdentifierNode node)
 {
     Name = node.Name;
       AtmarkPrefix = node.AtmarkPrefix;
       ExpressionPrefix = node.ExpressionPrefix;
       TypePrefix = node.TypePrefix;
 }
Ejemplo n.º 2
0
        /// <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));
              }
        }
Ejemplo n.º 3
0
        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);
              }
        }
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
 public ArrayGetNode(SyntaxTreeNode index = null)
 {
     Index = index;
 }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
 public OperatorNegateNode(SyntaxTreeNode expr)
 {
     Expression = expr;
 }
Ejemplo n.º 8
0
 public OperatorInvertNode(SyntaxTreeNode expr)
 {
     Expression = expr;
 }
Ejemplo n.º 9
0
 public IdentifierNode(string name, SyntaxTreeNode expPrefix)
 {
     Name = name;
       ExpressionPrefix = expPrefix;
 }
Ejemplo n.º 10
0
 public ArraySetNode(SyntaxTreeNode index = null, SyntaxTreeNode expr = null)
 {
     Index = index;
       Expression = expr;
 }
Ejemplo n.º 11
0
 public AsNode(SyntaxTreeNode expr, string to)
 {
     Expression = expr;
       ToType = to;
 }
Ejemplo n.º 12
0
 /// <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;
 }
Ejemplo n.º 13
0
 public IfNode(SyntaxTreeNode condition = null, SyntaxTreeNode trueBlock = null, SyntaxTreeNode falseBlock = null)
 {
     Condition = condition;
       TrueBlock = trueBlock;
       FalseBlock = falseBlock;
 }