English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
ocamllex and python-style indentation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-06-11 (12:57)
From: Andrej Bauer <andrej.bauer@a...>
Subject: ocamllex and python-style indentation
My parsing powers are not sufficient to easily come up with
lexer/parser for a simple language that uses python-style indentation
and newline rules. Does anyone have such a thing lying around, written
in ocamllex/yacc or menhir? I would appreciate a peek to see how
you've dealt with it.

For example, suppose we want just a very simple fragment of Python
involving True, False, conditional statements, variables, and
assignments, such as:

if True:
    x = 3
    y = (2 +
      4 + 5)
    x = 5
    if False:
        x = 8
        z = 2

How would I go about writing a lexer/parser for such a thing in ocaml?