pd_alg_lrp.h

Go to the documentation of this file.
00001 /** @file pd_alg_lrp.h  functions related to parsers*/
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 #ifndef FAUDES_PD_ALG_LRP_H
00011 #define FAUDES_PD_ALG_LRP_H
00012 
00013 #include "corefaudes.h"
00014 #include "pd_gotogenerator.h"
00015 #include "pd_parser.h"
00016 #include "pd_grammar.h"
00017 #include "pd_alg_first.h"
00018  
00019 namespace faudes {
00020 
00021 /**
00022  * Find the successor states of a state for a given input symbol.
00023  * 
00024  * @param gotoGen
00025  *      the generator on which to work
00026  * @param state
00027  *      the state of which to find the successor state
00028  * @param symbol
00029  *      the input symbol
00030  * @return
00031  *      A set with the successor states. The set size is 1 if a successor state
00032  * is found. Set size is 0 if no successor state is found.
00033  */
00034 std::set<Idx> GeneratorGoto(const GotoGenerator& gotoGen, Idx state, const GrammarSymbolPtr& symbol);
00035 
00036 /**
00037  * Find the successor state sequence of a state for a given input word. If the word
00038  * cannot be completely matched to a state sequence, the state sequence will be
00039  * partially matched (i. e., it will be as long as the part of the word that can be
00040  * matched).
00041  * 
00042  * @param gotoGen
00043  *      the generator on which to work
00044  * @param state
00045  *      the state of which to find the successor state
00046  * @param word
00047  *      the input word
00048  * @return
00049  *      A set with the successor states. The set size will be anywhere between 0 and 
00050  * the length of the word.
00051  */
00052 std::vector<Idx> GeneratorGotoSeq(const GotoGenerator& gotoGen, Idx startState, const GrammarSymbolVector& word);
00053 
00054 /**
00055  * construct the parsing rules for shifting from a grammar and its LR(k) machine
00056  * 
00057  * @param gr
00058  *      the grammar on which to work
00059  * @param augGr
00060  *      augmented version of the grammar on which to work
00061  * @param gotoGen
00062  *      LR(k) machine of the grammar
00063  * @param k
00064  *      a natural number that denotes the kind of parser the function is working
00065  * on (LR(k) parser) (will currently only work for LR(1))
00066  * @return
00067  *      set of shift actions
00068  */
00069 std::set<Lr1ParserAction> LrpShiftRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
00070 
00071 /**
00072  * construct the parsing rules for reducing from a grammar and its LR(k) machine
00073  * 
00074  * @param gr
00075  *      the grammar on which to work
00076  * @param augGr
00077  *      augmented version of the grammar on which to work
00078  * @param gotoGen
00079  *      LR(k) machine of the grammar
00080  * @param k
00081  *      a natural number that denotes the kind of parser the function is working
00082  * on (LR(k) parser) (will currently only work for LR(1))
00083  * @return
00084  *      set of reduce actions
00085  */
00086 std::set<Lr1ParserAction> LrpReduceRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
00087 
00088 /**
00089  * construct all parsing rules from a grammar and its LR(k) machine
00090  * 
00091  * @param gr
00092  *      the grammar on which to work
00093  * @param augGr
00094  *      augmented version of the grammar on which to work
00095  * @param gotoGen
00096  *      LR(k) machine of the grammar
00097  * @param k
00098  *      a natural number that denotes the kind of parser the function is working
00099  * on (LR(k) parser) (will currently only work for LR(1))
00100  * @return
00101  *      set of parsing rules
00102  */
00103 std::set<Lr1ParserAction> LrpRules(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k);
00104 
00105 /**
00106  * construct an LR(k) parser from a grammar and its LR(k) machine
00107  * 
00108  * @param gr
00109  *      the grammar on which to work
00110  * @param augGr
00111  *      augmented version of the grammar on which to work
00112  * @param gotoGen
00113  *      LR(k) machine of the grammar
00114  * @param k
00115  *      a natural number that denotes the kind of parser the function is working
00116  * on (LR(k) parser) (will currently only work for LR(1))
00117  * @param augSymbol
00118  *      the terminal with which the grammar was augmented to create the augmented
00119  * grammar
00120  * @return
00121  *      set of parsing rules
00122  */
00123 Lr1Parser Lrp(const Grammar& gr, const Grammar& augGr, const GotoGenerator& gotoGen, uint k, const Terminal& augSymbol);
00124 
00125 /**
00126  * Converts a parser into a pushdown generator. The stack symbols will be the parser's
00127  * nonterminals
00128  * 
00129  * @param gotoGen
00130  *      Lr(k) machine of the grammar that the parser parses
00131  * @param parser
00132  *      the parser to convert
00133  * @return
00134  *      the parser as a pushdown generator
00135  */
00136 PushdownGenerator Gp2Pp(const GotoGenerator& gotoGen, const Lr1Parser& parser);
00137 
00138 /**
00139  * Remove the augmentation from the generator (diminish it). This will remove all
00140  * transitions whose event is the augment symbol and make those transitions start
00141  * states final. It will also remove the augment symbol as an event.
00142  * 
00143  * @param pd
00144  *      generator to diminish
00145  * @param augSymbol
00146  *      the symbol with wich the grammar that was used to create the generator
00147  * was augmented
00148  * @return
00149  *      diminished generator
00150  */
00151 PushdownGenerator Dim(const PushdownGenerator& pd, const Terminal& augSymbol);
00152 
00153 
00154 
00155 } // namespace faudes
00156 
00157 #endif

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen