Orocos Real-Time Toolkit
2.6.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Thu Apr 22 20:40:59 CEST 2004 StateGraphParser.hpp 00003 00004 StateGraphParser.hpp - description 00005 ------------------- 00006 begin : Thu April 22 2004 00007 copyright : (C) 2004 Peter Soetens 00008 email : peter.soetens@mech.kuleuven.ac.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 00038 #ifndef EXECUTION_STATE_PARSER_HPP 00039 #define EXECUTION_STATE_PARSER_HPP 00040 00041 #include "parser-types.hpp" 00042 00043 #include <map> 00044 #include <string> 00045 #include <boost/function.hpp> 00046 #include <boost/shared_ptr.hpp> 00047 #include "../internal/DataSource.hpp" 00048 namespace RTT { namespace scripting 00049 { 00050 00061 class StateGraphParser 00062 { 00063 // Our task we are parsing in : 00064 TaskContext* context; 00065 // The task that will execute it: 00066 ExecutionEngine* caller; 00067 // The Service of the current StateMachine 00068 boost::shared_ptr<StateMachineService> curobject ; 00069 ServicePtr peer; 00070 our_pos_iter_t& mpositer; 00071 our_pos_iter_t saveStartPos; 00072 // offset relative to StateMachine text. 00073 int ln_offset; 00074 00075 typedef boost::shared_ptr<ParsedStateMachine> ParsedStateMachinePtr; 00076 typedef std::map<std::string, ParsedStateMachinePtr> machinenamemap_t; 00077 typedef std::map<std::string, base::AttributeBase*> machineparams_t; 00078 typedef std::map<std::string, base::DataSourceBase::shared_ptr> machineparamvalues_t; 00079 typedef std::map<std::string, StateDescription*> machinestatesmap_t; 00080 typedef std::map<std::string, StateMachineBuilder*> machinebuilders_t; 00081 00082 machinenamemap_t rootmachines; 00083 machinebuilders_t machinebuilders; 00084 ParsedStateMachinePtr curtemplate; 00085 std::vector<base::ActionInterface*> paraminitcommands; 00086 std::vector<base::ActionInterface*> varinitcommands; 00087 ParsedStateMachinePtr curinstantiatedmachine; 00088 StateMachineBuilder* curmachinebuilder; 00089 std::string curinstmachinename; 00090 machineparamvalues_t curinstmachineparams; 00091 std::string curmachineinstargumentname; 00092 std::string curmachinename; 00093 bool curinitialstateflag; 00094 bool curfinalstateflag; 00095 StateDescription* curstate; 00096 StateDescription* curnonprecstate; 00097 ProgramGraphParser* progParser; 00098 boost::shared_ptr<ProgramInterface> transProgram; 00099 StateDescription* elsestate; 00100 boost::shared_ptr<ProgramInterface> elseProgram; 00101 ConditionInterface* curcondition; 00102 #if 0 00103 std::string curscvcmachinename; 00104 std::string curscvcparamname; 00105 #endif 00106 00110 int rank; 00111 bool isroot; 00112 unsigned int selectln; 00113 00114 std::vector<base::DataSourceBase::shared_ptr> evargs; 00115 std::string evname; 00116 std::map<std::string,ConditionCache*> cur_port_events; 00117 std::map<std::string,ConditionCache*> global_port_events; 00118 00119 rule_t production; 00120 rule_t body; 00121 rule_t newline; 00122 rule_t rootmachineinstantiation; 00123 rule_t statemachine; 00124 rule_t machineinstantiation; 00125 rule_t statemachinecontent; 00126 rule_t varline; 00127 rule_t state; 00128 rule_t vardec; 00129 rule_t subMachinedecl; 00130 rule_t statecontent; 00131 rule_t statecontentline; 00132 rule_t entry; 00133 rule_t preconditions; 00134 rule_t precondition; 00135 rule_t run; 00136 rule_t transitions; 00137 rule_t transition; 00138 rule_t argslist; 00139 rule_t handle; 00140 rule_t exit; 00141 rule_t programBody; 00142 rule_t transline; 00143 rule_t eventline; 00144 rule_t program; 00145 rule_t progselect; 00146 rule_t ifbranch; 00147 rule_t elsebranch; 00148 rule_t selector; 00149 rule_t machineinstarguments; 00150 rule_t machineinstargument; 00151 rule_t machinememvar; 00152 rule_t machinevariable; 00153 rule_t machineparam; 00154 rule_t machineconstant; 00155 rule_t machinealias; 00156 rule_t subMachinevarchange; 00157 00158 CommonParser* commonparser; 00159 ConditionParser* conditionparser; 00160 ValueChangeParser* valuechangeparser; 00161 ExpressionParser* expressionparser; 00162 ArgumentsParser* argsparser; 00163 PeerParser* peerparser; 00164 00165 void clear(); 00166 00167 void seeninitialstate(); 00168 void seenfinalstate(); 00169 void statedef( iter_t s, iter_t f); 00170 void seenstateend(); 00171 00172 void inprogram( const std::string& name ); 00173 void seenentry(); 00174 void seenexit(); 00175 void seenhandle(); 00176 void seenrun(); 00177 boost::shared_ptr<ProgramInterface> finishProgram(); 00178 00179 void seencondition(); 00180 void seenendcondition(); 00181 void seentransprog(); 00182 void seenelseprog(); 00183 void seenelse(); 00184 void noselect(); 00185 void seenselect( iter_t s, iter_t f); 00186 void doselect(const std::string& name); 00187 void seenprecondition(); 00188 void seeneventname(iter_t s, iter_t f); 00189 void seeneventtrans(); 00190 void seeneventargs(); 00191 00192 void seenstatemachinename( iter_t begin, iter_t end ); 00193 void saveText( iter_t begin, iter_t end ); 00194 void startrootmachineinstantiation(); 00195 void seenrootmachineinstantiation(); 00196 void seenstatemachineend(); 00197 void seensubMachineinstantiation(); 00198 00199 void inpreconditions(); 00200 void seenpreconditions(); 00201 00202 void seenmachinetypename( iter_t begin, iter_t end ); 00203 void seeninstmachinename( iter_t begin, iter_t end ); 00204 void seenmachineinstantiation(); 00205 void seenmachineinstargumentname( iter_t begin, iter_t end ); 00206 void seenmachineinstargumentvalue(); 00207 00208 void seenmachinevariable(); 00209 void seenmachineparam(); 00210 00211 #if 0 00212 void seenscvcsubMachinename( iter_t begin, iter_t end ); 00213 void seenscvcparamname( iter_t begin, iter_t end ); 00214 #endif 00215 public: 00216 StateGraphParser( iter_t& positer, TaskContext* tc, ExecutionEngine* caller, CommonParser* cp ); 00217 ~StateGraphParser(); 00218 00219 // tries to parse, returns the instantiated root machines. On all 00220 // returned machines setName() will have been called with the 00221 // correct name. 00222 // will throw an file_parse_exception on error 00223 std::vector<ParsedStateMachinePtr> parse( iter_t& begin, iter_t end ); 00224 00231 rule_t& parser(); 00236 ParsedStateMachinePtr getParserResult(); 00237 00243 void storeOffset(); 00244 }; 00245 }} 00246 00247 #endif