ProgramGraphParser.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:26 CET 2004  ProgramGraphParser.hpp
00003 
00004                         ProgramGraphParser.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 EXECUTION_PROGRAM_PARSER_HPP
00039 #define EXECUTION_PROGRAM_PARSER_HPP
00040 
00041 #include "parser-types.hpp"
00042 
00043 #include "CommonParser.hpp"
00044 #include "PeerParser.hpp"
00045 #include "ConditionParser.hpp"
00046 #include "ExpressionParser.hpp"
00047 #include "../TaskContext.hpp"
00048 #include "FunctionGraphBuilder.hpp"
00049 #include "ValueChangeParser.hpp"
00050 
00051 #include <map>
00052 #include <vector>
00053 #include <string>
00054 
00055 
00056 #include "ProgramService.hpp"
00057 //namespace RTT {
00058 //    class ProgramService;
00059 //}
00060 
00061 namespace RTT { namespace scripting
00062 {
00072   class ProgramGraphParser
00073   {
00074       typedef FunctionGraphBuilder::CommandNode CommandNode;
00075       typedef FunctionGraphBuilder::ConditionEdge ConditionEdge;
00076       typedef FunctionGraphBuilder::Graph  Graph;
00077 
00082       TaskContext* rootc;
00083 
00087       Service::shared_ptr context;
00088 
00092       TaskContext* fcontext;
00093 
00097       TaskContext* peer;
00098 
00099       our_pos_iter_t& mpositer;
00100 
00101       // The current function we are parsing.
00102       FunctionGraphPtr mfunc;
00103 
00104       // The function we will call next
00105       FunctionGraphPtr mcallfunc;
00106 
00107       // A map of all functions
00108       typedef std::map<std::string, FunctionGraphPtr> funcmap;
00109       funcmap mfuncs;
00110 
00111       // The return type of the current function.
00112       std::string rettype;
00113 
00114       // The implicit termination condition we just got for the
00115       // current command from the CommandParser..
00116       ConditionInterface* implcond;
00117       std::vector<ConditionInterface*> implcond_v;
00118       std::vector<base::DataSourceBase::shared_ptr> callfnargs;
00119 
00120       // last seen condition
00121       ConditionInterface* mcondition;
00122       // try-block condition
00123       ConditionInterface* try_cond;
00124 
00125       void seencondition();
00126 
00127       void seencallfunclabel( iter_t begin, iter_t end );
00128 
00129       void seencontinue( );
00130 
00131       void skip_eol();
00132       void noskip_eol();
00133       void seenyield();
00134       void seenstatement();
00135       void seentrystatement();
00136       void startcatchpart();
00137       void seencatchpart();
00138 
00139       void seenvaluechange();
00140 
00141       void functiondef( iter_t begin, iter_t end );
00142       void exportdef(  );
00143       void globaldef(  );
00144       void seenfunctionarg();
00145       void seenfunctionend();
00146       void seenvalidinput();
00147 
00148       void seenfuncidentifier( iter_t begin, iter_t end);
00149       void seencallfuncstatement();
00150       void seencallfuncargs();
00151 
00152       void seenreturnstatement();
00153       void seenreturnlabel();
00154       void seenreturnvalue();
00155       void seenreturntype( iter_t begin, iter_t end );
00156 
00157       void seenifstatement();
00158       void endifblock();
00159       void endifstatement();
00160 
00161       void seenwhilestatement();
00162       void endwhilestatement();
00163 
00164       void seenbreakstatement();
00165 
00166       void seenforstatement();
00167       void seenforinit();
00168       void seenforinit_expr();
00169       void seenforincr();
00170       void seenemptyforincr();
00171       void endforstatement();
00172 
00173       void startofprogram();
00174       void programdef( iter_t begin, iter_t end );
00175       void seenprogramend();
00176       void programtext(iter_t, iter_t);
00177 
00178       void setStack(Service::shared_ptr st);
00180       void clearParseState();
00181       void setup();
00182       void setup2();
00183       void cleanup(bool remove_service);
00184 
00185       rule_t newline, terminationclause, jumpdestination, terminationpart, andpart,
00186           dostatement, trystatement, statement, line, content, program,
00187           production, valuechange, returnstatement, function, functions, arguments, funcstatement,
00188           continuepart, returnpart, callpart, ifstatement, ifblock, whilestatement, breakstatement,
00189           openbrace, closebrace, opencurly, closecurly, forstatement, semicolon,
00190           condition, catchpart, funcargs, functionarg, emitstatement ;
00191 
00192       CommonParser& commonparser;
00193       ConditionParser conditionparser;
00194       ValueChangeParser valuechangeparser;
00195       ExpressionParser expressionparser;
00196       ArgumentsParser* argsparser;
00197       PeerParser peerparser;
00198 
00199       boost::shared_ptr<FunctionGraphBuilder> program_builder;
00200       std::vector< FunctionGraphPtr > program_list;
00201 
00202       base::ActionInterface* for_init_command;
00203       std::stack<base::ActionInterface*> for_incr_command;
00204       std::string program_text;
00205       bool exportf,globalf, parserused;
00206       int ln_offset;
00207   public:
00208       ProgramGraphParser( iter_t& positer, TaskContext* context, ExecutionEngine* caller, CommonParser& cp);
00209       ~ProgramGraphParser();
00210 
00215       std::vector<ProgramInterfacePtr> parse( iter_t& begin, iter_t end );
00216 
00217       std::vector<ProgramInterfacePtr> parseFunction( iter_t& begin, iter_t end );
00218 
00223       void initBodyParser(const std::string& name, Service::shared_ptr stck, int offset);
00224 
00230       rule_t& bodyParser();
00231 
00235       rule_t& statementParser();
00236 
00240       rule_t& programParser();
00241 
00245       ProgramInterfacePtr programParserResult();
00249       rule_t& functionParser();
00250 
00251       ProgramInterfacePtr bodyParserResult();
00252 
00257       bool parserUsed() const;
00258   };
00259 }}
00260 
00261 #endif


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:56