About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES
C++ API
Sections
Sets
Generators
Functions
PlugIns
Tutorials
Index
Classes
Files
pd_blockfree_test.cpp
Go to the documentation of this file.
1
/** @file pd_blockfree_test.cpp
2
3
This file tests the blockfree algorithm.
4
5
6
@ingroup Tutorials
7
8
@include pd_blockfree_test.cpp
9
10
*/
11
12
#include "
libfaudes.h
"
13
14
// make the faudes namespace available to our program
15
using namespace
faudes;
16
17
/**
18
* Tests the algorithm to ensure non blocking.
19
* In this case the algorithm is adapted to the given pushdown generator (pd_blocked)
20
* General algorithm see PushdownBlockfree() in file pd_alg_main.cpp
21
*/
22
PushdownGenerator
make_blockfree
(
const
PushdownGenerator
& pd){
23
24
//take a copy of the old generator
25
PushdownGenerator
rPd(pd);
26
27
//create SDPDA
28
rPd =
SPDA
(rPd);
29
FAUDES_TEST_DUMP
(
"Spda"
, rPd)
30
31
//remove double acceptance
32
rPd =
Nda
(rPd);
33
PushdownTrim
(rPd,0);
34
FAUDES_TEST_DUMP
(
"Nda"
, rPd)
35
36
//convert to grammar
37
Grammar
gr =
Sp2Lr
(rPd);
38
FAUDES_TEST_DUMP
(
"CFG has 12 productions"
, (gr.
GrammarProductions
().size() == 12))
39
40
//remove unreachable productions
41
gr =
Rup
(gr);
42
FAUDES_TEST_DUMP
(
"9 productions after Rup"
, (gr.
GrammarProductions
().size() == 9))
43
44
//augment grammar
45
//create temporary automaton to create a new event for the augment terminal
46
//and a new stack symbol for the augment nonterminal
47
PushdownGenerator
tempPd = rPd;
48
49
//create fresh terminal
50
Terminal
t(tempPd.
InsEvent
(
"augSymbol"
));
51
52
std::vector<Idx> v;
53
v.push_back(tempPd.
InsStackSymbol
(
StackSymbol
(
"augSymbol"
)));
54
Nonterminal
nt(0, v);
55
56
//Augments the grammar such that a new grammar production will be inserted
57
Grammar
augGr =
Aug
(gr, nt, t);
58
59
//construct the goto generator for the augmented grammar
60
GotoGenerator
gotoGen =
Lrm
(augGr, 1);
61
FAUDES_TEST_DUMP
(
"goto generator"
, gotoGen)
62
63
//construct a parser for the grammar
64
Lr1Parser
parser =
Lrp
(gr, augGr, gotoGen, 1, t);
65
FAUDES_TEST_DUMP
(
"Lr(1)-Parser has 13 actions"
, (parser.
Actions
().size() == 13))
66
67
//detach augment symbol
68
DetachAugSymbol
(parser);
69
70
// Transform actions
71
parser =
TransformParserAction
(parser);
72
FAUDES_TEST_DUMP
(
"12 actions after transform"
, (parser.
mActions
.size() == 12))
73
74
//convert parser to pushdown generator
75
rPd =
LrParser2EPDA
(parser);
76
FAUDES_TEST_DUMP
(
"Epda"
, rPd)
77
78
//merge adjacent transitions
79
MergeAdjacentTransitions
(rPd);
80
FAUDES_TEST_DUMP
(
"Merge adjacent transitions"
, rPd)
81
82
//removes transitions that pop lambda
83
rPd =
RemoveLambdaPop
(rPd);
84
FAUDES_TEST_DUMP
(
"No lambda pop"
, rPd)
85
86
//remove transitions popping more then one symbol
87
rPd =
RemoveMultPop
(rPd);
88
FAUDES_TEST_DUMP
(
"No multiple pop"
, rPd)
89
90
//removes transitions that pop lambda
91
rPd =
RemoveLambdaPop
(rPd);
92
FAUDES_TEST_DUMP
(
"Pda"
, rPd)
93
94
PushdownTrim
(rPd,2);
95
FAUDES_TEST_DUMP
(
"Pda trim with 2 as lookahead"
, rPd)
96
97
//merge adjacent transitions
98
MergeAdjacentTransitions
(rPd);
99
FAUDES_TEST_DUMP
(
"Merge adjacent transitions again"
, rPd)
100
101
PushdownTrim
(rPd,0);
102
103
return
rPd;
104
}
105
106
/** Run the blockfree test */
107
int
main
() {
108
109
//*******************************
110
//Get pushdown generator from DOT-file
111
//The generator can be seen in data/graph/pd_blockfree_test.png
112
//State 's3' will lead to a blocking issue
113
//*******************************
114
PushdownGenerator
pd(
"data/graph/pd_blockfree_test.dot"
);
115
116
117
//*******************************
118
//create blockfree generator
119
//*******************************
120
PushdownGenerator
pd_blockfree =
make_blockfree
(pd);
121
122
123
//*******************************
124
// Record test case
125
//*******************************
126
127
FAUDES_TEST_DUMP
(
"blocked pushdown generator"
, pd)
128
FAUDES_TEST_DUMP
(
"blockfree pushdown generator"
, pd_blockfree)
129
130
// Validate result
131
FAUDES_TEST_DIFF
()
132
133
// done
134
return
0;
135
}
136
libFAUDES 2.26g
--- 2015.08.17 --- c++ api documentaion by
doxygen
>>
C++ API
Introduction
Sets
Generators
Functions
PlugIns
Tutorials
Classes
Files
Top of Page