pd_alg_first.hGo to the documentation of this file.00001 /** @file pd_alg_first.h functions related to the first function*/ 00002 00003 00004 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes) 00005 00006 Copyright (C) 2013 Stefan Jacobi, Sven Schneider, Anne-Kathrin Hess 00007 00008 */ 00009 00010 00011 #ifndef FAUDES_PD_ALG_FIRST_H 00012 #define FAUDES_PD_ALG_FIRST_H 00013 00014 #include "corefaudes.h" 00015 #include "pd_pdgenerator.h" 00016 #include "pd_alg_nb_sub_a.h" 00017 00018 00019 namespace faudes { 00020 00021 /** 00022 * Construct the postfix closure of a word. 00023 * 00024 * @param word 00025 * the word 00026 * @return 00027 * all postfixes of the word including lambda 00028 */ 00029 GrammarSymbolWordSet PostCl(const GrammarSymbolVector& word); 00030 00031 /** 00032 * Determine certain words in a grammar. The words are all lefthand sides and 00033 * all righthand sides as well as the righthand sides' postfixes 00034 * 00035 * @param gr 00036 * the grammar 00037 * @return 00038 * all lefthand sides and all righthand sides' postfixes as words 00039 */ 00040 GrammarSymbolWordSet Fds(const Grammar& gr); 00041 00042 /** 00043 * Updates the function which maps words to their first possible terminal symbols. Must 00044 * be called until no changes are made in order to have a complete mapping. 00045 * 00046 * @param gr 00047 * the grammar on which to work 00048 * @param f 00049 * the mapping function (word -> first symbols) 00050 * @param madeChanges 00051 * this variable will be written to true if changes were made and written to 00052 * false if no changes were made 00053 * @return 00054 * the updated first function 00055 */ 00056 GrammarSymbolWordMap First1(const Grammar& gr, const GrammarSymbolWordMap& f, bool* madeChanges); 00057 00058 /** 00059 * Builds a function that maps words to their first possible terminal 00060 * symbols by recursively calling First1. 00061 * 00062 * @param gr 00063 * the grammar on which to work 00064 * @param f 00065 * the mapping function (word -> first symbols) 00066 * @return 00067 * the first function 00068 */ 00069 GrammarSymbolWordMap FirstL(const Grammar& gr, const GrammarSymbolWordMap& f); 00070 00071 /** 00072 * Determines which terminals can come first for a given word. The word must be 00073 * in Fds()! 00074 * 00075 * @param gr 00076 * the grammar on which to work 00077 * @param word 00078 * the word whose first terminals are to be determined 00079 * @return 00080 * set of first terminals 00081 */ 00082 std::set<Terminal> FirstA(const Grammar& gr, const GrammarSymbolVector& word); 00083 00084 /** 00085 * Determines which terminals can come first for a given word. 00086 * 00087 * @param gr 00088 * the grammar on which to work 00089 * @param word 00090 * the word whose first terminals are to be determined 00091 * @return 00092 * set of first terminals 00093 */ 00094 std::set<Terminal> First(const Grammar& gr, const GrammarSymbolVector& word); 00095 00096 /** 00097 * Calls first, but only if all symbols in the word are in the grammar as well. 00098 * 00099 * @param gr 00100 * the grammar 00101 * @param word 00102 * the word 00103 * @return 00104 * set of first terminals or empty set if the word contained symbols not in 00105 * the grammar 00106 */ 00107 std::set<Terminal> FirstRed(const Grammar& gr, const GrammarSymbolVector& word); 00108 00109 /** 00110 * Extract the first symbol from the word that is in the symbol set 00111 * 00112 * @param symbolSet 00113 * the symbol set 00114 * @param w 00115 * the word 00116 * @return 00117 * pointer to the found symbol or NULL if none is found 00118 */ 00119 NonterminalPtr Filter1(const std::set<Nonterminal>& symbolSet, const GrammarSymbolVector& w); 00120 00121 /** 00122 * Determines which terminals can come first for a given word and ensures that 00123 * the word can be entirely reduced. 00124 * 00125 * @param gr 00126 * the grammar on which to work 00127 * @param word 00128 * the word whose first terminals are to be determined 00129 * @return 00130 * set of first terminals or empty set, if the word cannot be entirely reduced 00131 */ 00132 std::set<Terminal> FirstAll(const Grammar& gr, const GrammarSymbolVector& word); 00133 00134 /** 00135 * Determine which terminals can come first for a given word for any k <= 1. 00136 * 00137 * @param gr 00138 * the grammar on which to work 00139 * @param k 00140 * a natural number k 00141 * @param word 00142 * the word whose first terminals are to be determined 00143 * @return 00144 * for k = 1 and k = 0: set of first terminals 00145 * for k = 0 and set of first terminals not empty: lambda 00146 * for k > 1: empty set 00147 */ 00148 std::set<Terminal> FirstLeq1(const Grammar& gr, uint k, const GrammarSymbolVector& word); 00149 00150 /** 00151 * Convenience print function for first map function 00152 * 00153 * @param f 00154 * map function to print 00155 * @param changed 00156 * indicator if changes were made, defaults to false 00157 */ 00158 void WriteMap(GrammarSymbolWordMap f, bool changed = false); 00159 00160 00161 } // namespace faudes 00162 00163 #endif libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |