Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

functor.cpp


SourceForge.net Logo     CTTL on    
    SourceForge    
    Download    
    Latest    
    Documentation    
    Index    
    Library    
    News    
    CVS    
    Repository    
   Other    
   Links    

Program defining a function object that implements grammar production rule.

// sample code: functor.cpp
// demonstrates function object rule_char used inside grammar rule.

#include "cttl/cttl.h"

using namespace cttl;

class rule_char : public std::unary_function< const_edge<>, size_t >{
    char m_char;

public:
    rule_char( char char_ )
        :   m_char( char_ )
    {}

    size_t operator() ( const_edge<>& edge_ ) const
    {
        return symbol( m_char ).match( edge_ );
    }
};


int main()
{
    input<> inp( "ZZZA" );
    const_edge<> U( new_edge( inp ) );
    char L = 'Z';
    rule_char R( L );           // construct grammar rule for a single character
    // the following statement describes grammar production rule R+ 'A'
    // and evaluates this grammar against specified universe by
    // invoking "match()" evaluation method:
    size_t P = ( +rule( R ) + 'A' ).match( U );
    assert( P == 0 );           // assert match found at the beginning of U
    assert( U.length() == 0 );  // make sure universe is fully consumed
    return 0;
}



Copyright © 1997-2006 Igor Kholodov mailto:cttl@users.sourceforge.net.

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.


Generated on Thu Nov 2 17:44:55 2006 for Common Text Transformation Library by  doxygen 1.3.9.1