Orocos Real-Time Toolkit  2.8.3
StateGraphParser.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Apr 22 20:40:59 CEST 2004 StateGraphParser.hpp
3 
4  StateGraphParser.hpp - description
5  -------------------
6  begin : Thu April 22 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 #ifndef EXECUTION_STATE_PARSER_HPP
39 #define EXECUTION_STATE_PARSER_HPP
40 
41 #include "parser-types.hpp"
42 
43 #include <map>
44 #include <string>
45 #include <boost/function.hpp>
46 #include <boost/shared_ptr.hpp>
47 #include "../internal/DataSource.hpp"
48 namespace RTT { namespace scripting
49 {
50 
62  {
63  // Our task we are parsing in :
64  TaskContext* context;
65  // The task that will execute it:
66  ExecutionEngine* caller;
67  // The Service of the current StateMachine
68  boost::shared_ptr<StateMachineService> curobject ;
69  ServicePtr peer;
70  our_pos_iter_t& mpositer;
71  our_pos_iter_t saveStartPos;
72  // offset relative to StateMachine text.
73  int ln_offset;
74 
75  typedef boost::shared_ptr<ParsedStateMachine> ParsedStateMachinePtr;
76  typedef std::map<std::string, ParsedStateMachinePtr> machinenamemap_t;
77  typedef std::map<std::string, base::AttributeBase*> machineparams_t;
78  typedef std::map<std::string, base::DataSourceBase::shared_ptr> machineparamvalues_t;
79  typedef std::map<std::string, StateDescription*> machinestatesmap_t;
80  typedef std::map<std::string, StateMachineBuilder*> machinebuilders_t;
81 
82  machinenamemap_t rootmachines;
83  machinebuilders_t machinebuilders;
84  ParsedStateMachinePtr curtemplate;
85  std::vector<base::ActionInterface*> paraminitcommands;
86  std::vector<base::ActionInterface*> varinitcommands;
87  ParsedStateMachinePtr curinstantiatedmachine;
88  StateMachineBuilder* curmachinebuilder;
89  std::string curinstmachinename;
90  machineparamvalues_t curinstmachineparams;
91  std::string curmachineinstargumentname;
92  std::string curmachinename;
93  bool curinitialstateflag;
94  bool curfinalstateflag;
95  StateDescription* curstate;
96  StateDescription* curnonprecstate;
97  ProgramGraphParser* progParser;
98  boost::shared_ptr<ProgramInterface> transProgram;
99  StateDescription* elsestate;
100  boost::shared_ptr<ProgramInterface> elseProgram;
101  ConditionInterface* curcondition;
102 #if 0
103  std::string curscvcmachinename;
104  std::string curscvcparamname;
105 #endif
106 
110  int rank;
111  bool isroot;
112  unsigned int selectln;
113 
114  std::vector<base::DataSourceBase::shared_ptr> evargs;
115  std::string evname;
116  std::map<std::string,ConditionCache*> cur_port_events;
117  std::map<std::string,ConditionCache*> global_port_events;
118 
119  rule_t production;
120  rule_t body;
121  rule_t newline;
122  rule_t rootmachineinstantiation;
123  rule_t statemachine;
124  rule_t machineinstantiation;
125  rule_t statemachinecontent;
126  rule_t varline;
127  rule_t state;
128  rule_t vardec;
129  rule_t subMachinedecl;
130  rule_t statecontent;
131  rule_t statecontentline;
132  rule_t entry;
133  rule_t preconditions;
134  rule_t precondition;
135  rule_t run;
136  rule_t transitions;
137  rule_t transition;
138  rule_t argslist;
139  rule_t handle;
140  rule_t exit;
141  rule_t programBody;
142  rule_t transline;
143  rule_t eventline;
144  rule_t program;
145  rule_t progselect;
146  rule_t ifbranch;
147  rule_t elsebranch;
148  rule_t selector;
149  rule_t machineinstarguments;
150  rule_t machineinstargument;
151  rule_t machinememvar;
152  rule_t machinevariable;
153  rule_t machineparam;
154  rule_t machineconstant;
155  rule_t machinealias;
156  rule_t subMachinevarchange;
157 
158  CommonParser* commonparser;
159  ConditionParser* conditionparser;
160  ValueChangeParser* valuechangeparser;
161  ExpressionParser* expressionparser;
162  ArgumentsParser* argsparser;
163  PeerParser* peerparser;
164 
165  void clear();
166 
167  void seeninitialstate();
168  void seenfinalstate();
169  void statedef( iter_t s, iter_t f);
170  void seenstateend();
171 
172  void inprogram( const std::string& name );
173  void seenentry();
174  void seenexit();
175  void seenhandle();
176  void seenrun();
177  boost::shared_ptr<ProgramInterface> finishProgram();
178 
179  void seencondition();
180  void seenendcondition();
181  void seentransprog();
182  void seenelseprog();
183  void seenelse();
184  void noselect();
185  void seenselect( iter_t s, iter_t f);
186  void doselect(const std::string& name);
187  void seenprecondition();
188  void seeneventname(iter_t s, iter_t f);
189  void seeneventtrans();
190  void seeneventargs();
191 
192  void seenstatemachinename( iter_t begin, iter_t end );
193  void saveText( iter_t begin, iter_t end );
194  void startrootmachineinstantiation();
195  void seenrootmachineinstantiation();
196  void seenstatemachineend();
197  void seensubMachineinstantiation();
198 
199  void inpreconditions();
200  void seenpreconditions();
201 
202  void seenmachinetypename( iter_t begin, iter_t end );
203  void seeninstmachinename( iter_t begin, iter_t end );
204  void seenmachineinstantiation();
205  void seenmachineinstargumentname( iter_t begin, iter_t end );
206  void seenmachineinstargumentvalue();
207 
208  void seenmachinevariable();
209  void seenmachineparam();
210 
211 #if 0
212  void seenscvcsubMachinename( iter_t begin, iter_t end );
213  void seenscvcparamname( iter_t begin, iter_t end );
214 #endif
215  public:
216  StateGraphParser( iter_t& positer, TaskContext* tc, ExecutionEngine* caller, CommonParser* cp );
218 
219  // tries to parse, returns the instantiated root machines. On all
220  // returned machines setName() will have been called with the
221  // correct name.
222  // will throw an file_parse_exception on error
223  std::vector<ParsedStateMachinePtr> parse( iter_t& begin, iter_t end );
224 
231  rule_t& parser();
236  ParsedStateMachinePtr getParserResult();
237 
243  void storeOffset();
244  };
245 }}
246 
247 #endif
This is not a parser in the Boost.spirit sense of the word, it&#39;s just a class used to hold the parser...
This interface represents the concept of a condition which can be evaluated and return true or false...
This class represents a state with all actions stored in an external program.
StateGraphParser(iter_t &positer, TaskContext *tc, ExecutionEngine *caller, CommonParser *cp)
A Parser for Orocos Program Scripts.
This is a parser that you construct to parse a set of arguments.
This class contains some very common parser definitions.
void storeOffset()
Stores the current position in the input stream (iterator received from the constructor) in order to ...
An execution engine serialises (executes one after the other) the execution of all commands...
How we parse: this parser works like a stack-based RPN calculator.
position_iterator< our_iterator_t > our_pos_iter_t
ParsedStateMachinePtr getParserResult()
Returns the last state machine instantiation of parser() or null if no instantiations were seen...
boost::shared_ptr< Service > ServicePtr
Definition: rtt-fwd.hpp:86
Get the peer and object from an invocation path like a.b.c.d() .
Definition: PeerParser.hpp:58
rule< scanner_t > rule_t
This class is responsible for parsing constant definitions, variable definitions, variable change ins...
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
rule_t & parser()
Returns the top-level parser for state machines.
our_pos_iter_t iter_t
This is a class containing a parse function for conditions.
std::vector< ParsedStateMachinePtr > parse(iter_t &begin, iter_t end)