Exemplo n.º 1
0
        public override void Visit(GraphDeclEdgeNode node)
        {
            _symbolTable.SetCurrentNode(node);
            AllType vertexFromType = _symbolTable.RetrieveSymbol(node.VertexNameFrom, false) ?? AllType.UNKNOWNTYPE;
            AllType vertexToType   = _symbolTable.RetrieveSymbol(node.VertexNameTo, false) ?? AllType.UNKNOWNTYPE;

            CheckAllowedCast(vertexFromType, vertexToType);
            foreach (KeyValuePair <string, AbstractNode> item in node.ValueList)
            {
                item.Value.Parent = node;
                item.Value.Accept(this);
                AllType?       typeOfKey = _symbolTable.GetAttributeType(item.Key, AllType.EDGE);
                ExpressionNode expNode;
                if (item.Value is BoolComparisonNode)
                {
                    expNode = (ExpressionNode)item.Value.Children[0];
                }
                else
                {
                    expNode = item.Value as ExpressionNode;
                }
                if (expNode is ExpressionNode)
                {
                    if (typeOfKey != expNode.OverAllType)
                    {
                        _symbolTable.TypeExpressionMismatch();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override AbstractNode VisitGraphInitDcl([NotNull] GiraphParser.GraphInitDclContext context)
        {
            GraphNode GNode = new GraphNode(context.Start.Line, context.Start.Column);

            GNode.Name = context.variable().GetText();
            // Handle all VetexDcl's and add them to the list in the GraphNode
            foreach (var Child in context.graphDclBlock().vertexDcls())
            {
                foreach (var NestedChild in Child.vertexDcl())
                {
                    GraphDeclVertexNode VNode = new GraphDeclVertexNode(context.Start.Line, context.Start.Column);
                    if (NestedChild.variable() != null)
                    {
                        VNode.Name = NestedChild.variable().GetText();
                    }
                    if (NestedChild.assignment() != null)
                    {
                        foreach (var Attribute in NestedChild.assignment())
                        {
                            VNode.ValueList.Add(Attribute.variable().GetText(), Visit(Attribute.boolCompOrExp()));
                        }
                    }
                    GNode.Vertices.Add(VNode);
                }
            }
            // Handle all edgeDcl's and add them to the list in the GraphNode
            foreach (var Child in context.graphDclBlock().edgeDcls())
            {
                foreach (var NestedChild in Child.edgeDcl())
                {
                    GraphDeclEdgeNode ENode = new GraphDeclEdgeNode(context.Start.Line, context.Start.Column);
                    // If there is a name for the Edge
                    if (NestedChild.variable().GetLength(0) > 2)
                    {
                        ENode.Name           = NestedChild.variable(0).GetText();               // Edge Name
                        ENode.VertexNameFrom = NestedChild.variable(1).GetText();               // Vertex From
                        ENode.VertexNameTo   = NestedChild.variable(2).GetText();               // Vertex To
                    }
                    else
                    {
                        ENode.VertexNameFrom = NestedChild.variable(0).GetText();                       // Vertex From
                        ENode.VertexNameTo   = NestedChild.variable(1).GetText();                       // Vertex To
                    }
                    // Checks if there are any assignments
                    if (NestedChild.assignment() != null)
                    {
                        foreach (var Attribute in NestedChild.assignment())
                        {
                            // This is in order to ignore the attributes that are without
                            if (Attribute.variable() != null)
                            {
                                ENode.ValueList.Add(Attribute.variable().GetText(), Visit(Attribute.boolCompOrExp()));
                            }
                        }
                    }
                    GNode.Edges.Add(ENode);
                }
            }
            return(GNode);
        }
 public override void Visit(GraphDeclEdgeNode node)
 {
     SymbolTable.SetCurrentNode(node);
     /* Missing the values of the edge*/
     if (CheckAlreadyDeclared(node.Name))
     {
         SymbolTable.EnterSymbol(node.Name, AllType.EDGE);
         SymbolTable.SetAssigned(node.Name);
         CheckDeclared(node.VertexNameFrom);
         CheckDeclared(node.VertexNameTo);
         foreach (var attribute in node.ValueList)
         {
             SymbolTable.AttributeDefined(attribute.Key, AllType.EDGE);
         }
     }
 }
        public override void Visit(GraphDeclEdgeNode node)
        {
            Debug.Print("GraphDeclEdgeNode");
            ProgramCode.Append($"{node.Name}(");
            int i = 0;

            ProgramCode.Append($"{node.VertexNameFrom}, {node.VertexNameTo}");
            if (node.ValueList.Count > 0)
            {
                ProgramCode.Append(", ");
            }

            foreach (KeyValuePair <string, AbstractNode> item in node.ValueList)
            {
                InsertComma(ref i);
                ProgramCode.Append($"{item.Key} = {item.Value}");
            }
            ProgramCode.Append(")");
        }
Exemplo n.º 5
0
        public override AbstractNode VisitEdgeDcl([NotNull] GiraphParser.EdgeDclContext context)
        {
            GraphDeclEdgeNode VarNode = new GraphDeclEdgeNode(context.Start.Line, context.Start.Column);
            int i = 0;

            if (context.GetChild(0).GetText() != "(")
            {
                VarNode.Name = context.variable(i++).GetText();
            }
            VarNode.VertexNameFrom = context.variable(i++).GetText();
            VarNode.VertexNameTo   = context.variable(i++).GetText();

            // Visit all assignments and add them as children, if there are any
            if (context.assignment() != null)
            {
                foreach (var Child in context.assignment())
                {
                    VarNode.ValueList.Add(Child.variable().GetText(), Visit(Child.boolCompOrExp()));
                    VarNode.AdoptChildren(Visit(Child));
                }
            }
            return(VarNode);
        }
Exemplo n.º 6
0
 public abstract void Visit(GraphDeclEdgeNode node);
Exemplo n.º 7
0
 public override void Visit(GraphDeclEdgeNode node)
 {
     throw new Exception("This should be done in the GraphDeclNode");
 }