Related articles |
---|
Why ML/OCaml are good for writing compilers dwight@pentasoft.com (1998-07-28) |
Re: Why ML/OCaml are good for writing compilers aeb@saltfarm.bt.co.uk (Tony Bass) (1998-07-30) |
Re: Why ML/OCaml are good for writing compilers amitp@Theory.Stanford.EDU (Amit Patel) (1998-08-13) |
Re: Why ML/OCaml are good for writing compilers cfc@world.std.com (Chris F Clark) (1998-08-16) |
Re: Why ML/OCaml are good for writing compilers bonnardv@pratique.fr (Valentin Bonnard) (1998-08-16) |
From: | Tony Bass <aeb@saltfarm.bt.co.uk> |
Newsgroups: | comp.compilers |
Date: | 30 Jul 1998 23:18:49 -0400 |
Organization: | DSP downstreaming |
References: | 98-07-220 |
Keywords: | practice, functional |
> From: dwight@pentasoft.com (Dwight VandenBerghe)
> [...] So although when I am writing about "ML"
> I am writing about Ocaml, what I say also applies, I think, to SML/NJ.
> So here is an unordered list of language features that seems to me
> to make writing compilers a pleasure rather than a horrendous chore.
> [...]
I heartily agree (though noting that my own experience is more with
compiler-like things than compilers themselves). And besides all
these splendid basic things there is the possibility of using
demand-driven evaluation for parsing, in caml-light with the stream
extension, and I imagine similar things are possible in Ocaml and
SML/NJ.
With caml-light streams one can write a set of mutually recursive
routines matching stream patterns against the input, often very close
to a BNF grammar notation apart from syntactic noise and semantic
restrictions,
and galt = function
[< gconcat e1;
(parselist gconcat) e2
>] -> makeseqlist (e1::e2)
and gexpr = function
[< galt e1;
(parselist (function [< 'Hch `|`; galt e >] -> e)) e2;
(parseoption (function [< 'Hch `#`; 'Hint n >] -> n)) _
>] -> makealtlist e1 e2
with the right hand side after -> giving the semantic translation; and
the basic concepts of syntactic list and option of anything are
themselves defined in the same notation,
let rec parselist f = function
[< f x; s >] -> x :: (parselist f s)
| [< >] -> [];;
let parseoption f = function
[< f x >] -> Some x
| [< >] -> None;;
Another good tool in the tool-box.
--
# A E Bass Tel: (01473) 645305
# MLB 3/19, BT Laboratories e-mail: aeb@saltfarm.bt.co.uk
# Martlesham Heath, Ipswich, Suffolk, IP5 3RE
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.