Re: Grammars are not Regexps

Steven Pemberton writes:

> I was working on some grammars this week, and tripped up a couple of
> times, getting ambiguous grammars, I think because I was thinking in
> regexp terms, and grammars are not regexps.

> The place where this was obvious was with repetition. Regexps are
> greedy, grammars aren't. So "x"* with a regexp will match a maximal
> number of x's, but not necessarily with a grammar.

It's a pedantic point but important, so I'll make it anyway: the
greediness is a property of the regex software in use, not of the
regular expression.  All regex libraries intended for wide use use
greedy matching because that is what most applications need, most of the
time, and by now that it may be in part because greedy matching is what
programmers active nowadays have grown up with.  I think some allow a
runtime switch to request non-greedy matching.

Michael

-- 
C. M. Sperberg-McQueen
Black Mesa Technologies LLC
http://blackmesatech.com

Received on Friday, 4 February 2022 00:47:37 UTC