[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Weird problem
From: |
Valentin Tolmer |
Subject: |
Weird problem |
Date: |
Mon, 24 Jun 2013 20:56:10 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 |
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; }
;
- Weird problem,
Valentin Tolmer <=