Orocos Real-Time Toolkit
2.6.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Mon Jan 19 14:11:25 CET 2004 ExpressionParser.hpp 00003 00004 ExpressionParser.hpp - description 00005 ------------------- 00006 begin : Mon January 19 2004 00007 copyright : (C) 2004 Peter Soetens 00008 email : peter.soetens@mech.kuleuven.ac.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 00038 #ifndef EXPRESSIONPARSER_HPP 00039 #define EXPRESSIONPARSER_HPP 00040 00041 #include "parser-types.hpp" 00042 #include "CommonParser.hpp" 00043 #include "PeerParser.hpp" 00044 #include "ValueParser.hpp" 00045 #include "../internal/DataSource.hpp" 00046 #include "../types/Operators.hpp" 00047 #include "../Time.hpp" 00048 00049 #include <stack> 00050 00051 #ifdef ORO_PRAGMA_INTERFACE 00052 #pragma interface 00053 #endif 00054 00055 namespace RTT { namespace scripting 00056 { 00065 class DataCallParser 00066 { 00067 base::DataSourceBase::shared_ptr ret; 00068 boost::shared_ptr<base::AttributeBase> mhandle; 00069 std::string mobject; 00070 std::string mmethod; 00071 ExecutionEngine* mcaller; 00072 bool mis_send; 00073 00074 rule_t datacall, arguments, peerpath, object, method; 00075 00076 void seenmethodname( iter_t begin, iter_t end ); 00077 void seenobjectname( iter_t begin, iter_t end ); 00078 void seendataname(); 00079 void seendatacall(); 00080 void seensend(); 00081 CommonParser& commonparser; 00082 ExpressionParser& expressionparser; 00083 PeerParser peerparser; 00084 std::stack<ArgumentsParser*> argparsers; 00085 public: 00086 DataCallParser( ExpressionParser& p, CommonParser& cp, TaskContext* pc, ExecutionEngine* caller ); 00087 ~DataCallParser(); 00088 00089 rule_t& parser() 00090 { 00091 return datacall; 00092 } 00093 00094 base::DataSourceBase* getParseResult() 00095 { 00096 return ret.get(); 00097 } 00098 boost::shared_ptr<base::AttributeBase> getParseHandle() 00099 { 00100 return mhandle; 00101 } 00102 }; 00103 00107 class ConstructorParser 00108 { 00109 base::DataSourceBase::shared_ptr ret; 00110 rule_t type_name, arguments; 00111 00112 CommonParser& commonparser; 00113 ExpressionParser& expressionparser; 00114 std::stack<ArgumentsParser*> argparsers; 00115 public: 00116 ConstructorParser( ExpressionParser& p, CommonParser& cp); 00117 ~ConstructorParser(); 00118 00119 void seen_type_name( iter_t begin, iter_t end ); 00120 void seen_constructor( void ); 00121 00122 rule_t& parser() 00123 { 00124 return type_name; 00125 } 00126 00127 base::DataSourceBase* getParseResult() 00128 { 00129 return ret.get(); 00130 } 00131 }; 00132 00140 class ExpressionParser 00141 { 00142 rule_t expression, unarynotexp, unaryminusexp, unaryplusexp, div_or_mul, 00143 modexp, plus_or_min, smallereqexp, smallerexp, 00144 greatereqexp, greaterexp, equalexp, notequalexp, orexp, andexp, 00145 ifthenelseexp, dotexp, groupexp, atomicexpression, 00146 time_expression, time_spec, indexexp, comma, close_brace, 00147 value_expression, call_expression, assignexp, constructor_expression; 00148 00155 std::stack<base::DataSourceBase::shared_ptr> parsestack; 00160 boost::shared_ptr<base::AttributeBase> mhandle; 00161 00162 // the name that was parsed as the object to use a certain 00163 // data of.. 00164 std::string mobjectname; 00165 00166 // the name that was parsed as the name of the data to use 00167 // from the object with name mobjectname. 00168 std::string mpropname; 00169 00170 // time specification 00171 nsecs tsecs; 00172 00173 void seen_unary( const std::string& op ); 00174 void seen_binary( const std::string& op ); 00175 void seen_index(); 00176 void seen_assign(); 00177 void seen_dotmember( iter_t begin, iter_t end ); 00178 void seenvalue(); 00179 void seendatacall(); 00180 void seenconstructor(); 00181 void seentimespec( int n ); 00182 void seentimeunit( iter_t begin, iter_t end ); 00183 void inverttime(); 00184 void seentimeexpr(); 00185 00186 DataCallParser datacallparser; 00187 ConstructorParser constrparser; 00191 CommonParser& commonparser; 00192 ValueParser valueparser; 00193 bool _invert_time; 00194 types::OperatorRepository::shared_ptr opreg; 00195 00196 TaskContext* context; 00197 public: 00198 ExpressionParser( TaskContext* pc, ExecutionEngine* caller, CommonParser& common_parser ); 00199 ~ExpressionParser(); 00200 00201 rule_t& parser(); 00202 00203 base::DataSourceBase::shared_ptr getResult(); 00204 00210 boost::shared_ptr<base::AttributeBase> getHandle(); 00211 00212 // after an expression is parsed, the resultant base::DataSourceBase will 00213 // still be on top of the stack, and it should be removed before 00214 // going back down the parse stack. This is what this function 00215 // does.. 00216 void dropResult(); 00217 00218 bool hasResult() { return !parsestack.empty(); } 00219 }; 00220 }} 00221 00222 #endif