I'm writing my own scripting language using flex and bison. I have a grammar and I'm able to generate a parser which works fine with a correct script. I would like to be able to add also some meaningful error message for special error situations. For example I would like to be able to recognize unmatched parenthesis for a block of statements or a missing semicolon and so on. Suppose I have these statements (here the grammar is not complete):
...
statements: statement SEMICOLON statements
| statement SEMICOLON;
statement: ifStatement
| whileStatement
;
ifStatement: IF expression THEN statements END
| IF expression THEN statements ELSE statements END
;
whileStatement: DO statements WHILE expression END
;
...
I would like to be able to print messages such as "Missing semicolon" or "Missing then keyword" and so on. Should I modify my grammar to enable error handling? Or is there some Bison feature to do this?