Simple question on lex/yacc specifications

Eric Fowler <eric.fowler@gmail.com>
Fri, 13 Mar 2009 21:14:43 -0700

          From comp.compilers

Related articles
Simple question on lex/yacc specifications eric.fowler@gmail.com (Eric Fowler) (2009-03-13)
Re: Simple question on lex/yacc specifications eric.fowler@gmail.com (Eric Fowler) (2009-03-14)
Re: Simple question on lex/yacc specifications kym@svalbard.freeshell.org (russell kym horsell) (2009-03-15)
Re: Simple question on lex/yacc specifications max@gustavus.edu (Max Hailperin) (2009-03-15)
Re: Simple question on lex/yacc specifications eric.fowler@gmail.com (Eric Fowler) (2009-03-15)
| List of all articles for this month |
From: Eric Fowler <eric.fowler@gmail.com>
Newsgroups: comp.compilers
Date: Fri, 13 Mar 2009 21:14:43 -0700
Organization: Compilers Central
Keywords: lex, yacc, question
Posted-Date: 14 Mar 2009 19:33:05 EDT

This should be pretty easy: I am a relative newbie to lex & yacc, and
I am writing a parser for NMEA strings as a toy project. NMEA strings
are output by marine electronic equipment, and the ones I care about
now look like this:


!AIVDM,1,1,,B,15N@wP0P00o?
ruLK?UMMbOw>04KH,0*31
!AIVDM,1,1,,B,15Mj2u001vo?tV8K?<ub>8;@0D1<,0*17
!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E
!AIVDM,2,2,3,B,1@0000000000000,2*55
!AIVDM,1,1,,B,15N:bCPP01G?jPfKADGUvww>2<17,0*4D


So they are pretty simple, and I have a pretty good handle on parsing them.


The problem is that fourth comma-delimited field, which can hold
either a one-digit decimal, a two-digit decimal, or be empty: "...
,1,..." or "..,22,..." or "...,,..." .


How do I recognize the an empty field? There are a lot of fairly
trivial ways to do this, but as far as I can see all would trip up by
recognizing everything, or would hose yaccability by forcing me to
include the comma delimiter as part of the token (so the token is
returned only if it has a comma tacked on the end of it ... yecch ...
).


But there must be a clean way to do this.


Thanks


Eric
[I'd parse commas, numbers, and strings as different kinds of tokens and
deal with the optional stuff in the parser. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.