ExpressionParser.hpp

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 "../DataSource.hpp"
00046 #include "../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 detail
00056 {
00065   class DataCallParser
00066   {
00067     DataSourceBase::shared_ptr ret;
00068     std::string mobject;
00069     std::string mmethod;
00070 
00071     rule_t datacall, arguments;
00072 
00073     void seenmethodname( iter_t begin, iter_t end )
00074       {
00075         std::string name( begin, end );
00076         mmethod = name;
00077       };
00078 
00079     void seendataname();
00080     void seendatacall();
00081     CommonParser& commonparser;
00082     ExpressionParser& expressionparser;
00083     PeerParser peerparser;
00084     std::stack<ArgumentsParser*> argparsers;
00085   public:
00086     DataCallParser( ExpressionParser& p, CommonParser& cp, TaskContext* pc );
00087     ~DataCallParser();
00088 
00089     rule_t& parser()
00090       {
00091         return datacall;
00092       };
00093 
00094     DataSourceBase* getParseResult()
00095       {
00096         return ret.get();
00097       };
00098   };
00099 
00107   class ExpressionParser
00108   {
00109     rule_t expression, unarynotexp, unaryminusexp, unaryplusexp, div_or_mul,
00110       modexp, plusexp, minusexp, smallereqexp, smallerexp,
00111       greatereqexp, greaterexp, equalexp, notequalexp, orexp, andexp,
00112       ifthenelseexp, dotexp, groupexp, atomicexpression,
00113       time_expression, time_spec, indexexp, comma, open_brace, close_brace;
00114 
00121     std::stack<DataSourceBase::shared_ptr> parsestack;
00122 
00123     // the name that was parsed as the object to use a certain
00124     // data of..
00125     std::string mobjectname;
00126 
00127     // the name that was parsed as the name of the data to use
00128     // from the object with name mobjectname.
00129     std::string mpropname;
00130 
00131     // time specification
00132     nsecs tsecs;
00133 
00134     void seen_unary( const std::string& op );
00135     void seen_binary( const std::string& op );
00136     void seen_dotmember( iter_t begin, iter_t end );
00137     void seenvalue();
00138     void seendatacall();
00139     void seentimespec( int n );
00140     void seentimeunit( iter_t begin, iter_t end );
00141       void inverttime();
00142       void seentimeexpr();
00143 
00144       DataCallParser datacallparser;
00148       CommonParser& commonparser;
00149       ValueParser valueparser;
00150       bool _invert_time;
00151       OperatorRepository::shared_ptr opreg;
00152   public:
00153       ExpressionParser( TaskContext* pc, CommonParser& common_parser );
00154     ~ExpressionParser();
00155 
00156     rule_t& parser();
00157 
00158     DataSourceBase::shared_ptr getResult();
00159     // after an expression is parsed, the resultant DataSourceBase will
00160     // still be on top of the stack, and it should be removed before
00161     // going back down the parse stack.  This is what this function
00162     // does..
00163     void dropResult();
00164 
00165       bool hasResult() { return !parsestack.empty(); }
00166   };
00167 }}
00168 
00169 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3