Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00063 void ProgramGraphParser::setup2()
00064 {
00065
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
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
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
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