[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matching opening and closing bracket question
From: |
Simon Richter |
Subject: |
Re: Matching opening and closing bracket question |
Date: |
Thu, 13 Apr 2023 03:49:43 +0200 |
Hi Maury,
On Wed, Apr 12, 2023 at 06:38:35PM -0400, Maury Markowitz wrote:
> I am parsing a grammar that allows bracketing using (), [] and <>. It would
> simplify my code if I could do…
> open_bracket: ‘(‘ | ‘[‘ | ‘<‘ ;
> close_bracket: ‘)‘ | ‘]‘ | ‘>’ ;
> bracketed_expression : open_bracket expression close_bracket ;
Indeed, that would parse the brackets independently.
Since "expression" is a nonterminal, you can just use
bracketed_expression:
'(' expression ')'
| '[' expression ']'
| '{' expression '}'
to get the behaviour you want, and then you'd use { $$ = $2; } to pass
through the value.
Simon