%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define YYSTYPE char*
int line = 1;
void processInput(const char *input); // Function to process input
%}
%%
[ \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); }
%%
void processInput(const char *input) {
yy_scan_string(input);
yylex();
}
int main() {
const char *exampleInput =
"si (x > 10) {\n"
" ecr
(\"x
is greater than
10\"
); // Print message\n"
"} sino {\n"
" ecr(\"x <= 10\");\n"
"}\n"
"/* Multi-line comment */\n"
"qt = 3.14;\n"
"jsq (x != 0) {\n"
" x = x - 1;\n"
"}";
printf("Processing input...\n\n");
processInput(exampleInput);
return 0;
}
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojZGVmaW5lIFlZU1RZUEUgY2hhcioKaW50IGxpbmUgPSAxOwp2b2lkIHByb2Nlc3NJbnB1dChjb25zdCBjaGFyICppbnB1dCk7IC8vIEZ1bmN0aW9uIHRvIHByb2Nlc3MgaW5wdXQKJX0KCiUlClsgXHRdKyAgICAgICAgICAgICAgICAgOyAgIC8qIElnbm9yZSBzcGFjZXMgYW5kIHRhYnMgKi8KXG4gICAgICAgICAgICAgICAgICAgICB7IGxpbmUrKzsgfSAvKiBJbmNyZW1lbnQgbGluZSBjb3VudCBvbiBuZXdsaW5lcyAqLwoKLyogQ29tbWVudHMgKi8KXC9cLy4qICAgICAgICAgICAgICAgIHsgcHJpbnRmKCJVbml0w6kgTGV4aWNhbGUgQ29tbWVudGFpcmUgTGlnbmUgJWQgbGV4w6ltZSAvL1xuIiwgbGluZSk7IH0KXC9cKihbXipdfFwqK1teXC9dKSpcKit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ssOigpe31dICAgICAgICAgICAgIHsgcHJpbnRmKCJVbml0w6kgTGV4aWNhbGUgU2VwYXJhdGV1ciBMaWduZSAlZCBsZXjDqW1lICVzXG4iLCBsaW5lLCB5eXRleHQpOyB9CgovKiBTdHJpbmdzICovClwiKFteXCJcbl18XFwuKSpcIiAgICB7IHByaW50ZigiVW5pdMOpIExleGljYWxlIENoYWluZSBMaWduZSAlZCBsZXjDqW1lICVzXG4iLCBsaW5lLCB5eXRleHQpOyB9ClwiLipcbiAgICAgICAgICAgICAgICB7IHByaW50ZigiRVJST1IgTGlnbmUgJWQgRmluIGRlIGZpY2hpZXIgZGFucyB1bmUgY29uc3RhbnRlIGNoYcOubmVcbiIsIGxpbmUpOyBsaW5lKys7IH0KCi8qIEludmFsaWQgQ2hhcmFjdGVycyAqLwouICAgICAgICAgICAgICAgICAgICAgeyBwcmludGYoIkVSUk9SIExpZ25lICVkIENhcmFjdMOocmUgaW52YWxpZGUgJXNcbiIsIGxpbmUsIHl5dGV4dCk7IH0KCiUlCgp2b2lkIHByb2Nlc3NJbnB1dChjb25zdCBjaGFyICppbnB1dCkgewogICAgeXlfc2Nhbl9zdHJpbmcoaW5wdXQpOwogICAgeXlsZXgoKTsKfQoKaW50IG1haW4oKSB7CiAgICBjb25zdCBjaGFyICpleGFtcGxlSW5wdXQgPSAKICAgICAgICAic2kgKHggPiAxMCkge1xuIgogICAgICAgICIgICAgZWNyKFwieCBpcyBncmVhdGVyIHRoYW4gMTBcIik7IC8vIFByaW50IG1lc3NhZ2VcbiIKICAgICAgICAifSBzaW5vIHtcbiIKICAgICAgICAiICAgIGVjcihcInggPD0gMTBcIik7XG4iCiAgICAgICAgIn1cbiIKICAgICAgICAiLyogTXVsdGktbGluZSBjb21tZW50ICovXG4iCiAgICAgICAgInF0ID0gMy4xNDtcbiIKICAgICAgICAibnVtYmVyID0gMTIzNDU7XG4iCiAgICAgICAgImpzcSAoeCAhPSAwKSB7XG4iCiAgICAgICAgIiAgICB4ID0geCAtIDE7XG4iCiAgICAgICAgIn0iOwogICAgCiAgICBwcmludGYoIlByb2Nlc3NpbmcgaW5wdXQuLi5cblxuIik7CiAgICBwcm9jZXNzSW5wdXQoZXhhbXBsZUlucHV0KTsKICAgIHJldHVybiAwOwp9CgppbnQgeXl3cmFwKCkgewogICAgcmV0dXJuIDE7Cn0K