Orocos Real-Time Toolkit  2.9.0
ExpressionParser.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:25 CET 2004 ExpressionParser.hpp
3 
4  ExpressionParser.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 EXPRESSIONPARSER_HPP
39 #define EXPRESSIONPARSER_HPP
40 
41 #include "parser-types.hpp"
42 #include "CommonParser.hpp"
43 #include "PeerParser.hpp"
44 #include "ValueParser.hpp"
45 #include "SendHandleAlias.hpp"
46 #include "../internal/DataSource.hpp"
47 #include "../types/Operators.hpp"
48 #include "../Time.hpp"
49 
50 #include <stack>
51 
52 #ifdef ORO_PRAGMA_INTERFACE
53 #pragma interface
54 #endif
55 
56 namespace RTT { namespace scripting
57 {
67  {
69  boost::shared_ptr<SendHandleAlias> mhandle;
70  ConditionInterface* mcmdcnd;
71  std::string mobject;
72  std::string mmethod;
73  ExecutionEngine* mcaller;
74  enum CallType { DEFAULT_CALLTYPE, CALLTYPE_CALL, CALLTYPE_SEND, CALLTYPE_CMD } mcalltype;
75 
76  rule_t datacall, arguments, peerpath, object, method;
77 
78  void seenmethodname( iter_t begin, iter_t end );
79  void seenobjectname( iter_t begin, iter_t end );
80  void seendataname();
81  void seendatacall();
82 
83  CommonParser& commonparser;
84  ExpressionParser& expressionparser;
85  PeerParser peerparser;
86  std::stack<ArgumentsParser*> argparsers;
87  public:
90 
92  {
93  return datacall;
94  }
95 
97  {
98  return ret.get();
99  }
101  {
102  return mcmdcnd;
103  }
104  boost::shared_ptr<SendHandleAlias> getParseHandle()
105  {
106  return mhandle;
107  }
108  };
109 
114  {
116  rule_t type_name, arguments;
117 
118  CommonParser& commonparser;
119  ExpressionParser& expressionparser;
120  std::stack<ArgumentsParser*> argparsers;
121  public:
124 
125  void seen_type_name( iter_t begin, iter_t end );
126  void seen_constructor( void );
127 
129  {
130  return type_name;
131  }
132 
134  {
135  return ret.get();
136  }
137  };
138 
147  {
148  rule_t expression, unarynotexp, unaryminusexp, unaryplusexp, div_or_mul,
149  modexp, plus_or_min, smallereqexp, smallerexp,
150  greatereqexp, greaterexp, equalexp, notequalexp, orexp, andexp,
151  ifthenelseexp, dotexp, groupexp, atomicexpression,
152  time_expression, time_spec, indexexp, comma, close_brace,
153  value_expression, call_expression, assignexp, constructor_expression;
154 
161  std::stack<base::DataSourceBase::shared_ptr> parsestack;
166  boost::shared_ptr<SendHandleAlias> mhandle;
167 
168  ConditionInterface* mcmdcnd;
169 
170  // the name that was parsed as the object to use a certain
171  // data of..
172  std::string mobjectname;
173 
174  // the name that was parsed as the name of the data to use
175  // from the object with name mobjectname.
176  std::string mpropname;
177 
178  // time specification
179  nsecs tsecs;
180 
181  void seen_unary( const std::string& op );
182  void seen_binary( const std::string& op );
183  void seen_index();
184  void seen_assign();
185  void seen_dotmember( iter_t begin, iter_t end );
186  void seenvalue();
187  void seendatacall();
188  void seenconstructor();
189  void seentimespec( int n );
190  void seentimeunit( iter_t begin, iter_t end );
191  void inverttime();
192  void seentimeexpr();
193 
194  DataCallParser datacallparser;
195  ConstructorParser constrparser;
199  CommonParser& commonparser;
200  ValueParser valueparser;
201  bool _invert_time;
203 
204  TaskContext* context;
205  public:
206  ExpressionParser( TaskContext* pc, ExecutionEngine* caller, CommonParser& common_parser );
207  ~ExpressionParser();
208 
209  rule_t& parser();
210 
212  ConditionInterface* getCmdResult();
213 
219  boost::shared_ptr<base::AttributeBase> getHandle();
220 
221  // after an expression is parsed, the resultant base::DataSourceBase will
222  // still be on top of the stack, and it should be removed before
223  // going back down the parse stack. This is what this function
224  // does..
225  void dropResult();
226 
227  bool hasResult() { return !parsestack.empty(); }
228  };
229 }}
230 
231 #endif
This parser parses a call of the form "a.b( arg1, arg2, ..., argN )".
The base class for all internal data representations.
DataCallParser(ExpressionParser &p, CommonParser &cp, TaskContext *pc, ExecutionEngine *caller)
This interface represents the concept of a condition which can be evaluated and return true or false...
boost::shared_ptr< OperatorRepository > shared_ptr
Definition: Operators.hpp:118
base::DataSourceBase * getParseResult()
This class contains some very common parser definitions.
An execution engine serialises (executes one after the other) the execution of all commands...
Parses type constructor syntax.
A class for parsing const values.
Definition: ValueParser.hpp:58
How we parse: this parser works like a stack-based RPN calculator.
Get the peer and object from an invocation path like a.b.c.d() .
Definition: PeerParser.hpp:58
rule< scanner_t > rule_t
ConditionInterface * getParseCmdResult()
base::DataSourceBase * getParseResult()
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
our_pos_iter_t iter_t
long long nsecs
nanoseconds as a signed long long.
Definition: Time.hpp:69
boost::shared_ptr< SendHandleAlias > getParseHandle()