caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Testing lexers and parsers
@ 2007-02-27 15:29 Joel Reymont
  2007-02-27 15:42 ` [Caml-list] " Denis Bueno
  0 siblings, 1 reply; 5+ messages in thread
From: Joel Reymont @ 2007-02-27 15:29 UTC (permalink / raw)
  To: caml-list

Folks,

I'm trying to incrementally develop a translator using a test-driven  
approach. I figure I can write a bunch of tests for small chunks of  
functionality to structurally test expected AST against produced.

Once I get to testing the parsing of whole files I think I can print  
the AST I produce into a file and test this against a target file  
with the correct printed AST. I can probably run 'cmp' to make sure  
my files match. This would not be a structural comparison, though,  
and would be highly dependent on white space which does not strike me  
as ideal.

Is there a better way to accomplish this while still using structural  
comparison of ASTs?

Should I try to read my target AST into OCaml, for example? Should I  
create a bunch of "target AST" modules with functions that return my  
target AST?

How does everyone else approach testing of lexers and parsers?

	Thanks, Joel

--
http://wagerlabs.com/






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

* Re: [Caml-list] Testing lexers and parsers
  2007-02-27 15:29 Testing lexers and parsers Joel Reymont
@ 2007-02-27 15:42 ` Denis Bueno
  2007-02-27 15:46   ` Joel Reymont
  0 siblings, 1 reply; 5+ messages in thread
From: Denis Bueno @ 2007-02-27 15:42 UTC (permalink / raw)
  To: Joel Reymont; +Cc: caml-list

On 2/27/07, Joel Reymont <joelr1@gmail.com> wrote:
> Is there a better way to accomplish this while still using structural
> comparison of ASTs?
>
> Should I try to read my target AST into OCaml, for example? Should I
> create a bunch of "target AST" modules with functions that return my
> target AST?

I recently had to deal with this problem. I ended up testing the
parsing/printing by parsing a file, printing it out, and parsing the
print-out, and then making sure the ASTs built up are structurally
identical (modulo any position fields you might have lurking in your
ASTs).

I have to say, ever since I did this testing, I have had no problems
with my parser.

-Denis


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

* Re: [Caml-list] Testing lexers and parsers
  2007-02-27 15:42 ` [Caml-list] " Denis Bueno
@ 2007-02-27 15:46   ` Joel Reymont
       [not found]     ` <6dbd4d000702270810h16ea3308k49dfcf7e5a479ecb@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Joel Reymont @ 2007-02-27 15:46 UTC (permalink / raw)
  To: Denis Bueno; +Cc: caml-list


On Feb 27, 2007, at 3:42 PM, Denis Bueno wrote:

> I recently had to deal with this problem. I ended up testing the
> parsing/printing by parsing a file, printing it out, and parsing the
> print-out,

Are you printing out the AST to make sure you can reproduce the  
original file you parsed?

	Thanks, Joel

--
http://wagerlabs.com/






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

* Re: [Caml-list] Testing lexers and parsers
       [not found]     ` <6dbd4d000702270810h16ea3308k49dfcf7e5a479ecb@mail.gmail.com>
@ 2007-02-27 16:11       ` Denis Bueno
  2007-02-27 16:20         ` konrad
  0 siblings, 1 reply; 5+ messages in thread
From: Denis Bueno @ 2007-02-27 16:11 UTC (permalink / raw)
  To: Joel Reymont; +Cc: OCaml Mailing List

[Meant to send to the list the first time. Sorry for the dupe.]

On 2/27/07, Denis Bueno <dbueno@gmail.com> wrote:
> On 2/27/07, Joel Reymont <joelr1@gmail.com> wrote:
> > Are you printing out the AST to make sure you can reproduce the
> > original file you parsed?

Yes. I wanted to make sure my AST-printing functions would print
correct source code in the source language. This makes it very easy to
inspect AST fragments.

-Denis


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

* Re: [Caml-list] Testing lexers and parsers
  2007-02-27 16:11       ` Denis Bueno
@ 2007-02-27 16:20         ` konrad
  0 siblings, 0 replies; 5+ messages in thread
From: konrad @ 2007-02-27 16:20 UTC (permalink / raw)
  To: Denis Bueno; +Cc: Joel Reymont, OCaml Mailing List


I actually attended a project in university on writing a C compiler (written in Java) and we printed out XML code for debugging, that represented the AST. That was a real benefit cause you can still see the structure of the AST in the XML tree. It is even easy to do that - one tree traversal is enough.

chris

On Tue, 27 Feb 2007 11:11:09 -0500, "Denis Bueno" <dbueno@gmail.com> wrote:
> [Meant to send to the list the first time. Sorry for the dupe.]
> 
> On 2/27/07, Denis Bueno <dbueno@gmail.com> wrote:
>> On 2/27/07, Joel Reymont <joelr1@gmail.com> wrote:
>> > Are you printing out the AST to make sure you can reproduce the
>> > original file you parsed?
> 
> Yes. I wanted to make sure my AST-printing functions would print
> correct source code in the source language. This makes it very easy to
> inspect AST fragments.
> 
> -Denis
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs



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

end of thread, other threads:[~2007-02-27 16:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-27 15:29 Testing lexers and parsers Joel Reymont
2007-02-27 15:42 ` [Caml-list] " Denis Bueno
2007-02-27 15:46   ` Joel Reymont
     [not found]     ` <6dbd4d000702270810h16ea3308k49dfcf7e5a479ecb@mail.gmail.com>
2007-02-27 16:11       ` Denis Bueno
2007-02-27 16:20         ` konrad

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