Example #1
0
        /// <summary>
        /// Reads the graph from the input stream.
        /// </summary>
        /// <returns>The read graph</returns>
        /// <exception cref="NotSupportedException">Occurs when the dot file contains an undirected graph.</exception>
        public Graph Read()
        {
            if (_tokenizer.Peek().Terminal == DotTerminal.Strict)
            {
                // Ignore.
                _tokenizer.Next();
            }

            var  graphType = ExpectOneOf(DotTerminal.DiGraph, DotTerminal.Graph);
            bool directed  = false;

            switch (graphType.Terminal)
            {
            case DotTerminal.DiGraph:
                directed = true;
                break;

            case DotTerminal.Graph:
                directed = false;
                break;
            }

            _graph = new Graph(directed);

            ExpectOneOf(DotTerminal.OpenBrace);
            ReadStatementList();
            ExpectOneOf(DotTerminal.CloseBrace);

            return(_graph);
        }
Example #2
0
        /// <summary>
        /// Reads the graph from the input stream.
        /// </summary>
        /// <returns>The read graph</returns>
        public Graph Read()
        {
            if (_tokenizer.Peek().Terminal == DotTerminal.Strict)
            {
                // Ignore.
                _tokenizer.Next();
            }

            var  graphType = ExpectOneOf(DotTerminal.DiGraph, DotTerminal.Graph);
            bool directed  = false;

            switch (graphType.Terminal)
            {
            case DotTerminal.DiGraph:
                directed = true;
                break;

            case DotTerminal.Graph:
                directed = false;
                break;
            }

            _graphs.Push(new Graph(directed));

            var nameToken = ExpectOneOf(DotTerminal.OpenBrace, DotTerminal.Identifier);

            if (nameToken.Terminal == DotTerminal.Identifier)
            {
                ExpectOneOf(DotTerminal.OpenBrace);
            }

            ReadStatementList();

            ExpectOneOf(DotTerminal.CloseBrace);

            return(_graphs.Pop());
        }