I also gave up on lex for parsing fairly early.   The problem was reserved words.  These looked like identifiers, but the state machine to pick out a couple of dozen reserved words out of all identifiers was too big for the PDP-11.   When I wrote spell, I ran into the same problem.  I had some rules that wanted to convert plurals to singular forms that would be found in the dictionary.   Writing a rule to recognize .*ies and convert the "ies" to "y" blew out the memory after only a handful of patterns.   My solution was to pick up words and reverse them before passing them through lex, so I looked for the pattern "sei.*", converted it to "y" and then reversed the word again.  As it turned out, I only owned spell for a few weeks because Doug and others grabbed it and ran with it...

Steve

---
 


On 2020-05-16 18:23, Warner Losh wrote:



On Sat, May 16, 2020, 6:05 PM Brantley Coile <brantley@coraid.com> wrote:
"The asteroid to kill this dinosaur is still in orbit."
    —- Plan 9 lex man page

I always hand craft my lexers and use yacc to parse. Most  code on plan 9 does that as well. 
 
Wow! That is the most awesome thing I've seen in a while....
 
Warner
 
 
  Brantley
 

On May 16, 2020, at 8:00 PM, Jon Steinhart <jon@fourwinds.com> wrote:

Steffen Nurpmeso writes:
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.
If you can deal with them they are surely a relief, especially in
rapidly moving syntax situations.  But if i look at settled source
code which uses it, for example usr.sbin/ospfd/parse.y, or
usr.sbin/smtpd/parse.y, both of OpenBSD, then i feel lost and am
happy that i do not need to maintain that code.
--steffen

Wow, I've had the opposite experience.  I find lex/yacc/flex/bison really
easy to use.  The issue, which I believe was covered in the early docs,
is that some languages are not designed with regularity in mind which makes
for ugly code.  But to be fair, that code is at least as ugly with hand-crafted
code.

I believe that the original wisecrack was directed towards FORTRAN.  My ancient
experience was that it was using lex/yacc for HSPICE was not going to work so I
had to hand-craft code for that.

Jon