| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 
 |  
%{
#include <string.h>
#include "codes.h"
 
int max=20;
int indentation=0;
int nbIndent = 0;
typedef struct InfoIdent {
  const char* texte; /* le mot-cle ou lident proprement dit */
  int code_mot_cle; /* code du mot-cle, ou code IDENT */
} InfoIdent;
 
struct InfoIdent table[] = 
  { {"faire",FAIRE},{"entier", ENTIER}, {"reel",REEL},{"chaine",CHAINE},{"<-",AFFECTER},
   {"tableau",TABLEAU},{"si",SI},{"alors",ALORS},{"finsi",FINSI},
   {"sinon",SINON},{"tantque",TANTQUE},{"fintantque",FINTANTQUE},{"ou",OU},{"et",ET},{"non",NON},
   {"lire",LIRE},{"afficher",AFFICHER},{"chaine",NEWCHAINE },{"=",EGAL},
   {"!=",DIFFERENT},{ "<", INFERIEUR},{"<=",INFEGAL},{">",SUPERIEUR},{">=",SUPEGAL}};
 
 
InfoIdent* chercher (const char* s);
/* Retourne lentree de la table correspondant a lidentificateur
ou au mot-cle qui secrit comme s.
AJOUTE lidentificateur s `a la table SIL NY EST PAS D´EJ`A.
Initialement, la table ne contient que les mots-cl´es du
langage (et ´eventuellement des identificateurs predefinis)
*/
void indent(); 
/* declaration en C ex #include <stdio.h
http://www.comp.sci.sitew.com/fs/Root/5ybea-Outil_ */
%}
 
Ident ([a-zA-Z])([a-zA-Z0-9]*)
Alors alors
Faire faire
MotClefSautLigneIndent {Alors}|{Faire}
Finsi finsi
Fintantque fintantque
MotClefLessIndent {Finsi}|{Fintantque}
Tantque tanque
Tableau tableau
Entier entier
NewChaine chaine
Si si
Ou ou
Et et
Non non
Afficher afficher
Lire lire
MotClef ({Tantque}|{Tableau}|{Entier}|{Chaine}|{Si}|{Ou}|{Et}|{Non}|{Afficher}|{Lire})
Affecter "<-"
Chaine \"([^"\\]|\\n|\\\")*\"
Nombre [0-9]+
Reel {Nombre}(((\.)({Nombre}))|e{Nombre})?
Egal "="
Different "!="
Inferieur "<"
InfEgal "<="
Superieur ">"
SupEgal ">="
Comparator ({Egal}|{Different}|{Inferieur}|{InfEgal}|{Superieur}|{SupEgal})
Plus "+"
Moins "-"
Multiplier "*"
Diviser "/"
Modulo "%"
Operateur ({Plus}|{Moins}|{Multiplier}|{Diviser}|{Modulo})
Commentaire1 ("/*"([^*]|"*"+[^/*])*"*"+"/")|("//"[^\n]*)
SINON sinon
 
 
%%
 
 
"\n"|";"	{
	 if (!indentation) { indentation=1; printf("<br>");}
	return ;	
	}
 
{Chaine}  {
		indent();printf("<font color=green>%s</font>",yytext);
		return CHAINE;
		}
 
{Nombre}  { indent();printf("<font color=green>%s</font>",yytext);
		return NOMBRE;
		}
 
{Reel} {
		indent();printf("<font color=green>%s</font>",yytext);
		return REEL;
		}
 
{Affecter}	{printf("←");
		return chercher(yytext)->code_mot_cle;}
 
">=" printf("≥");
 
"<=" printf("≤");
 
{Commentaire1}	{ indent();printf("<cite><font color=blue>%s</font></cite>",yytext); }
 
{SINON} {
			if (!indentation){ printf("<br>"); indentation=1;}
			if(nbIndent>0){nbIndent--;}
			indent();
			printf("<strong><font color=red>%s</font></strong><br>",yytext);
			indentation=1;
			nbIndent++;
			return chercher(yytext)->code_mot_cle;
			}
 
{MotClefLessIndent}	{
			if (!indentation){ printf("<br>"); indentation=1;}
			if(nbIndent>0){nbIndent--;}
			indent();
			printf("<strong><font color=red>%s</font></strong><br>",yytext);
			indentation=1;
			return chercher(yytext)->code_mot_cle; 			
			}
 
{MotClefSautLigneIndent} {
			  indent();
			  nbIndent++;
			  printf("<strong><font color=red>%s</font></strong>",yytext);
			  if(!indentation){
				indentation=1;
				printf("<br>");}
			return chercher(yytext)->code_mot_cle;
			 }
 
 
 
 
{MotClef}	{
		indent();
		printf("<strong><font color=red>%s</font></strong>",yytext);
		return chercher(yytext)->code_mot_cle;}
 
{Ident}		{
		indent();
		printf("%s",yytext);
		return chercher(yytext)->code_mot_cle;}
 
{Comparator}    { return chercher(yytext)->code_mot_cle;}
 
{Operateur}     {  return yytext[0];}
 
 
[ \t]	return ;
 
.|\n	return; 
 
 
%%
 
 
void indent(){
  int i=0;
  if(indentation){
  for(i;i<nbIndent;i++){
  printf("    ");
    }
indentation=0;
}
}
 
InfoIdent* chercher (const char* s){
   int i=0;
	printf("%s",s);
   while(!strcmp(s,table[i].texte)){
	printf("%s",table[i].texte);
    return table+i;
    i++;
   }
} | 
Partager