ProgramGraphParser2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon May 10 19:10:37 CEST 2004 ProgramGraphParser.cpp
3 
4  ProgramGraphParser.cpp - description
5  -------------------
6  begin : Mon May 10 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 #include "parser-debug.hpp"
39 #include "parse_exception.hpp"
40 #include "ProgramGraphParser.hpp"
41 
42 #include <boost/bind.hpp>
43 #include <boost/lambda/lambda.hpp>
44 
45 #ifdef WIN32
46  #ifdef NDEBUG
47  #pragma optimize( "", off)
48  #endif
49 #endif
50 
51 namespace RTT
52 {
53  using namespace boost;
54  using namespace detail;
55 
56  namespace {
57  boost::spirit::classic::assertion<std::string> expect_ifblock("Expected a statement (or { block } ).");
58  boost::spirit::classic::assertion<std::string> expect_then("Wrongly formatted \"if ... then\" clause.");
59  boost::spirit::classic::assertion<std::string> expect_elseblock("Expected a statement (or {block} ) after else.");
60  boost::spirit::classic::assertion<std::string> expect_ident("Expected a valid identifier.");
61  }
62  // Work around GCC 4.1 bug: not too much templates in one.cpp file.
64  {
65  // a function statement : "call functionname"
66  funcstatement = (
67  lexeme_d[keyword_p( "call" )]
68  >> expect_ident( commonparser.identifier[boost::bind( &ProgramGraphParser::seenfuncidentifier, this, _1, _2) ] )
69  >> !arguments[ boost::bind( &ProgramGraphParser::seencallfuncargs, this )]
70  )[ boost::bind( &ProgramGraphParser::seencallfuncstatement, this ) ];
71 
72  // a return statement : "return"
73  returnstatement =
74  (keyword_p( "return" )[boost::bind(&ProgramGraphParser::noskip_eol, this )]
75  >> ( eps_p(commonparser.notassertingeos) | expressionparser.parser()[boost::bind( &ProgramGraphParser::seenreturnvalue, this ) ] )[boost::bind(&ProgramGraphParser::skip_eol, this )])[ boost::bind( &ProgramGraphParser::seenreturnstatement, this ) ];
76 
77  // break from a while or for loop,...
78  breakstatement =
79  keyword_p( "break" )[ boost::bind (&ProgramGraphParser::seenbreakstatement, this) ];
80 
81  catchpart = (keyword_p("catch") [boost::bind(&ProgramGraphParser::startcatchpart, this)]
82  >> expect_ifblock( ifblock ) )[boost::bind(&ProgramGraphParser::seencatchpart, this)];
83 
84  forstatement = ( keyword_p("for") >> openbrace
85  >> !(valuechangeparser.parser()[boost::bind(&ProgramGraphParser::seenforinit, this)]
86  |
87  expressionparser.parser()[boost::bind(&ProgramGraphParser::seenforinit_expr, this)])>> semicolon
88  >> condition >> semicolon >> !keyword_p("set")
89  >> ( (expressionparser.parser()[boost::bind(&ProgramGraphParser::seenforincr, this)] >> closebrace ) | closebrace[boost::bind(&ProgramGraphParser::seenemptyforincr, this)])
90  ) [boost::bind(&ProgramGraphParser::seenforstatement, this)]
91  >> expect_ifblock( ifblock[ boost::bind(&ProgramGraphParser::endforstatement, this) ]);
92 
93  ifstatement = (keyword_p("if")
94  >> condition
95  >> expect_then( keyword_p("then")[boost::bind(&ProgramGraphParser::seenifstatement, this)] )
96  >> expect_ifblock( ifblock[ boost::bind(&ProgramGraphParser::endifblock, this) ] )
97  >> !( keyword_p("else") >> expect_elseblock(ifblock) )
98  )[ boost::bind(&ProgramGraphParser::endifstatement, this) ];
99 
100  // ifblock is used for a group of statements or one statement (see also whilestatement)
101  // The semicolon after a single statement is optional, but do not emit an error if there is a semicolon before the else clause.
102  ifblock = ( ch_p('{') >> *line >> closecurly ) | ( statement >> !commonparser.notassertingeos );
103 
104  whilestatement =
105  (keyword_p("while")
106  >> condition )
107  [boost::bind(&ProgramGraphParser::seenwhilestatement, this)]
108  >> expect_ifblock( ifblock[ boost::bind(&ProgramGraphParser::endwhilestatement, this) ] );
109 
110  continuepart = keyword_p("continue")[ boost::bind( &ProgramGraphParser::seencontinue, this)];
111 
112  }
113 }
114 
#define keyword_p(word)
void seenfuncidentifier(iter_t begin, iter_t end)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:26