|
@@ -1,26 +1,24 @@
|
|
|
-/* -- eval.y --
|
|
|
- Evaluation d'une expression
|
|
|
- Partie analyseur grammatical.
|
|
|
-
|
|
|
- Utilisation : bison eval.y */
|
|
|
-
|
|
|
+/*
|
|
|
+Syntax analyser
|
|
|
+for `bison`
|
|
|
+*/
|
|
|
%{
|
|
|
#include <stdio.h>
|
|
|
|
|
|
-/* Pré-déclarations */
|
|
|
+/* Prototypes */
|
|
|
int yylex (void);
|
|
|
void yyerror (const char *);
|
|
|
|
|
|
-/* Variable définie dans un autre fichier */
|
|
|
+/* Variable from lexical analysis */
|
|
|
extern char* yytext;
|
|
|
|
|
|
%}
|
|
|
|
|
|
-%defines /* Génère le fichier en-tête eval.tab.h */
|
|
|
+%defines /* Geneates eval.tab.h */
|
|
|
|
|
|
-%token nombre
|
|
|
+%token number
|
|
|
|
|
|
-%start EXPR_CALCS /* Axiome de la grammaire */
|
|
|
+%start EXPR_CALCS /* Axiom */
|
|
|
|
|
|
%%
|
|
|
|
|
@@ -36,7 +34,7 @@ EXPR : EXPR '+' EXPR {$$ = $1 + $3;}
|
|
|
| FACTOR
|
|
|
;
|
|
|
|
|
|
-FACTOR : nombre {$$ = $1;}
|
|
|
+FACTOR : number {$$ = $1;}
|
|
|
| FACTOR '*' FACTOR {$$ = $1 * $3;}
|
|
|
| FACTOR '/' FACTOR {$$ = $1 / $3;}
|
|
|
| '(' EXPR ')' {$$ = $2;}
|
|
@@ -48,12 +46,14 @@ FACTOR : nombre {$$ = $1;}
|
|
|
|
|
|
void yyerror (const char * error)
|
|
|
{
|
|
|
- fprintf (stderr, "Erreur: %s sur l'expression %s\n", error, yytext);
|
|
|
+ fprintf (stderr, "Error detected : %s\n for expression\n%s\n", error, yytext);
|
|
|
}
|
|
|
|
|
|
int main() {
|
|
|
if ( yyparse() != 0 ) {
|
|
|
- fprintf(stderr,"Syntaxe incorrecte\n"); return 1; }
|
|
|
+ fprintf(stderr, "Error detected : syntax error\n");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
else
|
|
|
return 0;
|
|
|
}
|