Main Page | Report this Page
Computers Forum Index  »  Computer Compilers  »  Simple parsing problem...
Page 1 of 1    

Simple parsing problem...

Author Message
Hans Aberg...
Posted: Tue Jun 23, 2009 12:26 pm
Guest
Eric Fowler wrote:
Quote:
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
 
 
Page 1 of 1    
All times are GMT
The time now is Thu Mar 18, 2010 3:12 am