Re: Simple parsing problem

Hans Aberg <>
Tue, 23 Jun 2009 10:26:10 +0200

          From comp.compilers

Related articles
Simple parsing problem (Eric Fowler) (2009-06-21)
Re: Simple parsing problem (Hans Aberg) (2009-06-23)
Re: Simple parsing problem (Waldek Hebisch) (2009-06-23)
| List of all articles for this month |

From: Hans Aberg <>
Newsgroups: comp.compilers
Date: Tue, 23 Jun 2009 10:26:10 +0200
Organization: NNTP Server
References: 09-06-073
Keywords: parse
Posted-Date: 23 Jun 2009 16:02:27 EDT

Eric Fowler wrote:
> I am writing a bison grammar to parse strings coming from various
> kinds of attached devices.
> One of the strings is of the form:
> $FOO,field1,field2, 0,a,1,b,3,c, ....<CRLF>
> where there are a variable number of paired fields of the form
> <number> COMMA <text> COMMA. The comma is always a delimiter here,
> the text contains no commas.

How about:
%token COMMA ","
%token FOO CRLF field1 field2
      FOO "," field1 "," field2 "," sequence "," CRLF

            /* empty */
      | sequence NUMBER "," LETTER

If the last LETTER of a "sequence" should not have a terminating ",",
delete it from the "item" grammar variable. If sequence must be
non-empty, replace the empty rule by 'NUMBER "," LETTER'. (field1 and
field2 tokens here only to make the snippet Bison-compilable.)


Post a followup to this message

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