Understanding regexes (Was: Re: DMD 0.147 release)
Georg Wrede
georg.wrede at nospam.org
Wed Feb 22 16:01:54 PST 2006
Walter Bright wrote:
> "Georg Wrede" <georg.wrede at nospam.org> wrote
>> Walter Bright wrote:
>>
>>> If the compiler is to constant fold regular expressions, then it
>>> needs to build in to the compiler exactly what would happen if
>>> the regex code was evaluated at runtime.
>>
>> Yes. IMHO in essence, the binary machine code, which the runtime
>> also would build. What I have a hard time seeing is, how this
>> differs from building a normal function at compile time?
>
> Consider the strlen() function. Compiling a strlen() function and
> generating machine code for it is a very different thing from the
> compiler knowing what strlen is and replacing:
>
> strlen("abc")
>
> with:
>
> 3
Either I'm getting too old for this business, or you're only giving
pseudo answers.
(1) If we were to stop the compiler dead in its tracks, and I compiled
the function "manually" and returned it to the compiler, would we still
have a problem here?
(2) {-- and this I've so far avoided to bring up, out of courtesy --},
if Don can do it with templates, what's so impossible doing it the
regular way??
-------------------
Just a cross-check: [I think] we're talking about compiling a single
regular expression.
My definition: "a compiled regular expression" is any piece of machine
code that takes *one string* as the argument, and returns (depending on
which of the 2 kinds it is) either a boolean (as in found or not), or an
integer denoting position of First Match.
Such a piece of machine code is a function that complies to one of the
following signatures:
bool foo(char[]); // match
int bar(char[]); // search
More information about the Digitalmars-d-announce
mailing list