If you want to generate a parser, there are lots of choices of software to help you. Most follow the classic yacc model: you write a grammar in a dedicated grammar language, run it through a parser generator, and end up with executable code for your parser. Newer tools run the same way: Bison, ANTLR, and Lemon.
So I was interested to find the Spirit Parser Framework, which employs a completely different technology. Grammars are written in highly stylized C++, and executed directly. The grammar syntax is unconventional, because it’s all based on C++ operator overloading. Here’s part of a SQL parser:
program = +(query) ;
= longest_d[ select_from_clause
| select_from_where_clause ] >> SEMI;
= select_clause >> from_clause ;
= select_from_clause >> where_clause ;
= SELECT >> !(DISTINCT) >> ( STAR | var_list_clause ) ;
= list_p( varname >> !alias_clause, COMMA ) ;
= FROM >> list_p( table_name >> !alias_clause, COMMA ) ;
Significant template wizardry is at work behind the scenes, I don’t claim to understand it.