help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable length fields


From: Hans Aberg
Subject: Re: variable length fields
Date: Thu, 06 Jan 2005 19:27:45 +0100
User-agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6

At 12:34 +0000 2005/01/06, Leo Kirch wrote:
>i've got the following problem with bison: imagine a text file by the
>structure of one line that tells us how many lines will follow and the
>following lines... ahm... sample:
>
>   ......
>   ......
>   3                 // three lines will follow
>   line1            // the first line...
>   line2
>   line3            //the last line..
>   2
>   anotherline1
>   anotherline2
>   ....
>   ...
>
>and so on. but how do i tell bison to remember (3) and then read exactly the
>next three lines?

It might be easiest to check this semantically, in the actions.

%{
size_t line_count, maxline_count;
%}

%token NUMBER

%%

get_lines:
    NUMBER { maxline_count = $1 } lines
;
lines:
      { line_count = 0; }
  | lines line { (++line_count > maxline_count)  error ... }
;

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]