help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Flex empty string


From: Dan Haggarty
Subject: Re: Flex empty string
Date: Mon, 10 Sep 2007 10:55:06 -0400
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

"Eric Fowler" wrote:

> I hear a rumor this is the place for online flex discussion.
>
> I am a relative newbie and I want to match NMEA 0183 strings coming
> from a GPS.
>
> They look like this:
> $GPGGA,123519,4807.038,N,01131.000,E,1,08, 0.9,545.4,M,46.9,M,,*47
>
> except when they look like this:
>
> $GPGGA,123519,4807.038,N,01131.000,E,,,,,,,,,*47
>
> In other words, many fields can be blank, but they are always comma -
> delimited. When they exist they are nicely structured, e.g.
> {DIGIT}{4}"."{DIGIT}{3} matches a latitude string.
>
> So how do I distinguish between a field with some specific data and a
> delimiter, and an empty string followed by the same delimiter?

Depending on how you want to define your grammar, you could (a) use the
/ meta character to match appropriate regular expressions for the fields
but only if followed by a comma or \r, e.g., [A-Z]*/(,|\r) or (b) have
your pattern(s) include the trailing comma or \r and strip out the last
character in the action program code for the expression(s).  Either way
would allow you to have empty strings returned by flex.

Hope this helps,

Dan

-- 
Dan Haggarty
Principal Consultant
Dunhaven Inc.
"advanced data architectures and business systems analysis"
416.234.8202





reply via email to

[Prev in Thread] Current Thread [Next in Thread]