[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Top Dowm Variable Communication
From: |
Ramón García |
Subject: |
Re: Top Dowm Variable Communication |
Date: |
Wed, 22 Aug 2007 10:49:17 +0200 |
You have to put the register_name as an attribute of Register_decl_control
%union {
struct register_decl_contd_data {
const char* register_name;
/* other data that you want for register_decl_contd */
} register_decl_contd_data;
// Other union members for other terminals and non terminals
}
/* Associate the symbol register_decl_contd with that union member */
%type <register_decl_contd_data> Register_decl_contd
%%
/* In the grammar read and write into the member */
Register_decl: REGISTER IDENTIFIER { $3.register_name = $2; }
Register_decl_contd
Register_decl_contd { work with $0.register_name }
Do yourself a favour, and buy the Dragon book (Aho, Seti, Ullman,
"Compilers. Principles Techniques and Tools") Chapter 5 "Syntax
directed translation" has all the details.. I think that Synopsys, a
company that charges about 10000 $ for each software license, can
afford a 30 $ book.
On 8/22/07, Arijit Das <address@hidden> wrote:
> Even though Bison is a bottom up parser, if I need to pass a variable's
> content top-down, what are the possible ways (except using global
> variable)?
>
>
> Register_decl
> : REGISTER IDENTIFIER Register_decl_contd
> {
> Char * register_name = $2;
> // $2 has the 'register_name' now. I wanted that
> name to be communicated down to the scope of the non-terminal
> 'Register_decl_contd'
> }
> ;
>
>
> Register_decl_contd
> : '.' IDENTIFIER ...something...
> { ... }
> | '=' IDENTIFIER ...something...
> { ... }
> | '[' IDENTIFIER ...something...
> {
> // I want to use get the content of
> 'register_name' here to be able to print user friendly error messages,
> if required.
> // How can I get that info since register_name
> is defined in a top level scope in the non-terminal hierarchy? Any help?
> }
>
> ;
>
>
> Thanks
> Arijit
>
>
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
>
- shift/reduce conflict with unary, cwcaceres, 2007/08/21
- Re: Top Dowm Variable Communication, Ramón García, 2007/08/24
- Re: shift/reduce conflict with unary, Evan Lavelle, 2007/08/22
- Re: shift/reduce conflict with unary, cwcaceres, 2007/08/22
- Re: shift/reduce conflict with unary, Evan Lavelle, 2007/08/22
- Re: shift/reduce conflict with unary, cwcaceres, 2007/08/22
- Re: shift/reduce conflict with unary, Evan Lavelle, 2007/08/22