pd_alg_lrp.h
Go to the documentation of this file.
1 /** @file pd_alg_lrp.h functions related to parsers*/
2 
3 
4 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2013/14 Stefan Jacobi, Ramon Barakat, Sven Schneider, Anne-Kathrin Hess
7 
8 */
9 
10 #ifndef FAUDES_PD_ALG_LRP_H
11 #define FAUDES_PD_ALG_LRP_H
12 
13 #include "corefaudes.h"
14 #include "pd_include.h"
15 
16 namespace faudes {
17 
18 /**
19  * Find the successor states of a state for a given input symbol.
20  *
21  * @param gotoGen
22  * the generator on which to work
23  * @param state
24  * the state of which to find the successor state
25  * @param symbol
26  * the input symbol
27  * @return
28  * A set with the successor states. The set size is 1 if a successor state
29  * is found. Set size is 0 if no successor state is found.
30  */
31 std::set<Idx> GeneratorGoto(const GotoGenerator& gotoGen, Idx state, const GrammarSymbolPtr& symbol);
32 
33 /**
34  * Find the successor state sequence of a state for a given input word. If the word
35  * cannot be completely matched to a state sequence, the state sequence will be
36  * partially matched (i. e., it will be as long as the part of the word that can be
37  * matched).
38  *
39  * @param gotoGen
40  * the generator on which to work
41  * @param state
42  * the state of which to find the successor state
43  * @param word
44  * the input word
45  * @return
46  * A set with the successor states. The set size will be anywhere between 0 and
47  * the length of the word.
48  */
49 std::vector<Idx> GeneratorGotoSeq(const GotoGenerator& gotoGen, Idx startState, const GrammarSymbolVector& word);
50 
51 /**
52  * construct the parsing rules for shifting from a grammar and its LR(k) machine
53  *
54  * @param gr
55  * the grammar on which to work
56  * @param augGr
57  * augmented version of the grammar on which to work
58  * @param gotoGen
59  * LR(k) machine of the grammar
60  * @param k
61  * a natural number that denotes the kind of parser the function is working
62  * on (LR(k) parser) (will currently only work for LR(1))
63  * @return
64  * set of shift actions
65  */
66 std::set<Lr1ParserAction> LrpShiftRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
67 
68 /**
69  * construct the parsing rules for reducing from a grammar and its LR(k) machine
70  *
71  * @param gr
72  * the grammar on which to work
73  * @param augGr
74  * augmented version of the grammar on which to work
75  * @param gotoGen
76  * LR(k) machine of the grammar
77  * @param k
78  * a natural number that denotes the kind of parser the function is working
79  * on (LR(k) parser) (will currently only work for LR(1))
80  * @return
81  * set of reduce actions
82  */
83 std::set<Lr1ParserAction> LrpReduceRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
84 
85 /**
86  * construct all parsing rules from a grammar and its LR(k) machine
87  *
88  * @param gr
89  * the grammar on which to work
90  * @param augGr
91  * augmented version of the grammar on which to work
92  * @param gotoGen
93  * LR(k) machine of the grammar
94  * @param k
95  * a natural number that denotes the kind of parser the function is working
96  * on (LR(k) parser) (will currently only work for LR(1))
97  * @return
98  * set of parsing rules
99  */
100 std::set<Lr1ParserAction> LrpRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
101 
102 /**
103  * construct an LR(k) parser from a grammar and its LR(k) machine
104  *
105  * @param gr
106  * the grammar on which to work
107  * @param augGr
108  * augmented version of the grammar on which to work
109  * @param gotoGen
110  * LR(k) machine of the grammar
111  * @param k
112  * a natural number that denotes the kind of parser the function is working
113  * on (LR(k) parser) (will currently only work for LR(1))
114  * @param augSymbol
115  * the terminal with which the grammar was augmented to create the augmented
116  * grammar
117  * @return
118  * set of parsing rules
119  */
120 Lr1Parser Lrp(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k, const Terminal& augSymbol);
121 
122 /**
123  * Detach augmented symbole from Lr(1)-parser
124  *
125  * @param rParser
126  * reference to Lr(1)-parser
127  *
128  * @return
129  */
130 void DetachAugSymbol(Lr1Parser& rParser);
131 
132 /**
133  *
134  * Transform action of Lr(1)-parser as follows
135  * actions of the form (q,a,p,a) to ((q,lambda),a,(p,a),lambda), ((q,a),lambda,(p,a),lambda)
136  * actions of the form (q,a,p,lambda) to ((q,lambda),a,(p,lambda),lambda) , ((q,a),lambda,(p,lambda),lambda)
137  *
138  * @param rParser
139  * reference to Lr(1)-parser
140  *
141  * @return
142  * Lr(1)-parser with transformed actions
143  */
144 Lr1Parser TransformParserAction(const Lr1Parser& rParser);
145 
146 /*
147  * Transform a Lr(1)-parser to a pushdown generator.
148  *
149  * @param rParser
150  * reference to LR1-parser
151  *
152  * @return
153  * pushdown generator with same marked language as given parser
154  */
155 PushdownGenerator LrParser2EPDA(const Lr1Parser& rParser);
156 
157 
158 
159 } // namespace faudes
160 
161 #endif

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen