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

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