Sujet : Re: Static regex for embedded systems
De : gneuner2 (at) *nospam* comcast.net (George Neuner)
Groupes : comp.arch.embeddedDate : 22. Jan 2025, 01:38:03
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <9me0pjpctevm2k0vjf07iei0a1isf58tqa@4ax.com>
References : 1 2 3
User-Agent : ForteAgent/8.00.32.1272
On Tue, 21 Jan 2025 18:03:48 +0100, pozz <
pozzugno@gmail.com> wrote:
Il 21/01/2025 17:03, Stefan Reuther ha scritto:
Am 21.01.2025 um 15:31 schrieb pozz:
Many times I need to parse/decode a text string that comes from an
external system, over a serial bus, MQTT, and so on.
>
Many times this string has a fixed syntax/layout. In order to parse this
string, I everytime create a custom parser that can be tedious,
cumbersom and error prone.
[...]
I don't see a question in this posting,
>
The hiddend question was if there's a better approach than handcrafted
parsers.
>
>
but isn't this the task that
'lex' is intended to be used for?
>
I will look at it.
>
>
(Personally, I have no problem with handcrafted parsers.)
So long as they are correct 8-)
Stefan
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.
Minding David's warnings about lexer size, if you really want to try
using regex, I would recommend RE2C. RE2C is a preprocessor that
generates simple recursive code to directly implement matching of
regex strings in your code. There are versions available for several
languages.
https://re2c.org/