[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pattern matches one type of paren but not another
From: |
Hans Åberg |
Subject: |
Re: Pattern matches one type of paren but not another |
Date: |
Sun, 28 May 2023 22:40:25 +0200 |
> On 28 May 2023, at 20:12, Maury Markowitz <maury.markowitz@gmail.com> 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 ']'
;