/* Calcul d'expressions arithme'tiques on de'termine la valeur a utiliser avec etf.lex qui reconnait les differents terminaux NUMBER: nombre entier, PARO PARF: parentheses, MULT PLUS multiplication addition , POINTV point virgule, ID identificateur (ne sert pas ici) */ %{ #define YYSTYPE int #include %} %token NUMBER PLUS POINTV MULT PARO PARF ID EGAL %% statement : expression POINTV {printf("val = %d\n", $1);} ; expression : expression PLUS terme {$$ = $1 + $3;} | terme {$$ = $1;} ; terme : terme MULT facteur {$$ = $1 * $3;} | facteur {$$ = $1;} ; facteur : PARO expression PARF {$$ = $2;} | NUMBER {$$ = $1;} ; %% #include "lex.yy.c" main() { yyparse(); } yyerror(char *s) { printf ("%s\n",s); }