caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* The lexer hack
@ 2009-11-10 14:42 Dario Teixeira
  2009-11-10 17:35 ` [Caml-list] " David Allsopp
  2009-11-14 16:20 ` Micha
  0 siblings, 2 replies; 7+ messages in thread
From: Dario Teixeira @ 2009-11-10 14:42 UTC (permalink / raw)
  To: caml-list

Hi,

I'm creating a parser for a LaTeX-ish language that features verbatim blocks.
To handle them I want to switch lexers on-the-fly, depending on the parsing
context.  Therefore, I need the state from the (Menhir generated) parser
to influence the lexing process (I believe this is called the "lexer hack"
in compiler lore).

Presently I am doing this by placing a module between the lexer and the
parser, listening in on the flow of tokens, and using a crude state machine
to figure out the parsing context.  This solution is however error-prone
and a bit wasteful, since I'm reimplementing by hand stuff that should be
the sole competence of the parser generator.

Anyway, since I'm sure this problem pops up often, does someone have any
alternative suggestions?  I would preferably keep Menhir, but I'll switch
if some other generator offers a better approach(*).

Thanks + best regards,
Dario Teixeira


(*) I've looked into Dypgen, and its partial actions may offer a way out.
    Does someone have any experience with those and with real-world usage
    of Dypgen in general?  (In other words, is it stable enough for
    production use?)






^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: The lexer hack
@ 2009-11-10 15:26 Jeff Shaw
  0 siblings, 0 replies; 7+ messages in thread
From: Jeff Shaw @ 2009-11-10 15:26 UTC (permalink / raw)
  To: caml-list

Dario,
You could write your lexers in Menhir and make them part of your 
grammar. I know this isn't a terribly easy solution but it would be 
elegant IMO.


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

end of thread, other threads:[~2009-11-14 19:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-10 14:42 The lexer hack Dario Teixeira
2009-11-10 17:35 ` [Caml-list] " David Allsopp
2009-11-10 20:02   ` Dario Teixeira
2009-11-14 16:20 ` Micha
2009-11-14 18:08   ` Dario Teixeira
2009-11-14 19:09   ` Goswin von Brederlow
2009-11-10 15:26 Jeff Shaw

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