Orocos Real-Time Toolkit  2.9.0
ProgramGraphParser.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:26 CET 2004 ProgramGraphParser.hpp
3 
4  ProgramGraphParser.hpp - description
5  -------------------
6  begin : Mon January 19 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_PROGRAM_PARSER_HPP
39 #define EXECUTION_PROGRAM_PARSER_HPP
40 
41 #include "parser-types.hpp"
42 
43 #include "CommonParser.hpp"
44 #include "PeerParser.hpp"
45 #include "ConditionParser.hpp"
46 #include "ExpressionParser.hpp"
47 #include "../TaskContext.hpp"
48 #include "FunctionGraphBuilder.hpp"
49 #include "ValueChangeParser.hpp"
50 
51 #include <map>
52 #include <vector>
53 #include <string>
54 
55 
56 #include "ProgramService.hpp"
57 //namespace RTT {
58 // class ProgramService;
59 //}
60 
61 namespace RTT { namespace scripting
62 {
73  {
74  typedef FunctionGraphBuilder::CommandNode CommandNode;
75  typedef FunctionGraphBuilder::ConditionEdge ConditionEdge;
76  typedef FunctionGraphBuilder::Graph Graph;
77 
82  TaskContext* rootc;
83 
87  Service::shared_ptr context;
88 
92  Service::shared_ptr fcontext;
93 
97  TaskContext* peer;
98 
99  our_pos_iter_t& mpositer;
100 
101  // The current function we are parsing.
102  FunctionGraphPtr mfunc;
103 
104  // The function we will call next
105  FunctionGraphPtr mcallfunc;
106 
107  // A map of all functions
108  typedef std::map<std::string, FunctionGraphPtr> funcmap;
109  funcmap mfuncs;
110 
111  // The return type of the current function.
112  std::string rettype;
113 
114  // The implicit termination condition we just got for the
115  // current command from the CommandParser..
116  ConditionInterface* implcond;
117  std::vector<ConditionInterface*> implcond_v;
118  std::vector<base::DataSourceBase::shared_ptr> callfnargs;
119 
120  // last seen condition
121  ConditionInterface* mcondition;
122  // try-block condition
123  ConditionInterface* try_cond;
124 
125  void seencondition();
126 
127  void seencallfunclabel( iter_t begin, iter_t end );
128 
129  void seencontinue( );
130 
131  void skip_eol();
132  void noskip_eol();
133  void seenyield();
134  void seenstatement();
135  void seentrystatement();
136  void startcatchpart();
137  void seencatchpart();
138 
139  void seenvaluechange();
140 
141  void functiondef( iter_t begin, iter_t end );
142  void exportdef( );
143  void globaldef( );
144  void seenfunctionarg();
145  void seenfunctionend();
146  void seenvalidinput();
147 
148  void seenfuncidentifier( iter_t begin, iter_t end);
149  void seencallfuncstatement();
150  void seencallfuncargs();
151 
152  void seenreturnstatement();
153  void seenreturnlabel();
154  void seenreturnvalue();
155  void seenreturntype( iter_t begin, iter_t end );
156 
157  void seenifstatement();
158  void endifblock();
159  void endifstatement();
160 
161  void seenwhilestatement();
162  void endwhilestatement();
163 
164  void seenbreakstatement();
165 
166  void seenforstatement();
167  void seenforinit();
168  void seenforinit_expr();
169  void seenforincr();
170  void seenemptyforincr();
171  void endforstatement();
172 
173  void startofprogram();
174  void programdef( iter_t begin, iter_t end );
175  void seenprogramend();
176  void programtext(iter_t, iter_t);
177 
178  void setStack(Service::shared_ptr st);
180  void clearParseState();
181  void setup();
182  void setup2();
183  void cleanup(bool remove_service);
184 
185  rule_t newline, terminationclause, jumpdestination, terminationpart, andpart,
186  dostatement, trystatement, statement, line, content, program,
187  production, valuechange, returnstatement, function, functions, arguments, funcstatement,
188  continuepart, returnpart, callpart, ifstatement, ifblock, whilestatement, breakstatement,
189  openbrace, closebrace, opencurly, closecurly, forstatement, semicolon,
190  condition, catchpart, funcargs, functionarg, emitstatement ;
191 
192  CommonParser& commonparser;
193  ConditionParser conditionparser;
194  ValueChangeParser valuechangeparser;
195  ExpressionParser expressionparser;
196  ArgumentsParser* argsparser;
197  PeerParser peerparser;
198 
199  boost::shared_ptr<FunctionGraphBuilder> program_builder;
200  std::vector< FunctionGraphPtr > program_list;
201 
202  base::ActionInterface* for_init_command;
203  std::stack<base::ActionInterface*> for_incr_command;
204  std::string program_text;
205  bool exportf,globalf, parserused;
206  int ln_offset;
207  public:
208  ProgramGraphParser( iter_t& positer, TaskContext* context, ExecutionEngine* caller, CommonParser& cp);
210 
215  std::vector<ProgramInterfacePtr> parse( iter_t& begin, iter_t end );
216 
217  std::vector<ProgramInterfacePtr> parseFunction( iter_t& begin, iter_t end );
218 
223  void initBodyParser(const std::string& name, Service::shared_ptr stck, int offset);
224 
230  rule_t& bodyParser();
231 
236 
241 
250 
252 
257  bool parserUsed() const;
258  };
259 }}
260 
261 #endif
FunctionGraph::Edge ConditionEdge
A ConditionEdge serves as a token to construct an edge, containing a condition.
boost::shared_ptr< FunctionGraph > FunctionGraphPtr
This interface represents the concept of a condition which can be evaluated and return true or false...
A Parser for Orocos Program Scripts.
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
void initBodyParser(const std::string &name, Service::shared_ptr stck, int offset)
Initialize the bodyParser to parse and store each statement it sees.
This is a parser that you construct to parse a set of arguments.
This class contains some very common parser definitions.
An execution engine serialises (executes one after the other) the execution of all commands...
boost::shared_ptr< Service > shared_ptr
Definition: Service.hpp:101
ProgramInterfacePtr programParserResult()
Returns the last program parsed by programParser()
bool parserUsed() const
Returns true if the parser was already used (even partially).
rule_t & programParser()
Returns a program foo {} parser.
How we parse: this parser works like a stack-based RPN calculator.
rule_t & functionParser()
Parses a function foo {} definition.
ProgramGraphParser(iter_t &positer, TaskContext *context, ExecutionEngine *caller, CommonParser &cp)
position_iterator< our_iterator_t > our_pos_iter_t
Get the peer and object from an invocation path like a.b.c.d() .
Definition: PeerParser.hpp:58
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
rule< scanner_t > rule_t
rule_t & statementParser()
Parses a single-line statement.
This class is responsible for parsing constant definitions, variable definitions, variable change ins...
rule_t & bodyParser()
Parses a multi-line program, which you can retrieve with bodyParserResult().
std::vector< ProgramInterfacePtr > parse(iter_t &begin, iter_t end)
Tries to parse programs, returns the generated programs on success.
std::vector< ProgramInterfacePtr > parseFunction(iter_t &begin, iter_t end)
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:52
our_pos_iter_t iter_t
This is a class containing a parse function for conditions.
boost::adjacency_list< boost::vecS, boost::listS, boost::directedS, VertProperty, EdgeProperty > Graph
FunctionGraph::Vertex CommandNode
A CommandNode serves as a token to construct a vertex or node, containing a command.