1. The grammar used

Let's write a mini calculator. The grammar needed for such a program is quite simple. We will have to evaluate expressions that can be either a number, either an expression between parenthesis, either an expression added to an other, etc. So, as you can see, the grammar is recursive.

The analysis of the language is made in two passes. The first one is what is called lexical analysis. This is the job of Lex, through the function yylex(), which consums the tokens (see below). This function will inform the syntaxical analyser, generated by Yacc, through the function yyparse().