Browse Source

Translate from french to english

DricomDragon 5 years ago
parent
commit
4860fecf0a
2 changed files with 24 additions and 28 deletions
  1. 10 14
      eval.l
  2. 14 14
      eval.y

+ 10 - 14
eval.l

@@ -1,25 +1,21 @@
-/* -- eval.l --       
-   Evaluation d'une expression       
-   Partie analyseur lexical.    
-
-   Utilisation : flex eval.l */
-
+/*
+Lexical analyser
+for `flex`
+*/
 %{
-#include "eval.tab.h" /* Généré par bison grâce à l'option %defines */
+#include "eval.tab.h" // From bison
 %}
 
 %option noinput
 %option nounput
 %option noyywrap
 
-BLANC [ \n\t]
+VOID [ \n\t]
 
 %%
 
-[0-9]+      yylval = atoi(yytext); return nombre; /* atoi = ascii to integer; yylval est la 
-                                                     valeur sémantique (par défaut un int) 
-                                                     associée au token */
-[-*+()=]     return yytext[0];   /* caracteres unites lexicales */
-{BLANC}+    ;
-.           fprintf(stderr, "Caractere (%c) non reconnu\n", yytext[0]); /* tout le reste (les règles sont évaluées de haut en bas */
+[0-9]+      yylval = atoi(yytext); return number; // Number token
+[-*+()=]    return yytext[0]; // Operators
+{VOID}+     ; // Skip white characters
+.           fprintf(stderr, "Input '%c' unknown\n", yytext[0]); // Fallback error
 

+ 14 - 14
eval.y

@@ -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;
 }