Re: Simple parsing problem

Hans Aberg <haberg_20080406@math.su.se>
Tue, 23 Jun 2009 10:26:10 +0200

          From comp.compilers

Related articles
Simple parsing problem eric.fowler@gmail.com (Eric Fowler) (2009-06-21)
Re: Simple parsing problem haberg_20080406@math.su.se (Hans Aberg) (2009-06-23)
Re: Simple parsing problem hebisch@math.uni.wroc.pl (Waldek Hebisch) (2009-06-23)
| List of all articles for this month |
From: Hans Aberg <haberg_20080406@math.su.se>
Newsgroups: comp.compilers
Date: Tue, 23 Jun 2009 10:26:10 +0200
Organization: Aioe.org 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
%token NUMBER LETTER
%%
item:
      FOO "," field1 "," field2 "," sequence "," CRLF
;


sequence:
            /* 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.)


      Hans



Post a followup to this message

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