yacc/bison code for counting brackets


How can I write a sample yacc/bison code that verifies whether the number of ( brackets if equal to ) brackets or not. I have gone through the tutorials and examples. I understand the general concept but I don’t know how to formulate a grammar rule set in this case.

expr:         | '(' expr ')'       ;