CTTL on
SourceForge |
Download
Latest |
Documentation
Index |
Library
News |
CVS
Repository |
Other
Links |
Demonstrates semantic action implemented as member function template:
// sample code: action_handler.cpp // demonstrates semantic action implemented as member function template. #include "cttl/cttl.h" using namespace cttl; class handler { //... public: template< typename UniverseT > size_t action( UniverseT& universe_ ) { //... return universe_.first.offset(); } }; int main(int argc, char* argv[]) { input<> inp; // construct input object typedef const_edge<> universe_T; // type of parseable universe universe_T universe( new_edge( inp ) ); // construct universe handler sa_handler; // handler class implements // semantic actions // VC7.1 error C2784 workaround: typedef size_t ( handler::* action_T ) ( universe_T& ); size_t result = rule( sa_handler, action_T( &handler::action< universe_T > ) ).match( universe ); assert( result != std::string::npos ); // assert that match succeeded return 0; }
Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.