help-bison
[Top][All Lists]
Advanced

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

Re: accessing yyval outside lex and yacc


From: Manju James
Subject: Re: accessing yyval outside lex and yacc
Date: Fri, 20 Jul 2001 10:48:15 +0200

Sorry if my question was too vague.

what i am doing , is basically calling yyparse() from an external C++ file.
i have defined all the yy- functions and variables as 'extern' entities in
my C++ file.

In my .y file, i have:

*********************************************************
% type < constraint > string1
% type < constraint > string2

(where constraint is a pointer to a class Constraint i have defined in my
C++ file - and is a member of the union YYSTYPE)

%%

string1:    string2
                {$$ = $1;}

..........................

%%

so in effect, when yyparse() is called it builds string1. this works fine as
it is - but i now want to get constraint and pass it to sumthing else and
this is where i have  a problem.

what i was trying before  was - in my main()

main()
{

int return_value = ::yyparse();  /* which works fine */

Constraint* root = yyval.constraint;  /* hoping to gain access to string1 -
but i */
                                                        /* actually get a
null pointer instead*/

}

and that in a nutshell is my problem.

If i define a global like u suggested, i am not sure how that works and how
i will call it from main().


Thank you for ur response - hope i have made the problem clearer now.

Regards
Manju James
Telecommunications Research Group (CeTAS)
Department of Electrical and Information Engineering
University of the Witwatersrand
e-mail: address@hidden
http://www.satina.ee.wits.ac.za




----- Original Message -----
From: Akim Demaille <address@hidden>
To: Manju James <address@hidden>
Cc: <address@hidden>
Sent: Friday, July 20, 2001 10:28 AM
Subject: Re: accessing yyval outside lex and yacc


> >>>>> "Manju" == Manju James <address@hidden> writes:
>
> Manju> Hi - i am a realtively new user of Flex and Bison - was
> Manju> wondering if sumone could clear a doubt for me.
>
> Manju> Is it possible to access yyval externally (from another file -
> Manju> for instance)?  I would like to gain access to the $$ value of
> Manju> the last non-terminal/terminal that yyparse() builds.
>
> Your question is not clear to me.  Are you asking how to get the
> _last_ $$, i.e., the result of your semantic actions?
>
> Then just use a global, say `ast', and in your axiom, write
>
> %%
> axiom: sentence { ast = $$ };
> ...
>
>
> And you're done.
>




reply via email to

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