Related articles |
---|
accessing yyval outside lex and yacc?? m.james@ee.wits.ac.za (Manju James) (2001-07-23) |
From: | "Manju James" <m.james@ee.wits.ac.za> |
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
this.
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??
Regards
Manju James
University of the Witwatersrand, Jo'burg, SA
e-mail: m.james@ee.wits.ac.za
[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]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.