[erlang-questions] Using Leex vs rolling your own lexer

Robert Virding <>
Wed Dec 19 02:29:00 CET 2007


On 18/12/2007, Hasan Veldstra <> wrote:
>
>
> > No OTP code uses Leex it seems. All apps and libraries roll their own
> > lexer.
> >
> > It's very easy in Erlang to roll your own lexer but any particular
> > reason why Leex is not used more often?


Two reasons to use leex:

1. If your tokens can be described by regular expressions then reading a
leex file is much clearer and easier than writing code.

2. The resultant scanner is re-entrant which fits i/o. This is not that
difficult to do by yourself but why bother.

The leex generated scanner is relatively efficient but you can do better
yourself.

Perhaps because it's old and unsupported by anyone? (It doesn't even
> have a homepage.) That coupled with the ease of writing a lexer is
> probably the reason.


This is the main reason not to use leex.

I've used Leex quite a lot though, and it works fine. There are a few
> minor annoyances, but no show-stoppers. (I might even get round to
> fixing them at some point...)


Thank you, I wrote it. :-) There is a version on trapexit that doesn't have
a manual but at least an example file. :-) Which is almost the erlang token
syntax. It needs a bit of a cleanup and perhaps reworking the input file
format. There is a bug which sometimes occurs. It could quite easily be
modified to work directly on binaries.

One of these days I will get around to it. Now I am fixing a lisp based
syntax for Erlang. Perhaps not useful but fun. And easy to make a macro
preprocessor for.

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071219/ac20df6b/attachment.html>


More information about the erlang-questions mailing list