Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
11
ParseTable
::ParseTable (QTextStream &o):
12
out (o)
13
{
14
}
15
16
void
ParseTable
::
operator
() (
Automaton
*aut)
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
}
Automaton
Definition
lalr.h:311
Automaton::_M_grammar
Grammar * _M_grammar
Definition
lalr.h:352
Automaton::states
StateList states
Definition
lalr.h:353
Grammar
Definition
lalr.h:215
Grammar::rules
debug_infot rules
Definition
lalr.h:242
Grammar::isNonTerminal
bool isNonTerminal(Name name) const
Definition
lalr.h:225
Grammar::isTerminal
bool isTerminal(Name name) const
Definition
lalr.h:222
ParseTable
Definition
parsetable.h:13
ParseTable::operator()
void operator()(Automaton *a)
Definition
parsetable.cpp:16
ItemPointer
ItemList::iterator ItemPointer
Definition
lalr.h:34
StatePointer
StateList::iterator StatePointer
Definition
lalr.h:43
qtbase
src
tools
qlalr
parsetable.cpp
Generated on
for Qt by
1.18.0