accessing yyval outside lex and yacc??

"Manju James" <>
23 Jul 2001 02:21:42 -0400

          From comp.compilers

Related articles
accessing yyval outside lex and yacc?? (Manju James) (2001-07-23)
| List of all articles for this month |

From: "Manju James" <>
Newsgroups: comp.compilers
Date: 23 Jul 2001 02:21:42 -0400
Organization: Compilers Central
Keywords: lex, yacc, question
Posted-Date: 23 Jul 2001 02:21:42 EDT

I was wondering if somebody might help me clear up a doubt. ( i am a
relatively new user of lex and yacc).

I am using flex and Bison ( v. 1.28).

I know that it is possible to call yyparse() externally from a C++ file.

But i was wondering if it is possible to access yyval from the C++ file??

In my .y file i had defined YYSTYPE to be a union - and one of the
members of the union was a pointer to a class I had defined.
and i have YYSTYPE yylval and YYSTYPE yyval.

in int main() (in the separate C++ file) - i call yyparse and it does what
it is
supposed to - but when i say :

Blahblah* root = yyval.constraint_ ;
(where Blahblah is my defined class and constraint_ is of the same type (as
defined in the union).

  : it returns a null pointer.

(I have defined YYSTYPE and all the functions yyparse(), yylex() etc, as
extern functions in my C++ file).

so , i dont know if i am calling yyval in the wrong way or if it is just not
possible to access yyval outside flex and bison itself.

what i want to do is gain access to the semantic value of the last resulting
non-terminal/ terminal that yyparse returns, and that is why i am trying

Does anyone know of any other way of actually doing this??

if it is not possible to do this in Bison - is it possible with Byacc??

Manju James
University of the Witwatersrand, Jo'burg, SA
[After the parse is done, there isn't anything useful in yyval. If you
want to save the value at the root of the parse tree, save it in the action
code for your start rule. -John]

Post a followup to this message

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