%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define YYSTYPE char*
int line = 1;
%}
%%
[ \t]+ ; /* Ignore spaces and tabs */
\n { line++; } /* Increment line count on newlines */
/* Comments */
\/\/.* { printf("Unité Lexicale Commentaire Ligne %d lexéme //\n", line); }
\/\*([^*]|\*+[^\/])*\*+\/ { printf("Unité Lexicale Commentaire Ligne %d lexéme /* ... */\n", line); }
/* Keywords - Case Insensitive */
[sS][iI] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme si\n", line); }
[sS][iI][nN][oO] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme sino\n", line); }
[eE][cC][rR] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme ecr\n", line); }
[vV][rR][aA][iI] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme vrai\n", line); }
[fF][aA][uU][xX] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme Faux\n", line); }
[tT][qQ] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme tq\n", line); }
[qQ][tT] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme qt\n", line); }
[rR][pP][tT] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme rpt\n", line); }
[jJ][sS][qQ] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme jsq\n", line); }
[lL][rR][eE] { printf("Unité Lexicale Mot_Cle Ligne %d lexéme lre\n", line); }
/* Integers */
[0-9]+ { printf("Unité Lexicale Int Ligne %d lexéme %s\n", line, yytext); }
/* Floats (Scientific Notation or Decimal) */
[-+]?
[0-9]+\
.[0-9]+([eE
][-+]?
[0-9]+)?
{ printf
("Unité Lexicale
Float Ligne
%d lexéme %s\n", line, yytext); }
/* Identifiers */
[A-Za-z][A-Za-z0-9]* { printf("Unité Lexicale Identificateur Ligne %d lexéme %s\n", line, yytext); }
/* Operators */
"=="|"<="|">="|"!=" { printf("Unité Lexicale Operateur Ligne %d lexéme %s\n", line, yytext); }
[+\-*/=<>!&|] { printf("Unité Lexicale Operateur Ligne %d lexéme %s\n", line, yytext); }
/* Separators */
[;,:(){}] { printf("Unité Lexicale Separateur Ligne %d lexéme %s\n", line, yytext); }
/* Strings */
\"([^\"\n]|\\.)*\" { printf("Unité Lexicale Chaine Ligne %d lexéme %s\n", line, yytext); }
\".*\n { printf("ERROR Ligne %d Fin de fichier dans une constante chaîne\n", line); line++; }
/* Invalid Characters */
. { printf("ERROR Ligne %d Caractère invalide %s\n", line, yytext); }
%%
int main(int argc, char *argv[]) {
if (argc > 1) {
FILE *file = fopen(argv[1], "r");
if (!file) {
printf
("Error
: Could not
open file
%s\n", argv[1]); return 1;
}
yyin = file;
} else {
yyin = stdin;
}
yylex();
return 0;
}
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojZGVmaW5lIFlZU1RZUEUgY2hhcioKaW50IGxpbmUgPSAxOwolfQoKJSUKWyBcdF0rICAgICAgICAgICAgICAgICA7ICAgLyogSWdub3JlIHNwYWNlcyBhbmQgdGFicyAqLwpcbiAgICAgICAgICAgICAgICAgICAgIHsgbGluZSsrOyB9IC8qIEluY3JlbWVudCBsaW5lIGNvdW50IG9uIG5ld2xpbmVzICovCgovKiBDb21tZW50cyAqLwpcL1wvLiogICAgICAgICAgICAgICAgeyBwcmludGYoIlVuaXTDqSBMZXhpY2FsZSBDb21tZW50YWlyZSBMaWduZSAlZCBsZXjDqW1lIC8vXG4iLCBsaW5lKTsgfQpcL1wqKFteKl18XCorW15cL10pKlwqK1wvICAgeyBwcmludGYoIlVuaXTDqSBMZXhpY2FsZSBDb21tZW50YWlyZSBMaWduZSAlZCBsZXjDqW1lIC8qIC4uLiAqL1xuIiwgbGluZSk7IH0KCi8qIEtleXdvcmRzIC0gQ2FzZSBJbnNlbnNpdGl2ZSAqLwpbc1NdW2lJXSAgICAgICAgICAgICAgeyBwcmludGYoIlVuaXTDqSBMZXhpY2F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