caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] debugging an ocamlyacc parser
@ 2001-10-23  2:14 Rafael 'Dido' Sevilla
  2001-10-23  5:42 ` Mattias Waldau
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rafael 'Dido' Sevilla @ 2001-10-23  2:14 UTC (permalink / raw)
  To: Caml List

Well, while my current ocamlyacc parser seems to be working pretty well,
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
goes through as it receives tokens from the lexer, so along with the
generated y.output file I can see how it's working (or not working as
the case may be).

-- 
Rafael R. Sevilla <sevillar@team.ph.inter.net>   +63(2)   8177746 ext. 8311
Programmer, Inter.Net Philippines                +63(917) 4458925
http://dido.engr.internet.org.ph/                OpenPGP Key ID: 0x5CDA17D8
-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [Caml-list] debugging an ocamlyacc parser
  2001-10-23  2:14 [Caml-list] debugging an ocamlyacc parser Rafael 'Dido' Sevilla
@ 2001-10-23  5:42 ` Mattias Waldau
  2001-10-23  7:51 ` Hendrik Tews
  2001-10-24 14:53 ` Xavier Leroy
  2 siblings, 0 replies; 4+ messages in thread
From: Mattias Waldau @ 2001-10-23  5:42 UTC (permalink / raw)
  To: Rafael 'Dido' Sevilla, Caml List

I normally test the lexer and the parser separately.

The lexer is easy to test using a function like:

  let lexbuf = Lexing.from_channel file_channel in
  let result = ref [] in
  try
    while true do
      let next_token = Dtd_lexer.token lexbuf in
      result := next_token :: !result;
      if debug_lexer then Dtd_types.print next_token;
      if next_token = Dtd_types.EOF then raise Not_found
    done;
    List.rev (!result)
  with Not_found -> List.rev (!result)

For debugging the parser I set the -v flag to ocamlyacc and look at the
.parser file

/mattias

> -----Original Message-----
> From: owner-caml-list@pauillac.inria.fr
> [mailto:owner-caml-list@pauillac.inria.fr]On Behalf Of Rafael 'Dido'
> Sevilla
> Sent: Tuesday, October 23, 2001 4:15 AM
> To: Caml List
> Subject: [Caml-list] debugging an ocamlyacc parser
>
>
> Well, while my current ocamlyacc parser seems to be working pretty well,
> 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
> goes through as it receives tokens from the lexer, so along with the
> generated y.output file I can see how it's working (or not working as
> the case may be).
>
> --
> Rafael R. Sevilla <sevillar@team.ph.inter.net>   +63(2)   8177746
> ext. 8311
> Programmer, Inter.Net Philippines                +63(917) 4458925
> http://dido.engr.internet.org.ph/                OpenPGP Key ID:
> 0x5CDA17D8
> -------------------
> 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

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] debugging an ocamlyacc parser
  2001-10-23  2:14 [Caml-list] debugging an ocamlyacc parser Rafael 'Dido' Sevilla
  2001-10-23  5:42 ` Mattias Waldau
@ 2001-10-23  7:51 ` Hendrik Tews
  2001-10-24 14:53 ` Xavier Leroy
  2 siblings, 0 replies; 4+ messages in thread
From: Hendrik Tews @ 2001-10-23  7:51 UTC (permalink / raw)
  To: Caml List

Hi,

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
    end;;

a typical rule looks like 

    signaturetype:
	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
    end

and 

     | '='			{ 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
switch.

Bye,

Hendrik
-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] debugging an ocamlyacc parser
  2001-10-23  2:14 [Caml-list] debugging an ocamlyacc parser Rafael 'Dido' Sevilla
  2001-10-23  5:42 ` Mattias Waldau
  2001-10-23  7:51 ` Hendrik Tews
@ 2001-10-24 14:53 ` Xavier Leroy
  2 siblings, 0 replies; 4+ messages in thread
From: Xavier Leroy @ 2001-10-24 14:53 UTC (permalink / raw)
  To: Rafael 'Dido' Sevilla; +Cc: Caml List

> Well, while my current ocamlyacc parser seems to be working pretty well,
> 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
> goes through as it receives tokens from the lexer, so along with the
> generated y.output file I can see how it's working (or not working as
> the case may be).

There is such a debugging mode in the pushdown automaton used to
execute ocamlyacc parsers, but it is not easily accessible.

You need to build the "debug" version of the bytecode interpreter (cd
runtime ; make ocamlrund), then run your bytecode executable with
"ocamlrund -P myprog".

You then get a trace of shift and reduce actions; tokens read are also
printed, but in such a low-level format that it's nearly useless...

I agree this tracing facility should be made better at some point,
although printing tokens correctly is difficult in general.

- Xavier Leroy
-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-24 16:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-23  2:14 [Caml-list] debugging an ocamlyacc parser Rafael 'Dido' Sevilla
2001-10-23  5:42 ` Mattias Waldau
2001-10-23  7:51 ` Hendrik Tews
2001-10-24 14:53 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).