Re: Matching opening and closing bracket question

Simon Richter <[email protected]> Thu, 13 Apr 2023 03:49:43 +0200
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
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