English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] debugging an ocamlyacc parser
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-10-23 (07:51)
From: Hendrik Tews <tews@t...>
Subject: Re: [Caml-list] debugging an ocamlyacc parser

Rafael 'Dido' Sevilla writes:
   Date: Tue, 23 Oct 2001 10:14:42 +0800
   Subject: [Caml-list] debugging an ocamlyacc parser
   I'm just wondering if there's a debug mode available for
   ocamlyacc-generated parsers, like the debugging mode that Bison uses
   when you do a #define YYDEBUG, printing out all the states the parser

I was also missing the YYDEBUG. My workaround looks as follows:

In the header of grammar.mly:

  let d s =
    if debug_level _DEBUG_PARSER
    then begin
      prerr_string ("REDUCE " ^ s ^ "\n");
      flush stderr

a typical rule looks like 

	TYPE ID	 		{ d "signaturetype";
				  do_sig_type_decl $2;

The lexer uses the same schema:

  let d s =
    if debug_level _DEBUG_LEXER
    then begin
      prerr_string ("SHIFT " ^ s ^ "\n");
      flush stderr


     | '='			{ d "Equal"; 
				  EQUAL }

_DEBUG_PARSER and _DEBUG_LEXER are constants and the return value
of the debug_level function can be influenced via a command line


Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr