Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /// <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;
 }
        /// <summary>
        /// TODO: Deprecate
        /// Emit IntNode or DoubleNode
        /// </summary>
        /// <param name="node"></param>
        /// <param name="outnode"></param>
        private void EmitLiteralNode(LiteralNode node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);
            Validity.Assert(node.children.Count == 0);

            // Create temp identifier and assign it to the literal (IntNode or DoubleNode) to create a BinaryExpressionNode
            // Return the temp IdentifierNode
            //BinaryExpressionNode expressionNode = new BinaryExpressionNode();
            AssociativeNode rightNode = null;

            int    number;
            double real;
            bool   flag;
            string val = node.ToScript();

            // If LiternalNode is double
            if (Double.TryParse(val, out real))
            {
                rightNode = new DoubleNode()
                {
                    value = node.ToScript()
                };
            }
            // If LiteralNode type is Int
            else if (Int32.TryParse(val, out number))
            {
                rightNode = new IntNode()
                {
                    value = val
                };
            }
            // If LiteralNode is bool
            else if (Boolean.TryParse(val, out flag))
            {
                rightNode = new BooleanNode()
                {
                    value = node.ToScript()
                };
            }

            /*IdentifierNode ident = CreateTempIdentifierNode(node);
            *  expressionNode.RightNode = rightNode;
            *  expressionNode.LeftNode = ident;
            *  expressionNode.Optr = ProtoCore.DSASM.Operator.assign;*/

            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);

            //outnode = expressionNode;
            outnode = CreateBinaryExpNode(node, rightNode);
        }
Ejemplo n.º 4
0
        //
        // TODO Jun: Re-evaluate the topsort implementation
        //
        static void DFSVisit(Node node, Dictionary <Node, int> nodeStateMap, List <Node> list, AST statementList)
        {
            nodeStateMap.Add(node, VISITING);
            List <Node>            nodes   = node.GetChildren();
            Dictionary <int, Node> nodeDic = node.GetChildrenWithIndices();
            IEnumerable            iter    = nodes;
            int j = 0;

            foreach (Node nodeI in iter)
            {
                if (node is IdentNode && nodeI is LiteralNode)
                {
                    BuildIdentToLiteralStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is IdentNode)
                {
                    BuildIdentToIdentStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is Block)
                {
                    Block blocknode = (Block)nodeI;
                    if (GraphUtilities.AnalyzeString(blocknode.Name) == SnapshotNodeType.Literal)
                    {
                        LiteralNode literal = new LiteralNode(blocknode.content, nodeI.Guid);
                        BuildIdentToLiteralStatement(node, literal, statementList);
                    }
                    else
                    {
                        j = BuildIdentToCodeBlockIdentStatement(node, nodeI, nodes, statementList, j);
                    }
                }
                else if (node is Operator && nodeI is Block)
                {
                    j = BuildOperatorToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Block)
                {
                    j = BuildFuncToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is IdentNode)
                {
                    j = BuildFuncToIdentStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Operator)
                {
                    BuildIdentToOperatorStatement(node, statementList, nodeI);
                }
                else if (node is Operator && nodeI is Operator)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Func)
                {
                    BuildIdentToFuncStatement(node, nodeI, statementList);
                }
                else if (node is Func && nodeI is Func)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Operator && nodeI is Func)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Operator)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Operator && nodeI is ArrayNode) || (node is Operator && nodeI is LiteralNode))
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Func && nodeI is ArrayNode) || (node is Func && nodeI is LiteralNode))
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Block && nodeI is Block))
                {
                    BuildBlockToBlockStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Func))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Operator))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is IdentNode))
                {
                    BuildBlockToIdentStatement(node, nodeI, statementList);
                }
                /*Block to Operator*/
                else if (node is Block && nodeI is Operator)
                {
                    //BuildBlockToOperatorStatement(node, nodeI, statementList);
                }
                //else if ((node is Block && nodeI is Func))
                //{
                //    BuildBlockToBlockStatement(node, nodeI, statementList);
                //}
                else
                {
                    if (node is Operator)
                    {
                        if (nodes.IndexOf(nodeI, j) == 0)
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).left = nodeI;
                            ++j;
                        }
                        else
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).right = nodeI;
                        }
                    }
                    else if (node is Func)
                    {
                        Assignment   a = (Assignment)statementList.GetNode(node.Guid);
                        FunctionCall f = ((FunctionCall)a.right);
                        f.parameters[nodes.IndexOf(nodeI, j)] = nodeI;
                        j = 0;
                    }
                }

                if (IsNotVisited(nodeI, nodeStateMap))
                {
                    DFSVisit(nodeI, nodeStateMap, list, statementList);
                }
            }
            nodeStateMap[node] = VISITED;
            list.Add(node);
        }
Ejemplo n.º 5
0
        //
        // TODO Jun: Re-evaluate the topsort implementation
        //
        static void DFSVisit(Node node, Dictionary<Node, int> nodeStateMap, List<Node> list, AST statementList)
        {
            nodeStateMap.Add(node, VISITING);
            List<Node> nodes = node.GetChildren();
            Dictionary<int, Node> nodeDic = node.GetChildrenWithIndices();
            IEnumerable iter = nodes;
            int j = 0;
            foreach (Node nodeI in iter)
            {
                if (node is IdentNode && nodeI is LiteralNode)
                {
                    BuildIdentToLiteralStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is IdentNode)
                {
                    BuildIdentToIdentStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is Block)
                {
                    Block blocknode = (Block)nodeI;
                    if (GraphBuilder.AnalyzeString(blocknode.Name) == SnapshotNodeType.Literal)
                    {
                        LiteralNode literal = new LiteralNode(blocknode.content, nodeI.Guid);
                        BuildIdentToLiteralStatement(node, literal, statementList);
                    }
                    else
                    {
                        j = BuildIdentToCodeBlockIdentStatement(node, nodeI, nodes, statementList, j);
                    }
                }
                else if (node is Operator && nodeI is Block)
                {
                    j = BuildOperatorToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Block)
                {
                    j = BuildFuncToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is IdentNode)
                {
                    j = BuildFuncToIdentStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Operator)
                {
                    BuildIdentToOperatorStatement(node, statementList, nodeI);
                }
                else if (node is Operator && nodeI is Operator)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Func)
                {
                    BuildIdentToFuncStatement(node, nodeI, statementList);
                }
                else if (node is Func && nodeI is Func)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Operator && nodeI is Func)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Operator)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Operator && nodeI is ArrayNode) || (node is Operator && nodeI is LiteralNode))
                { 
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Func && nodeI is ArrayNode) || (node is Func && nodeI is LiteralNode))
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Block && nodeI is Block))
                {
                    BuildBlockToBlockStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Func))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Operator))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is IdentNode))
                {
                    BuildBlockToIdentStatement(node, nodeI, statementList);
                }
                /*Block to Operator*/
                else if (node is Block && nodeI is Operator)
                {
                    //BuildBlockToOperatorStatement(node, nodeI, statementList);
                }
                //else if ((node is Block && nodeI is Func))
                //{
                //    BuildBlockToBlockStatement(node, nodeI, statementList);
                //}
                else
                {
                    if (node is Operator)
                    {
                        if (nodes.IndexOf(nodeI, j) == 0)
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).left = nodeI;
                            ++j;
                        }
                        else
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).right = nodeI;
                        }
                    }
                    else if (node is Func)
                    {
                        Assignment a = (Assignment)statementList.GetNode(node.Guid);
                        FunctionCall f = ((FunctionCall)a.right);
                        f.parameters[nodes.IndexOf(nodeI, j)] = nodeI;
                        j = 0;
                    }
                }

                if (IsNotVisited(nodeI, nodeStateMap))
                {
                    DFSVisit(nodeI, nodeStateMap, list, statementList);
                }
            }
            nodeStateMap[node] = VISITED;
            list.Add(node);
        }
        /// <summary>
        /// TODO: Deprecate
        /// Emit IntNode or DoubleNode
        /// </summary>
        /// <param name="node"></param>
        /// <param name="outnode"></param>
        private void EmitLiteralNode(LiteralNode node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);
            Validity.Assert(node.children.Count == 0);

            // Create temp identifier and assign it to the literal (IntNode or DoubleNode) to create a BinaryExpressionNode
            // Return the temp IdentifierNode
            //BinaryExpressionNode expressionNode = new BinaryExpressionNode();
            AssociativeNode rightNode = null;
            
            Int64 number;
            double real;
            bool flag;
            string val = node.ToScript();
            // If LiternalNode is double
            if(Double.TryParse(val, NumberStyles.Number, CultureInfo.InvariantCulture, out real))
            {
                rightNode = new DoubleNode(real); 
            }
            // If LiteralNode type is Int
            else if (Int64.TryParse(val, NumberStyles.Number, CultureInfo.InvariantCulture, out number))
            {
            
                rightNode = new IntNode(number);
            }            
            // If LiteralNode is bool
            else if (Boolean.TryParse(val, out flag))
            {
                rightNode = new BooleanNode(flag); 
            }

            /*IdentifierNode ident = CreateTempIdentifierNode(node);
            expressionNode.RightNode = rightNode;
            expressionNode.LeftNode = ident;
            expressionNode.Optr = ProtoCore.DSASM.Operator.assign;*/

            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);

            //outnode = expressionNode;
            outnode = CreateBinaryExpNode(node, rightNode);
        }
 internal Assignment(Node o, LiteralNode l)
     : base("=", l.Guid)
 {
     left = o; right = l;
 }
Ejemplo n.º 8
0
 internal Assignment(Node o, LiteralNode l)
     : base("=", l.Guid)
 {
     left = o; right = l;
 }