blob: 75bd304367748beebc050d907bc8bd48a48a6e62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "dotgraph.h"
#include "lalr.h"
#include <QtCore/qtextstream.h>
DotGraph::DotGraph(QTextStream &o):
out (o)
{
}
void DotGraph::operator () (Automaton *aut)
{
Grammar *g = aut->_M_grammar;
out << "digraph {" << Qt::endl << Qt::endl;
out << "subgraph Includes {" << Qt::endl;
for (Automaton::IncludesGraph::iterator incl = Automaton::IncludesGraph::begin_nodes ();
incl != Automaton::IncludesGraph::end_nodes (); ++incl)
{
for (Automaton::IncludesGraph::edge_iterator edge = incl->begin (); edge != incl->end (); ++edge)
{
out << "\t\"(" << aut->id (incl->data.state) << ", " << incl->data.nt << ")\"";
out << "\t->\t";
out << "\"(" << aut->id ((*edge)->data.state) << ", " << (*edge)->data.nt << ")\"\t";
out << "[label=\"" << incl->data.state->follows [incl->data.nt] << "\"]";
out << Qt::endl;
}
}
out << "}" << Qt::endl << Qt::endl;
out << "subgraph LRA {" << Qt::endl;
//out << "node [shape=record];" << Qt::endl << Qt::endl;
for (StatePointer q = aut->states.begin (); q != aut->states.end (); ++q)
{
int state = aut->id (q);
out << "\t" << state << "\t[shape=record,label=\"{";
out << "<0> State " << state;
int index = 1;
for (ItemPointer item = q->kernel.begin (); item != q->kernel.end (); ++item)
out << "| <" << index++ << "> " << *item;
out << "}\"]" << Qt::endl;
for (Bundle::iterator a = q->bundle.begin (); a != q->bundle.end (); ++a)
{
const char *clr = g->isTerminal (a.key ()) ? "blue" : "red";
out << "\t" << state << "\t->\t" << aut->id (*a) << "\t[color=\"" << clr << "\",label=\"" << a.key () << "\"]" << Qt::endl;
}
out << Qt::endl;
}
out << "}" << Qt::endl;
out << Qt::endl << Qt::endl << "}" << Qt::endl;
}
|