pd_alg_lrm.h
Go to the documentation of this file.
1 /** @file pd_alg_lrm.h functions related to LR machines*/
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 
11 #ifndef FAUDES_PD_ALG_LRM_H
12 #define FAUDES_PD_ALG_LRM_H
13 
14 #include "corefaudes.h"
15 #include "pd_pdgenerator.h"
16 #include "pd_parser.h"
17 #include "pd_alg_first.h"
18 #include "pd_gotogenerator.h"
19 
20 
21 namespace faudes {
22 
23  /**
24  * Obtain the immediate descendants of a configuration if the dot were pushed
25  * one nonterminal further.
26  *
27  * @param gr
28  * the grammar on which to work
29  * @param k
30  * a natural number that denotes the kind of parser the function is working
31  * on (LR(k) parser) (will currently only work for LR(1))
32  * @param config
33  * the configuration whose descendants are to be obtained
34  * @return
35  * set of all descendant parser configurations
36  */
37  std::set<Lr1Configuration> Desc11(const Grammar& gr, uint k, const Lr1Configuration& config);
38 
39  /**
40  * Obtain the immediate descendants of configurations if the dot were pushed
41  * one nonterminal further.
42  *
43  * @param gr
44  * the grammar on which to work
45  * @param k
46  * a natural number that denotes the kind of parser the function is working
47  * on (LR(k) parser) (will currently only work for LR(1))
48  * @param configs
49  * a set of configurations whose descendants are to be obtained
50  * @return
51  * set of all immediate descendant parser configurations
52  */
53  std::set<Lr1Configuration> Desc1(const Grammar& gr, uint k, const std::set<Lr1Configuration>& configs);
54 
55  /**
56  * Obtain all descendants of a configuration set.
57  *
58  * @param gr
59  * the grammar on which to work
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  * @param config
64  * a set of configurations whose descendants are to be obtained
65  * @return
66  * set of all descendant parser configurations
67  */
68  std::set<Lr1Configuration> Desc(const Grammar& gr, uint k, const std::set<Lr1Configuration>& config);
69 
70  /**
71  * Try to shift the dot in a configuration over a specified symbol.
72  *
73  * @param config
74  * the configuration
75  * @param symbol
76  * the symbol over which to shift
77  * @return
78  * set of size one that contains the new configuration or an empty set if the
79  * specified symbol was not found directly after the dot
80  */
81  std::set<Lr1Configuration> PassesX(const Lr1Configuration& config, const GrammarSymbolPtr& symbol);
82 
83  /**
84  * Try to shift the dots in a configuration set over a specified symbol
85  *
86  * @param configs
87  * the configurations
88  * @param symbol
89  * the symbol over which to shift
90  * @return
91  * set that contains all shifted configurations
92  */
93  std::set<Lr1Configuration> Basis(const std::set<Lr1Configuration> configs, const GrammarSymbolPtr& symbol);
94 
95  /**
96  * Try to shift the dots in a configurations set and obtain the shifted
97  * configuration set's descendants.
98  *
99  * @param gr
100  * the grammar on which to work
101  * @param k
102  * a natural number that denotes the kind of parser the function is working
103  * on (LR(k) parser) (will currently only work for LR(1))
104  * @param configs
105  * the configurations
106  * @param symbol
107  * the symbol over which to shift
108  * @return
109  * set containing the shifted configuration's descendant configurations
110  */
111  std::set<Lr1Configuration> GoTo(const Grammar& gr, uint k, const std::set<Lr1Configuration> configs, const GrammarSymbolPtr& symbol);
112 
113  /**
114  * Generate outgoing transitions for an LR(k) machine for a given configuration set.
115  *
116  * @param gr
117  * the grammar on which to work
118  * @param k
119  * a natural number that denotes the kind of parser the function is working
120  * on (LR(k) parser) (will currently only work for LR(1))
121  * @param configs
122  * the configuration set from which to generate the transitions
123  * @return
124  * outgoing transitions from the given configuration set as a map mapping
125  * the original configuration set and a grammar symbol to another configuration set
126  */
127  LrmTransitionMap Lrm1(const Grammar& gr, uint k, const Lr1ConfigurationSetSet& configSetSet);
128 
129  /**
130  * Recursively generate all transitions and states for an LR(k) machine.
131  * @param gr
132  * the grammar on which to work
133  * @param k
134  * a natural number that denotes the kind of parser the function is working
135  * on (LR(k) parser) (will currently only work for LR(1))
136  * @param transitions
137  * the transitions that are already found
138  * @param states
139  * the states that are already found
140  * @param examineStates
141  * the states that need to be examined for outgoing transitions
142  * @return
143  * a pair with the transition map and all states
144  */
145  std::pair<LrmTransitionMap,Lr1ConfigurationSetSet> LrmLoop(const Grammar& gr, uint k, const LrmTransitionMap& transitions, const Lr1ConfigurationSetSet& states, Lr1ConfigurationSetSet examineStates);
146 
147  /**
148  * Determine the initial parser configurations for a grammar.
149  *
150  * @param gr
151  * the grammar
152  * @return
153  * a set with the initial configurations
154  */
155  std::set<Lr1Configuration> DescInitial(const Grammar& gr);
156 
157  /**
158  * Determine the descendants of the initial parser configurations.
159  *
160  * @param gr
161  * the grammar
162  * @param k
163  * a natural number that denotes the kind of parser the function is working
164  * on (LR(k) parser) (will currently only work for LR(1))
165  * @return
166  * a set with the descendants of the initial configurations
167  */
168  std::set<Lr1Configuration> ValidEmpty(const Grammar& gr, uint k);
169 
170  /**
171  * Generate an LR(k) machine for a grammar.
172  *
173  * @param gr
174  * the grammar
175  * @param k
176  * a natural number that denotes the kind of parser the function is working
177  * on (LR(k) parser) (will currently only work for LR(1))
178  * @return
179  * the LR(k) machine
180  */
181  GotoGenerator Lrm(const Grammar& gr, uint k);
182 
183  /**
184  * Augments the grammar with a nonterminal S and a terminal $ such that a new grammar
185  * production will be inserted. S is the new start symbol of the grammar
186  * and S' is the old start symbol of the grammar
187  *
188  * @param gr
189  * the grammar to be augmented
190  * @param startSymbol
191  * the new start symbol S. S must not exist in the grammar
192  * @param augSymbol
193  * the $ symbol which augments the grammar. $ must not exist in the grammar
194  * @return
195  * augmented grammar with a new production S -> $ S' $
196  */
197  Grammar Aug(const Grammar& gr, const Nonterminal& startSymbol, const Terminal& augSymbol);
198 
199 
200 } // namespace faudes
201 
202 #endif

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