help-bison
[Top][All Lists]
Advanced

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

Bison Grammar Rules : Refering to non-terminals semantic value


From: Thomas Lavergne
Subject: Bison Grammar Rules : Refering to non-terminals semantic value
Date: Tue, 16 Dec 2003 18:02:43 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.1) Gecko/20020826

Hi.
I am quite new to the Yacc/Bison world and I have a problem to design my parser. It is designed to execute object constructors from the specifications of an input file.

The basic problem is that I want to refer to the semantic value of a non-terminal symbol from elsewhere than its own rule.

I will first try and explain why I have a problem quoting from my yacc.y file.

%{
   /*many inclusions of .h files*/
%}
/* Defining the possible types for semantic values */
%union {
       /*........*/
       Observ       *obs;
       Sensor        *sns;
}
/*Token and type definitions*/
%type <obs>  Observation Bdrplane
%type <sns>  Sensor

%% /* === The rule section ==== */
/* A lot of rules */
/**************************** Experiments ****************************/
Do              : tDO Observation Sensor
                   ;
Sensor        : /* empty */
                   {
                   /* default value */
                   $$ = TheosnsrSensorCreate;
                   }
                   ;
Observation  : Bdrplane /* But there will be many more*/
                   ;
/*ATTENTION::: the problem is here!!!!!!*/
Bdrplane        : tBDRPLANE UpLowHemis IExpr Expr
                   {
                       $$ = BdrplaneObservCreate($2, $3, $4, Sensor)
                   }
                   ;
/* Still another lot of rules*/

The problem is here : bison does not want (or I do not know how to ask him) to use the semantic value of Sensor in the Bdrplane rule. It would have been very simple to include Sensor in the RHS of BdrPlane and use a $n reference, but I do not want it because this parser is supposed to evolve and be easy to modify. I do not want to remember the Sensor each time I add a new Observation. So are there someother solutions? Should I use intermediate variables such as CurrentSensor=TheosnsrSensorCreate and then overrides the job of the bison program (should CurrentSensor be declared with <type>)? I read also about $0 and $-1 references, but it does not seem to apply here, isn't it?

What I want to do is perhaps a *you-should'nt-do-that-thing*, please tell me why?
Thanks for any help.
Thomas





reply via email to

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