Ejemplo n.º 1
0
        private static graphNode createGraphNode(Node n)
        {
            bool      dummyVar;
            long      id = IDgen.GetId(n, out dummyVar);
            graphNode no = new graphNode(id.ToString());

            setNodeAttributes(no.Attr, n.type);
            no.LabelText = n.getLabel();

            return(no);
        }
        public void ApplyOperatorToOperands(Node node)
        {
            StackValue value1 = ValueStack.Pop ();
            string op = node.Name;
            string opnd1 = value1.Value;
            string opnd2 = ValueStack.Pop ().Value;

            if (value1.Type == "Int") {
                CalcIntValues (op, opnd1, opnd2);
            } else if (value1.Type == "String") {
                CalcStringValues (op, opnd1, opnd2);
            } else if (value1.Type == "Bool") {
                CalcBoolValues (op, opnd1, opnd2);
            }
        }
        public void ApplyOperatorToOperands(Node node)
        {
            string type1 = TypeStack.Pop ();
            string type2 = TypeStack.Pop ();

            switch (node.Name) {
                case "+":
                    if (type1 == "String" && type2 == "String") {
                        TypeStack.Push ("String");
                    } else {
                        ApplyToIntOperands (type1, type2, node);
                    }
                    return;
                case "-":
                    ApplyToIntOperands (type1, type2, node);
                    return;
                case "*":
                    ApplyToIntOperands (type1, type2, node);
                    return;
                case "/":
                    ApplyToIntOperands (type1, type2, node);
                    return;
                case "=":
                    if (type1 == type2) {
                        TypeStack.Push ("Bool");
                    } else {
                        throwOperatorError (type1, type2, node);
                    }
                    return;
                case "<":
                    if (type1 == type2) {
                        TypeStack.Push ("Bool");
                    } else {
                        throwOperatorError (type1, type2, node);
                    }
                    return;
                case "&":
                    if (type1 == "Bool" && type2 == "Bool") {
                        TypeStack.Push ("Bool");
                    } else {
                        throwOperatorError (type1, type2, node);
                    }
                    return;
            }
        }
Ejemplo n.º 4
0
        public static Graph createGraph(Node n)
        {
            Graph     g        = new Graph();
            graphNode previous = createStartNode();

            g.AddNode(previous);

            graphNode next = generateSubtree(n, g);

            g.AddEdge(previous.Id, next.Id);

            /*
             * while (d != null)
             * {
             *      graphNode next = generateSubtree(d, g);
             *      g.AddNode(next);
             *      g.AddEdge(previous.Id, next.Id);
             *      previous = next;
             *      d = d.getNextDirective();
             * }
             */
            return(g);
        }
Ejemplo n.º 5
0
        private static graphNode generateSubtree(Node n, Graph g)
        {
            graphNode no = createGraphNode(n);

            g.AddNode(no);
            List <Node> successors = new List <Node>();

            n.getSuccessors(successors);
            int succIndex = 0;

            foreach (var succ in successors)
            {
                graphNode succNode = generateSubtree(succ, g);
                Edge      e        = g.AddEdge(no.Id, n.successors.GetSlot(succIndex).argumentDescription, succNode.Id);
                if (n.successors.GetSlot(succIndex).argumentDescription == "next directive")                 //is next successor edge
                {
                    e.Attr.Color             = Color.Brown;
                    e.Attr.ArrowheadAtTarget = ArrowStyle.Diamond;
                }

                succIndex++;
            }
            return(no);
        }
 public void Visit(Node node)
 {
 }
        public void VisitChildren(Node node)
        {
            for (int i = 0; i < node.Children.Count - 1; i++) {
                node.Children [i].Accept (this);
            }

            if (node.Children.Count > 0) {
                node.Children [node.Children.Count - 1].Accept (this);
            }
        }
 public void ApplyToIntOperands(string type1, string type2, Node node)
 {
     if (type1 == "Int" && type2 == "Int") {
         TypeStack.Push ("Int"); // "Int op Int" results to new Int in the stack
     } else {
         throwOperatorError (type1, type2, node);
     }
 }
 public void throwOperatorError(string type1, string type2, Node node)
 {
     throw new SemanticError ("Operator " + node.Name + " can not be applied to operands of types: " +
     type1 + " & " + type2, node.Children [0].Row, node.Children [0].Column);
 }
Ejemplo n.º 10
0
 public void AddChild(Node child)
 {
     Children.Add (child);
 }