[mercury-users] Mercury example programs

Ralph Becket rafe at cs.mu.OZ.AU
Fri Jun 17 14:32:18 AEST 2005


brogoff, Thursday, 16 June 2005:
> 
> xml.m uses parser combinators. Is that the idiomatic Mercury approach? I
> ask because even though I've seen parser combinator libraries for ML, in
> my experience they aren't used; rather lex/yacc or (in OCaml) stream pattern
> matching (just a nice syntax for hand coded recursive descent parsing)
> is used.

No, that's just the approach Tom took when he wrote xml.m.

Recursive descent parsers are very easy to write.  Indeed, there is even
syntactic sugare for just this purpose: if you look up DCG syntax in the
reference manual and search for examples on the web (it's something
Mercury borrows from Prolog).

> lex.m is a library module rather than a lexer generator. Yet there is a
> yacc like parser generator, moose.

Coming Real Soon Now are elk and caribou, which are Mercury equivalents
of yacc and lex.  moose is fine, but apparently has a few awkwardnesses
that made it easier to start a new design from scratch.

> > If you have specific examples in mind, I'd like to hear about them.  I
> > think the tutorial could be usefully extended with some more realistic
> > example programs.
> 
> I'll try and come up with some data munging examples in the field that
> I work in (EDA) as I develop familiarity with Mercury, but you're
> certainly right about extending the tutorial. Mercury is unfamiliar to those
> without a Prolog background, so that tutorial is where many of us will go
> first.

Actually, Mercury is unfamiliar to those *with* a Prolog background!  I
think Mercury is more like ML without the imperative parts, augmented
with ground unification and backtracking from Prolog.

> As a specific tutorial example, I am partial to ones that include a
> simple or medium complexity recursive descent parser. Interpreters are
> great, as they are simple enough to be easily understood, invoke
> enough of the IO features of the language to be broadly interesting,
> and they provide a skeletal framework for modification. The parser in
> xml.m is a nice example, but I wonder if the parser combinator
> approach is what the Mercury programmer in the trenches would use.

Well, I've dabbled with Parser combinators, but recent experiments
indicate to me that recursive descent is the right tool in most
situations.

-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list