<<< Integer tree | Lambda Home | >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
CTTL grammars support multiple tracing and debugging facilities. Furthermore, to simplify the debugging of in-line semantic actions, the lambda library provides additional levels of trace output to visualize the execution of lambda expressions at run-time. The messages are sent to the CTTL_UNILOG_STREAM stream (refer to CTTL documentation for the detailed description.) If CTTL_UNILOG_STREAM macro is undefined, the library uses std::cout stream. Trace messages are turned on by a combination of one or more of the following trace-level macros:
Program debugging_n_tracing.cpp prints tracing messages when tracing mode is on. The code shows how CTTL_LAMBDA_TRACE can be used to trace the source code location:
// debugging_n_tracing.cpp // Program demonstrates lambda tracing macros. #define CTTL_TRACE_RULES // automatically turns lambda tracing on #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main(int argc, char* argv[]) { CTTL_TRACE_DEPOSIT_JUSTIFY(); CTTL_TRACE_DEPOSIT_TEXT( "BEGIN" ); CTTL_TRACE_DEPOSIT_TEXT( 123 ); CTTL_TRACE_DEPOSIT_TEXT( std::endl ); ( CTTL_LAMBDA_TRACE( "File: " __FILE__ " Line:" CTTL_QUOTED_EXPRESSION( __LINE__ ) ) ).evaluate(); CTTL_TRACE_DEPOSIT_JUSTIFY(); CTTL_TRACE_DEPOSIT_TEXT( "END" ); return 0; } /*Output: BEGIN123 ( ++ "File: .\main.cpp Line:18" 0 ) END */
These two macros are in-line assertion and tracing facilities for lambda expressions.
The program lambda_assert.cpp implements a simple grammar rule along with the two lambda-based boolean switch parsers. The CTTL_LAMBDA_TRACE macro prints the message on the screen. It has no effect on the grammar evaluation flow:
CTTL_LAMBDA_TRACE( "checkpoint" )
Another macro,
CTTL_LAMBDA_ASSERT( scalar( !"bad input" ) )
always fails, since the result of logical expression !"bad input" is zero.
// lambda_assert.cpp // Program demonstrates lambda binary switch parser // and CTTL_LAMBDA_ASSERT macro. //#define NDEBUG #define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main(/*int argc, char* argv[]*/) { std::string inp = "abc"; const_edge<> substring( inp ); ( CTTL_LAMBDA_TRACE( "checkpoint" ) | symbol( "xyz" ) | CTTL_LAMBDA_ASSERT( scalar( !"bad input" ) ) ).match( substring ); return 0; }
If NDEBUG is defined, CTTL_LAMBDA_ASSERT has no effect, and is being resolved as integral literal 1.
Otherwise, if tracing mode is enabled, (for example, when CTTL_TRACE_EVERYTHING is defined), the program generates output
--------------------@abc?{| 0-3 --------------------@abc? {| 0-3 --------------------@abc? {u 0-3 ( ++ "checkpoint" 0 ) } ~~~~~~~~~~~~~~~~~~~~~~~@~ T 0-3 FAIL xyz ~~~~~~~~~~~~~~~~~~~~~~~@~ | 0-3 FAIL } --------------------@abc? {b 0-3 ( || 0 ( -- "Assertion failed: scalar( !"bad input" ) in ./main.cpp:20" Assertion failed: CTTL_LAMBDA_ASSERT_, file ./lambda/xst_literal_translator.h, line 110
and then stops the execution on a false assert.
Copyright © 1997-2009 Igor Kholodov mailto:cttl@users.sourceforge.net.
Permission to copy 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.
<<< Integer tree | Lambda Home | >>> |