Groups | Search | Server Info | Login | Register


Groups > comp.arch.embedded > #32324

Re: Static regex for embedded systems

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Stefan Reuther <stefan.news@arcor.de>
Newsgroups comp.arch.embedded
Subject Re: Static regex for embedded systems
Date Wed, 22 Jan 2025 17:53:15 +0100
Lines 42
Message-ID <vmrbac.3i8.1@stefan.msgid.phost.de> (permalink)
References <vmob4o$3ssqn$2@dont-email.me> <vmok15.1gs.1@stefan.msgid.phost.de> <vmok1j$3ssqn$3@dont-email.me> <9me0pjpctevm2k0vjf07iei0a1isf58tqa@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace individual.net OSXBdmfOGKOy4ppsJBnLtwQkYUAcdFJmGVOaRkHDygHyqF/ZmF
Cancel-Lock sha1:uMoUciZg61XLiVJPmwpR67HUhng= sha256:HDuI6cHEG2okQsW766r6zzwuV0duw7FaX0267yJzPws=
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 Hamster/2.1.0.1538
In-Reply-To <9me0pjpctevm2k0vjf07iei0a1isf58tqa@4ax.com>
Xref csiph.com comp.arch.embedded:32324

Show key headers only | View raw


Am 22.01.2025 um 01:38 schrieb George Neuner:
> On Tue, 21 Jan 2025 18:03:48 +0100, pozz <pozzugno@gmail.com> wrote:
>>> (Personally, I have no problem with handcrafted parsers.)
> 
> So long as they are correct 8-)

Correctness has an inverse correlation with complexity, so optimize for
non-complexity.

I would implement a two-stage parser: first break the lines into a
buffer, then throw a bunch of statements like

   if (Parser p(str); p.matchString("+")
         && p.matchTextUntil(":", &prefix)
         && p.matchWhitespace() ...)

at this, with Parser being a small C++ class wrapping the individual
matching operations (strncmp, strspn, etc.)

Surely this is more complex as a regex/template, but still easy enough
to be "obviously correct".

> Lex and Flex create table driven lexers (and driver code for them).
> Under certain circumstances Flex can create far smaller tables than
> Lex, but likely either would be massive overkill for the scenario you
> described.

Maybe, maybe not. I find it hard to extrapolate to the complete task
from the two examples given. If there's hundreds of these templates,
that need to be matched bit-by-bit, I have the impression that lex would
be a quick and easy way to pull them out of a byte stream.

But splitting it into lines first, and then tackling each line on its
own (...using lex, maybe? Or any other tool. Or a parser class.) might
be a good option as well. For example, this can answer the question
whether linefeeds are required to be \r\n, or whether a single \n also
suffices, in a central place. And if you decide that you want to do a
hard connection close if you see a \r or \n outside a \r\n sequence (to
prevent an attack such as SMTP smuggling), that would be easy.


  Stefan

Back to comp.arch.embedded | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Static regex for embedded systems pozz <pozzugno@gmail.com> - 2025-01-21 15:31 +0100
  Re: Static regex for embedded systems David Brown <david.brown@hesbynett.no> - 2025-01-21 16:40 +0100
  Re: Static regex for embedded systems Stefan Reuther <stefan.news@arcor.de> - 2025-01-21 17:03 +0100
    Re: Static regex for embedded systems pozz <pozzugno@gmail.com> - 2025-01-21 18:03 +0100
      Re: Static regex for embedded systems Hans-Bernhard Bröker <HBBroeker@gmail.com> - 2025-01-21 20:40 +0100
      Re: Static regex for embedded systems "Niocláiſín Cóilín de Ġloſtéir" <Master_Fontaine_is_dishonest@Strand_in_London.Gov.UK> - 2025-01-22 00:41 +0100
      Re: Static regex for embedded systems George Neuner <gneuner2@comcast.net> - 2025-01-21 19:38 -0500
        Re: Static regex for embedded systems David Brown <david.brown@hesbynett.no> - 2025-01-22 10:59 +0100
          Re: Static regex for embedded systems George Neuner <gneuner2@comcast.net> - 2025-01-22 18:23 -0500
        Re: Static regex for embedded systems Stefan Reuther <stefan.news@arcor.de> - 2025-01-22 17:53 +0100
          Re: Static regex for embedded systems George Neuner <gneuner2@comcast.net> - 2025-01-22 18:33 -0500

csiph-web