Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
parsetable.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:insignificant reason:build-tool
4
5#include "parsetable.h"
6
7#include "lalr.h"
8
9#include <QtCore/qtextstream.h>
10
11ParseTable::ParseTable (QTextStream &o):
12 out (o)
13{
14}
15
17{
18 Grammar *g = aut->_M_grammar;
19
20 int rindex = 1;
21 for (RulePointer rule = g->rules.begin (); rule != g->rules.end (); ++rule)
22 out << rindex++ << ")\t" << *rule << Qt::endl;
23 out << Qt::endl << Qt::endl;
24
25 int index = 0;
26 for (StatePointer state = aut->states.begin (); state != aut->states.end (); ++state)
27 {
28 out << "state " << index++ << Qt::endl << Qt::endl;
29
30 for (ItemPointer item = state->kernel.begin (); item != state->kernel.end (); ++item)
31 {
32 out << " * " << *item;
33
34 if (item->dot == item->end_rhs ())
35 out << " " << aut->lookaheads [item];
36
37 out << Qt::endl;
38 }
39
40 bool first = true;
41 for (Bundle::iterator arrow = state->bundle.begin (); arrow != state->bundle.end (); ++arrow)
42 {
43 if (! g->isTerminal (arrow.key ()))
44 continue;
45
46 if (first)
47 out << Qt::endl;
48
49 first = false;
50
51 out << " " << *arrow.key () << " shift, and go to state " << std::distance (aut->states.begin (), *arrow) << Qt::endl;
52 }
53
54 first = true;
55 for (ItemPointer item = state->closure.begin (); item != state->closure.end (); ++item)
56 {
57 if (item->dot != item->end_rhs () || item->rule == state->defaultReduce)
58 continue;
59
60 if (first)
61 out << Qt::endl;
62
63 first = false;
64
65 const auto lookaheads = aut->lookaheads.value(item);
66 for (const Name &la : lookaheads)
67 out << " " << *la << " reduce using rule " << aut->id (item->rule) << " (" << *item->rule->lhs << ")" << Qt::endl;
68 }
69
70 first = true;
71 for (Bundle::iterator arrow = state->bundle.begin (); arrow != state->bundle.end (); ++arrow)
72 {
73 if (! g->isNonTerminal (arrow.key ()))
74 continue;
75
76 if (first)
77 out << Qt::endl;
78
79 first = false;
80
81 out << " " << *arrow.key () << " go to state " << std::distance (aut->states.begin (), *arrow) << Qt::endl;
82 }
83
84 if (state->defaultReduce != g->rules.end ())
85 {
86 out << Qt::endl
87 << " $default reduce using rule " << aut->id (state->defaultReduce) << " (" << *state->defaultReduce->lhs << ")" << Qt::endl;
88 }
89
90 out << Qt::endl;
91 }
92}
Grammar * _M_grammar
Definition lalr.h:351
StateList states
Definition lalr.h:352
debug_infot rules
Definition lalr.h:242
bool isNonTerminal(Name name) const
Definition lalr.h:225
bool isTerminal(Name name) const
Definition lalr.h:222
void operator()(Automaton *a)
ItemList::iterator ItemPointer
Definition lalr.h:34
StateList::iterator StatePointer
Definition lalr.h:43