pd_alg_lrm.h

Go to the documentation of this file.
00001 /** @file pd_alg_lrm.h  functions related to LR machines*/
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_LRM_H
00012 #define FAUDES_PD_ALG_LRM_H
00013 
00014 #include "corefaudes.h"
00015 #include "pd_pdgenerator.h"
00016 #include "pd_parser.h"
00017 #include "pd_alg_first.h"
00018 #include "pd_gotogenerator.h"
00019 
00020 
00021 namespace faudes {
00022   
00023   /**
00024    * Obtain the immediate descendants of a configuration if the dot were pushed
00025    * one nonterminal further.
00026    * 
00027    * @param gr
00028    *    the grammar on which to work
00029    * @param k
00030    *    a natural number that denotes the kind of parser the function is working
00031    * on (LR(k) parser) (will currently only work for LR(1))
00032    * @param config
00033    *    the configuration whose descendants are to be obtained
00034    * @return
00035    *    set of all descendant parser configurations
00036    */
00037   std::set<Lr1Configuration> Desc11(const Grammar& gr, uint k, const Lr1Configuration& config);
00038   
00039   /**
00040    * Obtain the immediate descendants of configurations if the dot were pushed
00041    * one nonterminal further.
00042    * 
00043    * @param gr
00044    *    the grammar on which to work
00045    * @param k
00046    *    a natural number that denotes the kind of parser the function is working
00047    * on (LR(k) parser) (will currently only work for LR(1))
00048    * @param configs
00049    *    a set of configurations whose descendants are to be obtained
00050    * @return
00051    *    set of all immediate descendant parser configurations
00052    */
00053   std::set<Lr1Configuration> Desc1(const Grammar& gr, uint k, const std::set<Lr1Configuration>& configs);
00054   
00055   /**
00056    * Obtain all descendants of a configuration set.
00057    * 
00058    * @param gr
00059    *    the grammar on which to work
00060    * @param k
00061    *    a natural number that denotes the kind of parser the function is working
00062    * on (LR(k) parser) (will currently only work for LR(1))
00063    * @param config
00064    *    a set of configurations whose descendants are to be obtained
00065    * @return
00066    *    set of all descendant parser configurations
00067    */
00068   std::set<Lr1Configuration> Desc(const Grammar& gr, uint k, const std::set<Lr1Configuration>& config);
00069   
00070   /**
00071    * Try to shift the dot in a configuration over a specified symbol.
00072    * 
00073    * @param config
00074    *    the configuration
00075    * @param symbol
00076    *    the symbol over which to shift
00077    * @return
00078    *    set of size one that contains the new configuration or an empty set if the 
00079    * specified symbol was not found directly after the dot
00080    */
00081   std::set<Lr1Configuration> PassesX(const Lr1Configuration& config, const GrammarSymbolPtr& symbol);
00082   
00083   /**
00084    * Try to shift the dots in a configuration set over a specified symbol
00085    * 
00086    * @param configs
00087    *    the configurations
00088    * @param symbol
00089    *    the symbol over which to shift
00090    * @return
00091    *    set that contains all shifted configurations
00092    */
00093   std::set<Lr1Configuration> Basis(const std::set<Lr1Configuration> configs, const GrammarSymbolPtr& symbol);
00094   
00095   /**
00096    * Try to shift the dots in a configurations set and obtain the shifted
00097    * configuration set's descendants.
00098    * 
00099    * @param gr
00100    *    the grammar on which to work
00101    * @param k
00102    *    a natural number that denotes the kind of parser the function is working
00103    * on (LR(k) parser) (will currently only work for LR(1))
00104    * @param configs
00105    *    the configurations
00106    * @param symbol
00107    *    the symbol over which to shift
00108    * @return
00109    *    set containing the shifted configuration's descendant configurations
00110    */
00111   std::set<Lr1Configuration> GoTo(const Grammar& gr, uint k, const std::set<Lr1Configuration> configs, const GrammarSymbolPtr& symbol);
00112   
00113   /**
00114    * Generate outgoing transitions for an LR(k) machine for a given configuration set.
00115    * 
00116    * @param gr
00117    *    the grammar on which to work
00118    * @param k
00119    *     a natural number that denotes the kind of parser the function is working
00120    * on (LR(k) parser) (will currently only work for LR(1))
00121    * @param configs
00122    *    the configuration set from which to generate the transitions
00123    * @return
00124    *    outgoing transitions from the given configuration set as a map mapping 
00125    * the original configuration set and a grammar symbol to another configuration set
00126    */
00127   LrmTransitionMap Lrm1(const Grammar& gr, uint k, const Lr1ConfigurationSetSet& configSetSet);
00128   
00129   /**
00130    * Recursively generate all transitions and states for an LR(k) machine.
00131    * @param gr
00132    *    the grammar on which to work
00133    * @param k
00134    *     a natural number that denotes the kind of parser the function is working
00135    * on (LR(k) parser) (will currently only work for LR(1))
00136    * @param transitions
00137    *    the transitions that are already found
00138    * @param states
00139    *    the states that are already found
00140    * @param examineStates
00141    *    the states that need to be examined for outgoing transitions
00142    * @return
00143    *    a pair with the transition map and all states
00144    */
00145   std::pair<LrmTransitionMap,Lr1ConfigurationSetSet> LrmLoop(const Grammar& gr, uint k, const LrmTransitionMap& transitions, const Lr1ConfigurationSetSet& states, Lr1ConfigurationSetSet examineStates);
00146   
00147   /**
00148    * Determine the initial parser configurations for a grammar.
00149    * 
00150    * @param gr
00151    *    the grammar
00152    * @return
00153    *    a set with the initial configurations
00154    */
00155   std::set<Lr1Configuration> DescInitial(const Grammar& gr);
00156   
00157   /**
00158    * Determine the descendants of the initial parser configurations.
00159    * 
00160    * @param gr
00161    *    the grammar
00162    * @param k
00163    *    a natural number that denotes the kind of parser the function is working
00164    * on (LR(k) parser) (will currently only work for LR(1))
00165    * @return
00166    *    a set with the descendants of the initial configurations
00167    */
00168   std::set<Lr1Configuration> ValidEmpty(const Grammar& gr, uint k);
00169   
00170   /**
00171    * Generate an LR(k) machine for a grammar.
00172    * 
00173    * @param gr
00174    *    the grammar
00175    * @param k
00176    *    a natural number that denotes the kind of parser the function is working
00177    * on (LR(k) parser) (will currently only work for LR(1))
00178    * @return
00179    *    the LR(k) machine
00180    */
00181   GotoGenerator Lrm(const Grammar& gr, uint k);
00182   
00183   /**
00184    * Augments the grammar with a nonterminal S and  a terminal $ such that a new grammar
00185    * production  will be inserted. S is the new start symbol of the grammar
00186    * and S' is the old start symbol of the grammar
00187    * 
00188    * @param gr
00189    *    the grammar to be augmented
00190    * @param startSymbol
00191    *    the new start symbol S. S must not exist in the grammar
00192    * @param augSymbol
00193    *    the $ symbol which augments the grammar. $ must not exist in the grammar
00194    * @return
00195    *    augmented grammar with a new production S -> $ S' $
00196    */
00197   Grammar Aug(const Grammar& gr, const Nonterminal& startSymbol, const Terminal& augSymbol);
00198   
00199 
00200 } // namespace faudes
00201 
00202 #endif

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