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: Sun, 23 Sep 2001 13:44:25 -0400 [thread overview]
Message-ID: <20010923134425.A28129@lakeland.eecs.harvard.edu> (raw)
In-Reply-To: <001501c1444c$a7b0a720$422aa8c0@housemarque.fi>; from vesa.karvonen@housemarque.fi on Sun, Sep 23, 2001 at 07:27:36PM +0300
On Sun, Sep 23, 2001 at 07:27:36PM +0300, Vesa Karvonen wrote:
> From: "Christian Lindig" <lindig@eecs.harvard.edu>
> > 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.
>
> This is basically the same technique that I have been using. The problem is
> that the map has to be global, because the only context passed to the lexer
> actions is the lexbuf.
You can pass the map to the lexer such that it does not has to be
global:
rule token = parse
eof { fun map -> P.EOF }
| ws+ { fun map -> token lexbuf map }
| tab { fun map -> tab lexbuf map; token lexbuf map }
| nl { fun map -> nl lexbuf map ; token lexbuf map }
| nl '#' { fun map -> line lexbuf map 0; token lexbuf map }
....
The lexer built from the above specification takes a lexbuf and map as
arguments.
> Furthermore, the records need to be manually removed (in order to save
> memory) after a file has been processed completely and the recorded
> connections for the file are no longer needed.
I assume that in a functional programming style without a global mutable
value the garbage collector will remove the map once I cannot access it
any longer.
> The basic idea was to put the token type definition into a separate
> module. Instead of two source files, you would have three source
> files:
>
> lexer.mll token.ml parser.mly
> In parser.mly there would be code that would tell ocamlyacc to look at
> token.ml for the token type.
Now you would have to keep the token type and the grammar up to dateup
to date manually. The parser generator also needs more informations
than just the token types: precedences, associativity, and return types
are tied to a token - where do you keep them?. I still think that
generating the token type from the grammar is the easiest way.
-- Christian
--
Christian Lindig Harvard University - DEAS
lindig@eecs.harvard.edu 33 Oxford St, MD 242, Cambridge MA 02138
phone: +1 (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
next prev parent reply other threads:[~2001-09-23 17:44 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
2001-09-23 16:27 ` Vesa Karvonen
2001-09-23 17:44 ` Christian Lindig [this message]
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=20010923134425.A28129@lakeland.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