help-bison
[Top][All Lists]
Advanced

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

Re: Any Method of reading the token values off the stack


From: Hans Aberg
Subject: Re: Any Method of reading the token values off the stack
Date: Mon, 10 May 2004 23:01:30 +0200

At 21:52 -0400 2004/05/09, Tim Zimmerlin wrote:
>Hans,
>
>I looked at the bison generated parser. I believe that:
>
>yystacksize is the number of stack elements in each of the yyss, yyvs,
>and yyls arrays.
>
>the yyss, yyvs, and yyls stacks are synchronized with the same offset
>from the head of the array.
>
>yyvs[0] is never used or initialized but yyss[0] is used.
>
>int size = yyvsp - yyvs[1] + 1;  // count of stack members with yyvs[0]
>unused
>
>
>Is this correct? What is yyls? How can I determine the data type of
>each yyvs[i] when a union is used?
>
>Your previous suggestion was very helpful.

I suggest you to write Help-Bison, and keep a cc on that list -- then more
can help.

I use a C++ skeleton file I once wrote, and so I am not so interested in
keeping track on the C stuff. I have a vague memory that the C skeleton
file puts the final state on the stack, but it is never used, as it just
means parsing is over. Apart from the stack(s), which contain the state,
semantic and (possibly) the location value, these values must also be kept
for the lookahead token. Unions do not work under C++ with types having
nontrivial constructors, so I do not use them. But Bison has a way top keep
track of the type statically, when %union is invoked. See the Bison manual
for details.

One way to understand this stuff better is to turn on the debugging and see
what the stack writes. Another is to read about LALR(1) parsing in books
about compiler construction and parsing, like the book by Aho et al. Also
see the newsgroup comp.compilers and its FAQ published there monthly.

  Hans Aberg






reply via email to

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