Re: Negative lookahead regex clarification needed

From: Anno Siegel (anno4000_at_lublin.zrz.tu-berlin.de)
Date: 01/25/05


Date: 25 Jan 2005 22:18:14 GMT

shifty <shifty_MyU@yahoo.com> wrote in comp.lang.perl.misc:
>
> > Something is going to compile it. Every regex engine in existence
> > does that.
>
> I would guess they're never compiled - regexes are interpreted, eh?
> So, in essence, if I am writing a regex for perl in particular (we'll
> keep it on-topic), perl is an interpreted language and so is a regex,
> so it's processed on the fly instead of compiling it into an object for
> future use. Unless I'm misinterpreting your use of "compile". If so,
> I have a true interest in understanding if you don't mind explaining.

Processing on-the-fly and compilation don't exclude one another. Both
Perl and, on another level, regular expressions, are first compiled
into a more readily executable form and then immediately executed.
There is still a distinct compilation phase for both, and this is the
phase where syntax is checked and syntax errors are detected.

In particular, a regular expression is not interpreted character by
character, but first translated into something else (often, but not
always, a model of a finite-state machine). There's a whole theory
about that.

> > My point was the misuse of "syntax" for "correct code". It's
> becoming a
> > sore spot.
>
> My apologies. I think we have conflicting views on what a regex really
> is. To me, a regex is a sentence or formula which expresses any number
> of meanings. Without the correct characters pattern (and/or placement)
> within the text (and/or string), you don't have a correct statement.
>
> If you don't produce a correct statement because one or more characters
> are misplaced, is it a syntax error or a code error?

If the regex engine cannot translate your string, it's a syntax error.
If it can, but the result doesn't match the intended set of patterns,
it's a semantic error. Both are coding errors.

Your description "without the correct character pattern ... you don't
have a correct statement" covers both kinds of errors. "Syntax error"
means only one.

Anno



Relevant Pages

  • Re: Duplicate Header Declaration
    ... syntax error before '{' token ... continued compilation (finally rejecting the translation unit because ... If your compiler reports a syntax error, ... identifier, a misspelled identifier, or a type mismatch usually aren't ...
    (comp.lang.c)
  • Re: Is there an easy way to patch Nethack in XP?
    ... tried to compile that. ... syntax error before '->' token". ... the regex headers and libraries? ... I ran into some trouble with that previously due to Windows' parsing ...
    (rec.games.roguelike.nethack)
  • Re: New template engine - retry
    ... syntax error, unexpected T_VARIABLE, expecting T_STRING ... The regex bug puzzled me for a while, but now I got it - only the ... but I haven't found anything in changelogs. ... I should do more testing on lower PHP versions. ...
    (comp.lang.php)
  • Re: regular expression strangeness
    ... interpolate into a character class, ... you'll get a compilation error. ... regex from captured groups in the same regex, ... that you could reference a match in a character class during execution ...
    (comp.lang.perl.misc)
  • Re: Compilation errors in Standard header files
    ... >errors in standard header files supplied by VC++ like stdlib.h, ... >When I write a simple C file, its not giving these compilation erros. ... >C2226: syntax error: unexpected type 'T' ... >C2062: type 'const int' unexpected ...
    (microsoft.public.vc.language)