Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
changes.

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, rossberg@ps.uni-sb.de

"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: 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