/// <summary>
 /// Represents simple binary expressions which involve literal on left and identifier on the right
 /// </summary>
 /// <param name="i1"></param>
 /// <param name="o"></param>
 /// <param name="i2"></param>
 internal BinExprNode(LiteralNode i1, Operator o, IdentNode i2)
     : base(i1.Name + o.Name + i2.Name, o.Guid)
 {
     op    = o;
     left  = i1;
     right = i2;
 }
Пример #2
0
        private static int BuildFuncToIdentStatement(Node node, Node nodeI, Dictionary <int, Node> nodeDic, AST statementList, int j)
        {
            Assignment a1        = (Assignment)statementList.GetNode(node.Guid);
            IdentNode  identNode = nodeI as IdentNode;

            Validity.Assert(null != identNode);

            List <int>   keys = GetKeysFromValue(nodeDic, nodeI);
            FunctionCall f    = ((FunctionCall)a1.right);

            if (keys.Count > 1)
            {
                do
                {
                    f.parameters[keys[j]] = identNode;
                    j++;
                } while (j < keys.Count);
            }
            else
            {
                f.parameters[keys[j]] = identNode;
            }
            j = 0;
            return(j);
        }
Пример #3
0
        private void EmitIdentifierNode(IdentNode node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            Dictionary <int, Node> nodes = node.GetChildrenWithIndices();

            Validity.Assert(nodes.Count <= 1);

            // Create BinaryExpressionNode with the lhs as the IdentifierNode and the rhs as the temp Node emitted from the child
            // Return the IdentifierNode
            BinaryExpressionNode expressionNode = new BinaryExpressionNode();

            if (nodes.Count > 0)
            {
                AssociativeNode tmpNode = null;
                DFSTraverse(nodes[0], out tmpNode);
                expressionNode.RightNode = tmpNode;
            }
            else
            {
                // Create IdentifierNode and assign it to null
                expressionNode.RightNode = new NullNode();
            }
            IdentifierNode leftNode = new IdentifierNode(node.Name);

            expressionNode.LeftNode = leftNode;
            expressionNode.Optr     = ProtoCore.DSASM.Operator.assign;
            expressionNode.Guid     = node.Guid;

            Validity.Assert(gc != null);
            gc.HandleNewNode(expressionNode);
            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);
            outnode = expressionNode;
        }
 /// <summary>
 /// Represents binary expressions which involve identifier on the left and compound expression on the right
 /// </summary>
 /// <param name="e1"></param>
 /// <param name="op"></param>
 /// <param name="e2"></param>
 public BinExprNode(IdentNode e1, Operator op, Expr e2)
     : base(op.Name, op.Guid)
 {
     left    = e1;
     this.op = op;
     right   = e2;
 }
Пример #5
0
 /// <summary>
 /// Represents simple binary expressions which involve identifier on left and literal on the right
 /// </summary>
 /// <param name="i1"></param>
 /// <param name="o"></param>
 /// <param name="i2"></param>
 internal BinExprNode(IdentNode i1, Operator o, LiteralNode i2)
     : base(i1.Name + o.Name + i2.Name, o.Guid)
 {
     op = o;
     left = i1;
     right = i2;
 }
Пример #6
0
        private static void BuildBlockToIdentStatement(Node node, Node nodeIdent, AST statementList)
        {
            Validity.Assert(node is Block);

            if (node.children.Count > 1)
            {
                statementList.AddNode(node);
            }
            else
            {
                IdentNode identNode = nodeIdent as IdentNode;
                Validity.Assert(null != identNode);

                Block block = node as Block;

                string lhs           = string.Empty;
                string content       = string.Empty;
                bool   isSingleIdent = string.IsNullOrEmpty(block.LHS);
                if (isSingleIdent)
                {
                    lhs = block.TrimName();
                }
                else
                {
                    lhs = block.LHS;
                }

                // Create the cnontents of the new block.
                content = lhs + '=' + identNode.Name;

                // Comment Jun: Remove the current codeblock first
                // Codeblock removal is guid dependent
                Node nodeToRemove = statementList.GetNode(node.Guid);
                int  index        = statementList.nodeList.IndexOf(nodeToRemove);
                statementList.RemoveNode(nodeToRemove);

                // Comment Jun: Create a new block using the current guid
                // This new codeblock represents the new contents
                Block block2 = new Block(content, node.Guid);
                statementList.nodeList.Insert(index, block2);
                statementList.nodeMap.Add(block2.Guid, block2);
                statementList.AddNode(block2);


                // Comment Jun: Reflect the new changes to the original block
                (node as Block).SetData(block2.LHS, content);
            }
        }
        private void EmitIdentifierNode(IdentNode node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            Dictionary<int, Node> nodes = node.GetChildrenWithIndices();
            Validity.Assert(nodes.Count <= 1);

            // Create BinaryExpressionNode with the lhs as the IdentifierNode and the rhs as the temp Node emitted from the child
            // Return the IdentifierNode
            BinaryExpressionNode expressionNode = new BinaryExpressionNode();

            if (nodes.Count > 0)
            {
                AssociativeNode tmpNode = null;
                DFSTraverse(nodes[0], out tmpNode);
                expressionNode.RightNode = tmpNode;
            }
            else
            {
                // Create IdentifierNode and assign it to null
                expressionNode.RightNode = new NullNode();
            }
            IdentifierNode leftNode = new IdentifierNode(node.Name);
            expressionNode.LeftNode = leftNode;
            expressionNode.Optr = ProtoCore.DSASM.Operator.assign;
            expressionNode.Guid = node.Guid;

            Validity.Assert(gc != null);
            gc.HandleNewNode(expressionNode);
            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);
            outnode = expressionNode;
        }
 internal Assignment(IdentNode identNodeL, IdentNode identNodeR)
     : base("=", identNodeL.Guid)
 {
     // TODO: Complete member initialization
     left = identNodeL; right = identNodeR;
 }
Пример #9
0
 internal Assignment(IdentNode identNodeL, IdentNode identNodeR)
     : base("=", identNodeL.Guid)
 {
     // TODO: Complete member initialization
     left = identNodeL; right = identNodeR;
 }
Пример #10
0
 /// <summary>
 /// Represents binary expressions which involve identifier on the left and compound expression on the right
 /// </summary>
 /// <param name="e1"></param>
 /// <param name="op"></param>
 /// <param name="e2"></param>
 public BinExprNode(IdentNode e1, Operator op, Expr e2)
     : base(op.Name, op.Guid)
 {
     left = e1;
     this.op = op;
     right = e2;
 }
Пример #11
0
        public bool CreateIdentifierNode(uint guid, string identifier)
        {
            if (guid < 0)
                throw new ArgumentException("Invalid argument value!", "guid");
            if (String.IsNullOrEmpty(identifier))
                throw new ArgumentException("Invalid argument value!", "identifier");

            IdentNode id = new IdentNode(identifier, guid);
            graph.AddNode(id);
            return true; // If failed, return 'false'.
        }