The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Larry McVoy <lm@mcvoy.com>
To: Tony Finch <dot@dotat.at>, Larry McVoy <lm@mcvoy.com>,
	The Eunuchs Hysterical Society <tuhs@tuhs.org>
Subject: Re: [TUHS] v7 K&R C
Date: Sat, 16 May 2020 17:35:59 -0700	[thread overview]
Message-ID: <20200517003559.GC19945@mcvoy.com> (raw)
In-Reply-To: <20200516235308.icuQH%steffen@sdaoden.eu>

On Sun, May 17, 2020 at 01:53:08AM +0200, Steffen Nurpmeso wrote:
> Tony Finch wrote in
> <alpine.DEB.2.20.2005142316170.3374@grey.csi.cam.ac.uk>:
>  |Larry McVoy <lm@mcvoy.com> wrote:
>  |>
>  |> It's got some perl goodness, regexps are part of the syntax, ....
>  |
>  |I got into Unix after perl and I've used it a lot. Back in the 1990s I saw
>  |Henry Spencer's joke that perl was the Swiss Army Chainsaw of Unix, as a
>  |riff on lex being its Swiss Army Knife. I came to appreciate lex
>  |regrettably late: lex makes it remarkably easy to chew through a huge pile
>  |of text and feed the pieces to some library code written in C. I've been
>  |using re2c recently (http://re2c.org/), which is differently weird than
>  |lex, though it still uses YY in all its variable names. It's remarkable
>  |how much newer lexer/parser generators can't escape from the user
>  |interface of lex/yacc. Another YY example: http://www.hwaci.com/sw/lemon/
> 
> P.S.: i really hate automated lexers.  I never ever got used to
> use them.  For learning i once tried to use flex/bison, but
> i failed really hard.  I like that blood, sweat and tears thing,
> and using a lexer seems so shattered, all the pieces.  And i find
> them really hard to read.

They are not bad if you are good at it.  One of my guys has a PhD in
compilers and he's good at it.

They are not good at performance.  BitKeeper has an extensive printf
like (sort of, different syntax) language that can be used to customize
log output.  Rob originally did all that in flex/bison but the performance
started to hurt so he rewrote it all:

/*
 * This is a recursive-descent parser that implements the following
 * grammar for dspecs (where [[...]] indicates an optional clause
 * and {{...}} indicates 0 or more repetitions of):
 *
 * <stmt_list> -> {{ <stmt> }}
 * <stmt>      -> $if(<expr>){<stmt_list>}[[$else{<stmt_list>}]]
 *             -> $unless(<expr>){<stmt_list>}[[$else{<stmt_list>}]]
 *             -> $each(:ID:){<stmt_list>}
 *             -> ${<num>=<stmt_list>}
 *             -> <atom>
 * <expr>      -> <expr2> {{ <logop> <expr2> }}
 * <expr2>     -> <str> <relop> <str>
 *             -> <str>
 *             -> (<expr>)
 *             -> !<expr2>
 * <str>       -> {{ <atom> }}
 * <atom>      -> char
 *             -> escaped_char
 *             -> :ID:
 *             -> (:ID:)
 *             -> $<num>
 * <logop>     -> " && " | " || "
 * <relop>     -> "=" | "!=" | "=~"
 *             -> " -eq " | " -ne " | " -gt " | " -ge " | " -lt " | " -le "
 *
 * This grammar is ambiguous due to (:ID:) loooking like a
 * parenthesized sub-expression.  The code tries to parse (:ID:) first
 * as an $each variable, then as a regular :ID:, then as regular text.
 *
 * Note that this is broken: $if((:MERGE:)){:REV:}
 *
 * The following procedures can be thought of as implementing an
 * attribute grammar where the output parameters are synthesized
 * attributes which hold the expression values and the next token
 * of lookahead in some cases.  It has been written for speed.
 *
 * NOTE: out==0 means evaluate but throw away.
 *
 * Written by Rob Netzer <rob@bolabs.com> with some hacking
 * by wscott & lm.
 */

That stuff screams perf wise.



  parent reply	other threads:[~2020-05-17  0:36 UTC|newest]

Thread overview: 153+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-25  1:59 Adam Thornton
2020-04-25  2:37 ` Charles Anthony
2020-04-25  2:47   ` Adam Thornton
2020-04-25  2:51     ` Rob Pike
2020-04-25  2:54       ` Rob Pike
2020-04-25  3:04         ` Larry McVoy
2020-04-25  3:30           ` Clem Cole
2020-04-25  3:43             ` Larry McVoy
2020-04-25  3:54               ` Jon Steinhart
2020-04-25 11:44                 ` Michael Kjörling
2020-04-25 13:17             ` Dan Cross
2020-05-11  0:28         ` scj
2020-05-11  0:32           ` Rob Pike
2020-05-11  0:57             ` Larry McVoy
2020-05-11 17:32               ` Greg A. Woods
2020-05-11 18:25                 ` Paul Winalski
2020-05-11 18:37                   ` Clem Cole
2020-05-11 19:12                     ` Paul Winalski
2020-05-11 19:57                       ` joe mcguckin
2020-05-11 20:25                         ` Larry McVoy
2020-05-12 17:23                           ` Paul Winalski
2020-05-12 17:35                             ` ron
2020-05-12 17:42                               ` Larry McVoy
2020-05-12 18:36                               ` Paul Winalski
2020-05-13 23:36                             ` Dave Horsfall
2020-05-14  0:42                               ` John P. Linderman
2020-05-14  2:44                                 ` Rich Morin
2020-05-14  3:09                                   ` Charles Anthony
2020-05-14 12:27                                     ` ron
2020-05-14 12:27                                     ` ron
2020-05-14 12:27                                     ` ron
2020-05-14  7:38                                   ` Dave Horsfall
2020-05-14 12:25                                     ` ron
2020-05-14 17:13                                   ` Paul Winalski
2020-05-14 17:21                                 ` Larry McVoy
2020-05-17 16:34                                   ` Derek Fawcus
2020-05-14  4:21                               ` Greg A. Woods
2020-05-14  4:40                                 ` Warner Losh
2020-05-14 17:32                               ` Larry McVoy
2020-05-14 22:32                                 ` Tony Finch
2020-05-16 23:53                                   ` Steffen Nurpmeso
2020-05-16 23:59                                     ` [TUHS] v7 K&R C [really lexers] Jon Steinhart
2020-05-17  0:04                                       ` Brantley Coile
2020-05-17  1:23                                         ` Warner Losh
2020-05-17  1:36                                           ` Brantley Coile
2020-06-13 21:24                                           ` scj
2020-06-14  8:47                                             ` arnold
2020-06-14 12:52                                             ` Richard Salz
2020-06-14 14:03                                               ` Ralph Corderoy
2020-06-14 14:26                                                 ` arnold
2020-06-14 14:48                                                   ` Ralph Corderoy
2020-06-15  1:12                                                     ` Warren Toomey
2020-06-15  1:29                                                       ` Warren Toomey
2020-06-15  6:06                                                         ` arnold
2020-05-17 16:31                                       ` Paul Winalski
2020-05-17  0:35                                     ` Larry McVoy [this message]
2020-05-11 18:37                   ` [TUHS] v7 K&R C Larry McVoy
2020-05-11  2:08           ` Lawrence Stewart
2020-05-11 11:36           ` Michael Kjörling
2020-04-25  3:37       ` Dave Horsfall
2020-04-27 13:19       ` Tony Finch
2020-04-25  2:50   ` Adam Thornton
2020-04-25  5:59     ` Lars Brinkhoff
2020-04-25 13:11 Noel Chiappa
2020-04-25 13:18 ` Rob Pike
2020-04-25 14:57   ` Warner Losh
2020-04-25 18:03   ` Noel Chiappa
2020-04-25 20:11     ` Michael Kjörling
2020-04-25 21:27       ` Brian L. Stuart
2020-04-26  0:07     ` emanuel stiebler
2020-04-26  0:54     ` Rob Pike
2020-04-26 19:37     ` Derek Fawcus
2020-04-26 20:10       ` Derek Fawcus
2020-04-26 21:59         ` Rich Morin
2020-04-26 22:38         ` Noel Hunt
2020-04-26 23:57         ` Nemo Nusquam
2020-04-27  3:38           ` Rob Pike
2020-04-25 13:35 ` Hellwig Geisse
2020-04-25 13:59   ` Richard Salz
2020-04-25 19:01   ` Brian L. Stuart
2020-04-25 20:07     ` Michael Kjörling
2020-04-25 21:34       ` Brian L. Stuart
2020-04-26  6:40     ` arnold
2020-04-25 19:41 Noel Chiappa
2020-04-25 20:27 ` Steffen Nurpmeso
2020-04-27 17:45 Noel Chiappa
2020-04-27 17:56 ` Richard Salz
2020-04-27 18:02 ` Brantley Coile
2020-04-27 18:47 ` Derek Fawcus
     [not found] <mailman.1.1589421601.13778.tuhs@minnie.tuhs.org>
2020-05-14  3:02 ` Paul McJones
2020-05-14 17:08   ` Paul Winalski
2020-05-14 17:58     ` Clem Cole
2020-05-14 18:41 Doug McIlroy
2020-05-14 18:45 ` Richard Salz
2020-05-14 20:54 ` Clem Cole
2020-05-15  2:44 ` Rob Pike
2020-05-15  3:57   ` Rich Morin
2020-05-15  7:55   ` Dr Iain Maoileoin
2020-05-15 15:01     ` Larry McVoy
2020-05-15 15:36       ` John P. Linderman
2020-05-15 20:01         ` ron
2020-05-15 20:03           ` Larry McVoy
2020-05-15 20:05           ` Clem Cole
2020-05-15 20:18             ` ron
2020-05-15 20:24               ` Clem Cole
2020-05-16  0:57               ` Brantley Coile
2020-05-16 16:14                 ` Dan Cross
2020-05-15 20:56           ` Steve Nickolas
2020-05-16  0:31             ` Peter Jeremy
2020-05-16  8:30               ` Steve Nickolas
2020-05-16  0:43           ` John P. Linderman
2020-05-16 16:28             ` Paul Winalski
2020-05-16 17:39               ` Warner Losh
2020-05-19 19:45                 ` Peter Pentchev
2020-05-20  3:52                   ` Rich Morin
2020-05-21 15:06                     ` Dave Horsfall
2020-05-15 20:34 Doug McIlroy
2020-05-15 20:40 ` Warner Losh
2020-05-15 21:31 Richard Tobin
2020-05-15 21:53 ` Steve Nickolas
2020-05-15 22:33   ` ron
2020-05-15 23:34     ` Steffen Nurpmeso
2020-05-16  1:26       ` Larry McVoy
2020-05-16 21:59       ` Ronald Natalie
2020-05-16 23:26         ` Steffen Nurpmeso
2020-05-17 16:24           ` Paul Winalski
2020-05-17 16:29             ` ron
2020-05-17 16:38               ` Paul Winalski
2020-05-17 20:08                 ` Clem Cole
2020-05-18  8:46                   ` Peter Jeremy
2020-05-19  7:41                     ` Dave Horsfall
2020-05-18 12:04             ` Tony Finch
2020-05-18 13:10               ` Clem Cole
2020-05-18 15:13             ` Rich Morin
2020-05-18 15:51               ` Brantley Coile
2020-05-18 16:11             ` Dan Cross
2020-05-18 21:18               ` ron
2020-05-17 16:10 ` Derek Fawcus
2020-05-17 16:14   ` ron
2020-05-16  0:15 Nelson H. F. Beebe
2020-05-16  0:28 ` Steffen Nurpmeso
2020-05-16  1:52 ` Warner Losh
2020-05-16 16:31   ` Paul Winalski
2020-05-16 20:35     ` Brad Spencer
2020-05-16 20:37       ` Warner Losh
2020-05-18 12:25     ` Tony Finch
2020-05-16 18:45 Richard Tobin
2020-05-16 21:55 ` Ronald Natalie
2020-05-18 13:58 Doug McIlroy
2020-05-18 14:33 Doug McIlroy
2020-05-19  2:29 Doug McIlroy
2020-05-19  3:20 ` Steve Nickolas
2020-05-19 12:29 Noel Chiappa

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=20200517003559.GC19945@mcvoy.com \
    --to=lm@mcvoy.com \
    --cc=dot@dotat.at \
    --cc=tuhs@tuhs.org \
    /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).