9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: Composition of regexps (Was re: [9fans] regular expressions in plan9 different from the ones in unix?)
Date: Fri, 23 Feb 2007 12:33:24 -0500	[thread overview]
Message-ID: <ee9e417a0702230933y7d4717b2nd3c51e015f26aeed@mail.gmail.com> (raw)
In-Reply-To: <224a39ebca9aaa0370eb804cd59e6aac@plan9.jp>

Lex has three benefits:

 1) You don't have to write the lexer directly.
 2) What you do have to write is fairly concise.
 3) The resulting lexer is fairly efficient.

It has two main drawbacks:

 4) The input model does not always match your
 own program's input model, creating a messy interface.
 5) Once you need more than regular expressions,
 lexers written with state variables and such can get
 very opaque very fast.

Many on this list would argue that (1) and (2) do not
outweigh (4) and (5), instead suggesting that writing a
lexer by hand is not too difficult and ends up being
more maintainable than a lex spec in the long run.
And of course, for a well-written by-hand lexer,
you get to keep (3).

Creating new entry hooks in the regexp library doesn't
preserve (1), (2), or (3).  And if much of your time is
spent in lexical analysis (as Ken claimed was true for
the Plan 9 compilers), losing (3) is a big deal.
So that seems like not a very good replacement for lex.

All that said, lex has been used to write a lot of C
compilers, and can be used in that context without
running into much of (4) or (5).  Why not just use lex here?

Russ


  parent reply	other threads:[~2007-02-23 17:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-22 22:16 [9fans] regular expressions in plan9 different from the ones in unix? (at least linux) Folkert van Heusden
2007-02-22 23:17 ` Alberto Cortés
2007-02-22 23:21 ` William Josephson
2007-02-22 23:48   ` Russ Cox
2007-02-23  6:27     ` Composition of regexps (Was re: [9fans] regular expressions in plan9 different from the ones in unix?) Joel Salomon
2007-02-23  6:54       ` William K. Josephson
2007-02-23 13:34         ` Joel C. Salomon
2007-02-23 17:33       ` Russ Cox [this message]
2007-02-23 11:19     ` [9fans] regular expressions in plan9 different from the ones in unix? (at least linux) Gorka Guardiola
2007-02-23 12:12       ` erik quanstrom
2007-02-23 12:17         ` Gorka Guardiola
2007-02-23 13:02           ` erik quanstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee9e417a0702230933y7d4717b2nd3c51e015f26aeed@mail.gmail.com \
    --to=rsc@swtch.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).