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 Stefan Jacobi, 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_gotogenerator.h"
15 #include "pd_parser.h"
16 #include "pd_grammar.h"
17 #include "pd_alg_first.h"
18 
19 namespace faudes {
20 
21 /**
22  * Find the successor states of a state for a given input symbol.
23  *
24  * @param gotoGen
25  * the generator on which to work
26  * @param state
27  * the state of which to find the successor state
28  * @param symbol
29  * the input symbol
30  * @return
31  * A set with the successor states. The set size is 1 if a successor state
32  * is found. Set size is 0 if no successor state is found.
33  */
34 std::set<Idx> GeneratorGoto(const GotoGenerator& gotoGen, Idx state, const GrammarSymbolPtr& symbol);
35 
36 /**
37  * Find the successor state sequence of a state for a given input word. If the word
38  * cannot be completely matched to a state sequence, the state sequence will be
39  * partially matched (i. e., it will be as long as the part of the word that can be
40  * matched).
41  *
42  * @param gotoGen
43  * the generator on which to work
44  * @param state
45  * the state of which to find the successor state
46  * @param word
47  * the input word
48  * @return
49  * A set with the successor states. The set size will be anywhere between 0 and
50  * the length of the word.
51  */
52 std::vector<Idx> GeneratorGotoSeq(const GotoGenerator& gotoGen, Idx startState, const GrammarSymbolVector& word);
53 
54 /**
55  * construct the parsing rules for shifting from a grammar and its LR(k) machine
56  *
57  * @param gr
58  * the grammar on which to work
59  * @param augGr
60  * augmented version of the grammar on which to work
61  * @param gotoGen
62  * LR(k) machine of the grammar
63  * @param k
64  * a natural number that denotes the kind of parser the function is working
65  * on (LR(k) parser) (will currently only work for LR(1))
66  * @return
67  * set of shift actions
68  */
69 std::set<Lr1ParserAction> LrpShiftRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
70 
71 /**
72  * construct the parsing rules for reducing from a grammar and its LR(k) machine
73  *
74  * @param gr
75  * the grammar on which to work
76  * @param augGr
77  * augmented version of the grammar on which to work
78  * @param gotoGen
79  * LR(k) machine of the grammar
80  * @param k
81  * a natural number that denotes the kind of parser the function is working
82  * on (LR(k) parser) (will currently only work for LR(1))
83  * @return
84  * set of reduce actions
85  */
86 std::set<Lr1ParserAction> LrpReduceRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
87 
88 /**
89  * construct all parsing rules from a grammar and its LR(k) machine
90  *
91  * @param gr
92  * the grammar on which to work
93  * @param augGr
94  * augmented version of the grammar on which to work
95  * @param gotoGen
96  * LR(k) machine of the grammar
97  * @param k
98  * a natural number that denotes the kind of parser the function is working
99  * on (LR(k) parser) (will currently only work for LR(1))
100  * @return
101  * set of parsing rules
102  */
103 std::set<Lr1ParserAction> LrpRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
104 
105 /**
106  * construct an LR(k) parser from a grammar and its LR(k) machine
107  *
108  * @param gr
109  * the grammar on which to work
110  * @param augGr
111  * augmented version of the grammar on which to work
112  * @param gotoGen
113  * LR(k) machine of the grammar
114  * @param k
115  * a natural number that denotes the kind of parser the function is working
116  * on (LR(k) parser) (will currently only work for LR(1))
117  * @param augSymbol
118  * the terminal with which the grammar was augmented to create the augmented
119  * grammar
120  * @return
121  * set of parsing rules
122  */
123 Lr1Parser Lrp(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k, const Terminal& augSymbol);
124 
125 /**
126  * Converts a parser into a pushdown generator. The stack symbols will be the parser's
127  * nonterminals
128  *
129  * @param gotoGen
130  * Lr(k) machine of the grammar that the parser parses
131  * @param parser
132  * the parser to convert
133  * @return
134  * the parser as a pushdown generator
135  */
136 PushdownGenerator Gp2Pp(const GotoGenerator& gotoGen, const Lr1Parser& parser);
137 
138 /**
139  * Remove the augmentation from the generator (diminish it). This will remove all
140  * transitions whose event is the augment symbol and make those transitions start
141  * states final. It will also remove the augment symbol as an event.
142  *
143  * @param pd
144  * generator to diminish
145  * @param augSymbol
146  * the symbol with wich the grammar that was used to create the generator
147  * was augmented
148  * @return
149  * diminished generator
150  */
151 PushdownGenerator Dim(const PushdownGenerator& pd, const Terminal& augSymbol);
152 
153 
154 
155 } // namespace faudes
156 
157 #endif

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen