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

libFAUDES 2.28c --- 2016.09.30 --- c++ api documentaion by doxygen