pd_alg_first.h
Go to the documentation of this file.
1 /** @file pd_alg_first.h functions related to the first function*/
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_FIRST_H
12 #define FAUDES_PD_ALG_FIRST_H
13 
14 #include "corefaudes.h"
15 #include "pd_pdgenerator.h"
16 #include "pd_alg_sub.h"
17 
18 namespace faudes {
19 
20  /**
21  * Construct the postfix closure of a word.
22  *
23  * @param word
24  * the word
25  * @return
26  * all postfixes of the word including lambda
27  */
29 
30  /**
31  * Determine certain words in a grammar. The words are all lefthand sides and
32  * all righthand sides as well as the righthand sides' postfixes
33  *
34  * @param gr
35  * the grammar
36  * @return
37  * all lefthand sides and all righthand sides' postfixes as words
38  */
39  GrammarSymbolWordSet Fds(const Grammar& gr);
40 
41  /**
42  * Updates the function which maps words to their first possible terminal symbols. Must
43  * be called until no changes are made in order to have a complete mapping.
44  *
45  * @param gr
46  * the grammar on which to work
47  * @param f
48  * the mapping function (word -> first symbols)
49  * @param madeChanges
50  * this variable will be written to true if changes were made and written to
51  * false if no changes were made
52  * @return
53  * the updated first function
54  */
55  GrammarSymbolWordMap First1(const Grammar& gr, const GrammarSymbolWordMap& f, bool* madeChanges);
56 
57  /**
58  * Builds a function that maps words to their first possible terminal
59  * symbols by recursively calling First1.
60  *
61  * @param gr
62  * the grammar on which to work
63  * @param f
64  * the mapping function (word -> first symbols)
65  * @return
66  * the first function
67  */
68  GrammarSymbolWordMap FirstL(const Grammar& gr, const GrammarSymbolWordMap& f);
69 
70  /**
71  * Determines which terminals can come first for a given word. The word must be
72  * in Fds()!
73  *
74  * @param gr
75  * the grammar on which to work
76  * @param word
77  * the word whose first terminals are to be determined
78  * @return
79  * set of first terminals
80  */
81  std::set<Terminal> FirstA(const Grammar& gr, const GrammarSymbolVector& word);
82 
83  /**
84  * Determines which terminals can come first for a given word.
85  *
86  * @param gr
87  * the grammar on which to work
88  * @param word
89  * the word whose first terminals are to be determined
90  * @return
91  * set of first terminals
92  */
93  std::set<Terminal> First(const Grammar& gr, const GrammarSymbolVector& word);
94 
95  /**
96  * Calls first, but only if all symbols in the word are in the grammar as well.
97  *
98  * @param gr
99  * the grammar
100  * @param word
101  * the word
102  * @return
103  * set of first terminals or empty set if the word contained symbols not in
104  * the grammar
105  */
106  std::set<Terminal> FirstRed(const Grammar& gr, const GrammarSymbolVector& word);
107 
108  /**
109  * Extract the first symbol from the word that is in the symbol set
110  *
111  * @param symbolSet
112  * the symbol set
113  * @param w
114  * the word
115  * @return
116  * pointer to the found symbol or NULL if none is found
117  */
118  NonterminalPtr Filter1(const std::set<Nonterminal>& symbolSet, const GrammarSymbolVector& w);
119 
120  /**
121  * Determines which terminals can come first for a given word and ensures that
122  * the word can be entirely reduced.
123  *
124  * @param gr
125  * the grammar on which to work
126  * @param word
127  * the word whose first terminals are to be determined
128  * @return
129  * set of first terminals or empty set, if the word cannot be entirely reduced
130  */
131  std::set<Terminal> FirstAll(const Grammar& gr, const GrammarSymbolVector& word);
132 
133  /**
134  * Determine which terminals can come first for a given word for any k <= 1.
135  *
136  * @param gr
137  * the grammar on which to work
138  * @param k
139  * a natural number k
140  * @param word
141  * the word whose first terminals are to be determined
142  * @return
143  * for k = 1 and k = 0: set of first terminals
144  * for k = 0 and set of first terminals not empty: lambda
145  * for k > 1: empty set
146  */
147  std::set<Terminal> FirstLeq1(const Grammar& gr, uint k, const GrammarSymbolVector& word);
148 
149  /**
150  * Convenience print function for first map function
151  *
152  * @param f
153  * map function to print
154  * @param changed
155  * indicator if changes were made, defaults to false
156  */
157  void WriteMap(GrammarSymbolWordMap f, bool changed = false);
158 
159 
160 } // namespace faudes
161 
162 #endif

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