|
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 |
|
|