caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christian Lindig <lindig@eecs.harvard.edu>
To: Vesa Karvonen <vesa.karvonen@housemarque.fi>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] On ocamlyacc and ocamllex
Date: Sat, 22 Sep 2001 21:10:13 -0400	[thread overview]
Message-ID: <20010922211013.A580@eecs.harvard.edu> (raw)
In-Reply-To: <000b01c143aa$d5218690$422aa8c0@housemarque.fi>

On Sun, Sep 23, 2001 at 12:09:14AM +0300, Vesa Karvonen wrote:
> I would like to make it so that the lexer would record the positions
> of line breaks so that I could directly give line number and column
> information in error messages.

I agree that more flexible lexer and parser generators would be nice and
have myself lobbied for them in the past. On the other hand I have
always found my way with the existing ones which probably is the reason
that we still use them. 

The particular problem can be solved outside of Lex and Yacc: in the
Quick C-- compiler we have a mutable Sourcemap.map data type that
records the connection between character positions and
(file,line,column) triples. The scanner call a function Sourcemap.nl for
every newline that it encounters and to build up the connection. Later
the map can be used to find the (file,line,column) position for every
character offset. This method has the advantage that it can deal with
input streams that are created from different source files using a
pre-processor. You can find the module as part of the ocamlerror tool
that annotates stack traces with source code positions:

http://www.eecs.harvard.edu/~lindig/software/download/ocamlerror.tar.gz

> Another issue with ocamllex and ocamlyacc (and lex/flex and
> yacc/bison) is that the dependencies between the generated lexer and
> parser are not quite optimal. Currently the generated lexer is
> dependent on the parser, because the parser generates the token type.
> This means that each time the grammar is modified, but not the token
> definitions, the lexer is recompiled. This could be avoided by making
> it so that the token type is defined in a separate module.

This is a general problem with make: when you edit a comment, a file is
touched and all dependent files must be recompiled. Knowing nothing
about OCaml, Make must assume that a touched file has changed in a
significant way. You can help Make out by comparing files explicitly
(untested - you get the idea): foo.mli is only updated, if the token
type has changed.

foo.mli foo.ml:         bar.mly
                        ocamlyacc bar.mly
                        cp bar.ml  foo.ml
                        cmp -s bar.mli foo.mli || cp bar.mli foo.mli 

-- Christian    

-- 
Christian Lindig          Harvard University - EECS 
lindig@eecs.harvard.edu   33 Oxford St, MD 242, Cambridge MA 02138
phone: (617) 496-7157     http://www.eecs.harvard.edu/~lindig/   
                          
-------------------
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


  reply	other threads:[~2001-09-23  1:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-22 21:09 Vesa Karvonen
2001-09-23  1:10 ` Christian Lindig [this message]
2001-09-23 16:27   ` Vesa Karvonen
2001-09-23 17:44     ` Christian Lindig
2001-09-23 19:32       ` Vesa Karvonen
2001-09-23 20:09         ` Christian Lindig
2001-09-23 20:51           ` Vesa Karvonen
2001-10-22 17:09           ` John Max Skaller
2001-10-22 16:47       ` John Max Skaller
2001-09-24  1:05 ` Christian RINDERKNECHT
2001-09-24 11:17   ` Vesa Karvonen
2001-10-22 17:24     ` John Max Skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010922211013.A580@eecs.harvard.edu \
    --to=lindig@eecs.harvard.edu \
    --cc=caml-list@inria.fr \
    --cc=vesa.karvonen@housemarque.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).