Orocos Real-Time Toolkit  2.8.3
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 "../internal/DataSource.hpp"
46 #include "../types/Operators.hpp"
47 #include "../Time.hpp"
48 
49 #include <stack>
50 
51 #ifdef ORO_PRAGMA_INTERFACE
52 #pragma interface
53 #endif
54 
55 namespace RTT { namespace scripting
56 {
66  {
68  boost::shared_ptr<base::AttributeBase> mhandle;
69  std::string mobject;
70  std::string mmethod;
71  ExecutionEngine* mcaller;
72  bool mis_send;
73 
74  rule_t datacall, arguments, peerpath, object, method;
75 
76  void seenmethodname( iter_t begin, iter_t end );
77  void seenobjectname( iter_t begin, iter_t end );
78  void seendataname();
79  void seendatacall();
80  void seensend();
81  CommonParser& commonparser;
82  ExpressionParser& expressionparser;
83  PeerParser peerparser;
84  std::stack<ArgumentsParser*> argparsers;
85  public:
88 
90  {
91  return datacall;
92  }
93 
95  {
96  return ret.get();
97  }
98  boost::shared_ptr<base::AttributeBase> getParseHandle()
99  {
100  return mhandle;
101  }
102  };
103 
108  {
110  rule_t type_name, arguments;
111 
112  CommonParser& commonparser;
113  ExpressionParser& expressionparser;
114  std::stack<ArgumentsParser*> argparsers;
115  public:
118 
119  void seen_type_name( iter_t begin, iter_t end );
120  void seen_constructor( void );
121 
123  {
124  return type_name;
125  }
126 
128  {
129  return ret.get();
130  }
131  };
132 
141  {
142  rule_t expression, unarynotexp, unaryminusexp, unaryplusexp, div_or_mul,
143  modexp, plus_or_min, smallereqexp, smallerexp,
144  greatereqexp, greaterexp, equalexp, notequalexp, orexp, andexp,
145  ifthenelseexp, dotexp, groupexp, atomicexpression,
146  time_expression, time_spec, indexexp, comma, close_brace,
147  value_expression, call_expression, assignexp, constructor_expression;
148 
155  std::stack<base::DataSourceBase::shared_ptr> parsestack;
160  boost::shared_ptr<base::AttributeBase> mhandle;
161 
162  // the name that was parsed as the object to use a certain
163  // data of..
164  std::string mobjectname;
165 
166  // the name that was parsed as the name of the data to use
167  // from the object with name mobjectname.
168  std::string mpropname;
169 
170  // time specification
171  nsecs tsecs;
172 
173  void seen_unary( const std::string& op );
174  void seen_binary( const std::string& op );
175  void seen_index();
176  void seen_assign();
177  void seen_dotmember( iter_t begin, iter_t end );
178  void seenvalue();
179  void seendatacall();
180  void seenconstructor();
181  void seentimespec( int n );
182  void seentimeunit( iter_t begin, iter_t end );
183  void inverttime();
184  void seentimeexpr();
185 
186  DataCallParser datacallparser;
187  ConstructorParser constrparser;
191  CommonParser& commonparser;
192  ValueParser valueparser;
193  bool _invert_time;
195 
196  TaskContext* context;
197  public:
198  ExpressionParser( TaskContext* pc, ExecutionEngine* caller, CommonParser& common_parser );
199  ~ExpressionParser();
200 
201  rule_t& parser();
202 
204 
210  boost::shared_ptr<base::AttributeBase> getHandle();
211 
212  // after an expression is parsed, the resultant base::DataSourceBase will
213  // still be on top of the stack, and it should be removed before
214  // going back down the parse stack. This is what this function
215  // does..
216  void dropResult();
217 
218  bool hasResult() { return !parsestack.empty(); }
219  };
220 }}
221 
222 #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)
boost::shared_ptr< base::AttributeBase > getParseHandle()
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
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:51
our_pos_iter_t iter_t
long long nsecs
nanoseconds as a signed long long.
Definition: Time.hpp:69