Re: Pattern matches one type of paren but not another
Hans Åberg <[email protected]> Sun, 28 May 2023 22:40:25 +0200
| Newsgroups | gmane.comp.parsers.bison.general |
|---|---|
| Message-ID | <[email protected]> |
> On 28 May 2023, at 20:12, Maury Markowitz <[email protected]> wrote: > > Following, sort of, some advice I received earlier I modified my bison by adding this: > > open_bracket: > '(' | '['; > close_bracket: > ')' | ']’; You probably do not want to exchange delimiter types, as in "(…]" and "[…)". > And then modified the original code thus: > > variable: > VARIABLE_NAME > { > variable_t *new = malloc(sizeof(*new)); > new->name = $1; > new->subscripts = NULL; > new->slicing = NULL; > $$ = new; > } > | > VARIABLE_NAME open_bracket exprlist close_bracket > { > variable_t *new = malloc(sizeof(*new)); > new->name = $1; > new->subscripts = $3; > new->slicing = NULL; > $$ = new; > } To exclude that, use: operator_value: VARIABLE_NAME '(' exprlist ')' | VARIABLE_NAME '[' exprlist ']' ; Or more structured (in a C++-like syntax): operator_value: function_value | index_value ; function_value: VARIABLE_NAME '(' exprlist ')' ; index_value: VARIABLE_NAME '[' exprlist ']' ;