[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Weird problem
From: |
Gautam Kapoor |
Subject: |
RE: Weird problem |
Date: |
Fri, 28 Jun 2013 14:11:40 +0530 |
Hi Valentin,
Can you try printing the "address of the char" instead of printing the char
using the printf ?
If you see the same address being used everytime, it will be clear that you are
overwriting the same character pointer all this time and so the last one is
only valid at the end.
-regards
Gautam
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Valentin Tolmer
Sent: Tuesday, June 25, 2013 12:26 AM
To: Akim Demaille; Bison Help
Subject: Weird problem
Hello everyone,
I'm working on an addition to bison, and I have a small grammar problem...
I added something to the bison grammar, to understand statements such as
%prec OR '+' > '*' (for example)
However when parsing a statement with several tokens as char, I have a
problem. The example I'm currently testing with is this:
%prec '^' > OR '*' '/' '-' '+'
which is read to me, for some reason, as
%prec '+' > OR '+' '+' '+' '+'
What I mean is that every char is correctly read, the symbols are the
right ones, but somehow when creating the list, it screws up and
replaces every char with the last one read (not just +, the last one
read). I test the lists at the beginning of declare_precedence_relation,
so none of my outside code affects it.
Here's the code, in parse-gram.y (the printf displays the right characters):
precedence_relation_declaration:
"%prec" precedence_relation_symbols precedence_relation_comparator
precedence_relation_symbols
{ declare_precedence_relation ($2, $4, $3); }
;
precedence_relation_symbols:
precedence_symbol { $$ = $1; }
| precedence_relation_symbols precedence_symbol
{ $$ = symbol_list_append ($1, $2); }
;
precedence_symbol:
string_or_id
{
if (is_prec_group ($1))
$$ = expand_symbol_group (symgroup_from_uniqstr($1, &@1), @1);
//not called in this example
else
$$ = symbol_list_sym_new (symbol_from_uniqstr ($1, @1), @1);
}
| CHAR
{
printf ("char seen : %s\n", symbol_from_uniqstr(char_name ($1),
@1)->tag);
$$ = symbol_list_sym_new (symbol_from_uniqstr (char_name ($1), @1),
@1);
}
;
string_or_id:
STRING { $$ = uniqstr_new (quotearg_style (c_quoting_style, $1)); }
//not called, I believe, in that example
| ID { $$ = $1; }
;
precedence_relation_comparator:
">" { $$ = prec_superior; }
| "=" { $$ = prec_equal; }
| ">" ">" { $$ = prec_superior_strict; }
;
_______________________________________________
address@hidden https://lists.gnu.org/mailman/listinfo/help-bison