Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Re: [Caml-announce] OCamldoc
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-10-12 (08:29)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] Re: [Caml-announce] OCamldoc
Xavier Leroy wrote:
> I've been
> hacking Lex and Yacc for years, still I do not have the slightest idea
> on how to take indentation into account in a Lex/Yacc parser...

What you can do is, write a standard lexer and a (more or less, see
below) standard parser. In addition, you write a lexer wrapper that does
several things:

- calculate line/column information from the absolute character position
  for every token (e.g. by incrementally co-traversing the input),
- maintain a stack of current indentation levels,
- insert some appropriate virtual tokens on line and indentation level

The grammar implemented by the parser contains occurences of these
virtual tokens at the right places. In the approach taken by Haskell
(don't know about Python) you do not even need to think about that,
since you only insert standard tokens. And if you have a lexer that is
able to calculate lines/columns by itself, everything becomes very easy.

Andreas Rossberg,

"Computer games don't affect kids; I mean if Pac Man affected us
 as kids, we would all be running around in darkened rooms, munching
 magic pills, and listening to repetitive electronic music."
 - Kristian Wilson, Nintendo Inc.
Bug reports:  FAQ:
To unsubscribe, mail  Archives: