Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00064 TaskContext* context;
00065
00066 ExecutionEngine* caller;
00067
00068 boost::shared_ptr<StateMachineService> curobject ;
00069 ServicePtr peer;
00070 our_pos_iter_t& mpositer;
00071 our_pos_iter_t saveStartPos;
00072
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
00220
00221
00222
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