ProgramGraphParser2.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon May 10 19:10:37 CEST 2004  ProgramGraphParser.cpp
00003 
00004                         ProgramGraphParser.cpp -  description
00005                            -------------------
00006     begin                : Mon May 10 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 #include "parser-debug.hpp"
00039 #include "parse_exception.hpp"
00040 #include "ProgramGraphParser.hpp"
00041 
00042 #include <boost/bind.hpp>
00043 #include <boost/lambda/lambda.hpp>
00044 
00045 #ifdef WIN32
00046     #ifdef NDEBUG
00047         #pragma optimize( "", off)
00048     #endif
00049 #endif
00050 
00051 namespace RTT
00052 {
00053   using namespace boost;
00054   using namespace detail;
00055 
00056     namespace {
00057         boost::spirit::classic::assertion<std::string> expect_ifblock("Expected a statement (or { block } ).");
00058         boost::spirit::classic::assertion<std::string> expect_then("Wrongly formatted \"if ... then\" clause.");
00059         boost::spirit::classic::assertion<std::string> expect_elseblock("Expected a statement (or {block} ) after else.");
00060         boost::spirit::classic::assertion<std::string> expect_ident("Expected a valid identifier.");
00061     }
00062     // Work around GCC 4.1 bug: not too much templates in one.cpp file.
00063   void ProgramGraphParser::setup2()
00064   {
00065     // a function statement : "call functionname"
00066     funcstatement = (
00067       lexeme_d[keyword_p( "call" )]
00068       >> expect_ident( commonparser.identifier[boost::bind( &ProgramGraphParser::seenfuncidentifier, this, _1, _2) ] )
00069       >> !arguments[ boost::bind( &ProgramGraphParser::seencallfuncargs, this )]
00070       )[ boost::bind( &ProgramGraphParser::seencallfuncstatement, this ) ];
00071 
00072     // a return statement : "return"
00073     returnstatement =
00074         (keyword_p( "return" )[boost::bind(&ProgramGraphParser::noskip_eol, this )]
00075         >> (  eps_p(commonparser.notassertingeos) | expressionparser.parser()[boost::bind( &ProgramGraphParser::seenreturnvalue, this ) ] )[boost::bind(&ProgramGraphParser::skip_eol, this )])[ boost::bind( &ProgramGraphParser::seenreturnstatement, this ) ];
00076 
00077     // break from a while or for loop,...
00078     breakstatement =
00079         keyword_p( "break" )[ boost::bind (&ProgramGraphParser::seenbreakstatement, this) ];
00080 
00081     catchpart = (keyword_p("catch") [boost::bind(&ProgramGraphParser::startcatchpart, this)]
00082                  >> expect_ifblock( ifblock ) )[boost::bind(&ProgramGraphParser::seencatchpart, this)];
00083 
00084     forstatement = ( keyword_p("for") >> openbrace
00085                      >> !(valuechangeparser.parser()[boost::bind(&ProgramGraphParser::seenforinit, this)]
00086                           |
00087                           expressionparser.parser()[boost::bind(&ProgramGraphParser::seenforinit_expr, this)])>> semicolon
00088                      >> condition >> semicolon >> !keyword_p("set")
00089                      >> ( (expressionparser.parser()[boost::bind(&ProgramGraphParser::seenforincr, this)] >> closebrace ) | closebrace[boost::bind(&ProgramGraphParser::seenemptyforincr, this)])
00090                      ) [boost::bind(&ProgramGraphParser::seenforstatement, this)]
00091                                   >> expect_ifblock( ifblock[ boost::bind(&ProgramGraphParser::endforstatement, this) ]);
00092 
00093     ifstatement = (keyword_p("if")
00094                    >> condition
00095                    >> expect_then( keyword_p("then")[boost::bind(&ProgramGraphParser::seenifstatement, this)] )
00096                    >> expect_ifblock( ifblock[ boost::bind(&ProgramGraphParser::endifblock, this) ] )
00097                    >> !( keyword_p("else") >> expect_elseblock(ifblock) )
00098                    )[ boost::bind(&ProgramGraphParser::endifstatement, this) ];
00099 
00100     // ifblock is used for a group of statements or one statement (see also whilestatement)
00101     ifblock = ( ch_p('{') >> *line >> closecurly ) | statement;
00102 
00103     whilestatement =
00104         (keyword_p("while")
00105          >> condition )
00106         [boost::bind(&ProgramGraphParser::seenwhilestatement, this)]
00107          >> expect_ifblock( ifblock[ boost::bind(&ProgramGraphParser::endwhilestatement, this) ] );
00108 
00109     continuepart = keyword_p("continue")[ boost::bind( &ProgramGraphParser::seencontinue, this)];
00110 
00111   }
00112 }
00113 


rtt
Author(s): RTT Developers
autogenerated on Thu Jan 2 2014 11:35:23