From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id C80F7BC37 for ; Thu, 11 Jun 2009 15:12:58 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtwFAH+fMErB/BfEcGdsb2JhbACOIIofAQwIDQcSA7ZVhAoF X-IronPort-AV: E=Sophos;i="4.42,202,1243807200"; d="scan'208";a="29323632" Received: from smtp1f.orange.fr ([193.252.23.196]) by mail3-smtp-sop.national.inria.fr with ESMTP; 11 Jun 2009 15:12:58 +0200 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf1f02.orange.fr (SMTP Server) with ESMTP id E6B41700008F; Thu, 11 Jun 2009 15:12:57 +0200 (CEST) Received: from wwinf1f20 (wwinf1f20 [10.232.36.44]) by mwinf1f02.orange.fr (SMTP Server) with ESMTP id DCA9F7000081; Thu, 11 Jun 2009 15:12:57 +0200 (CEST) X-ME-UUID: 20090611131257903.DCA9F7000081@mwinf1f02.orange.fr From: yoann padioleau Reply-To: yoann padioleau To: Andrej Bauer , caml-list@inria.fr Message-ID: <27263828.237520.1244725977807.JavaMail.www@wwinf1f20> In-Reply-To: <7d8707de0906110557n6a1511a2k9f4f00827f954cb6@mail.gmail.com> References: <7d8707de0906110557n6a1511a2k9f4f00827f954cb6@mail.gmail.com> Subject: re: [Caml-list] ocamllex and python-style indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [98.212.173.155] X-Wum-Nature: EMAIL-NATURE X-WUM-FROM: |~| X-WUM-TO: |~||~| X-WUM-REPLYTO: |~| Date: Thu, 11 Jun 2009 15:12:57 +0200 (CEST) X-Spam: no; 0.00; ocamllex:01 lexer:01 parser:01 ocamllex:01 lexer:01 parser:01 ocaml:01 lexing:01 tokens:01 tokens:01 andrej:01 beginner's:01 ocaml:01 bug:01 beginners:01 > 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) > else: > x = 5 > if False: > x = 8 > z = 2 > > How would I go about writing a lexer/parser for such a thing in ocaml? I guess you could interpose a function between lexing and parsing that works on the tokens and position information of those tokens to insert some new extra tokens that will then make the job of the parser easier. For instance you could add some "virtual" ';' at the end of each line except when you are in a parenthesized stuff. > > Andrej > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >