Browse thread
ocamllex and python-style indentation
-
Andrej Bauer
- yoann padioleau
- Andreas Rossberg
- Martin Jambon
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | yoann padioleau <padator@w...> |
| Subject: | re: [Caml-list] 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) > 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 > >