Created
November 3, 2015 17:41
-
-
Save dlion/2af88b005b338a793898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
/* | |
* Scrivere un programma in flex che trasformi in maiuscole tutte le parole delle righe che cominciano con una parola di caratteri tutti minuscoli, | |
* in minuscole tutte le parole che cominciano con una parola di caratteri tutti maiuscoli. | |
* Le altre siano lasciate invariate. | |
*/ | |
#include <ctype.h> | |
int i; | |
%} | |
%option main | |
%x min2max max2min | |
%% | |
^[a-z]+/[ ]+ { | |
for(i=0; i < yyleng; i++) | |
{ | |
printf("%c", toupper(yytext[i])); | |
BEGIN(min2max); | |
} | |
} | |
^[A-Z]+/[ ]+ { | |
for(i=0; i < yyleng; i++) | |
{ | |
printf("%c", tolower(yytext[i])); | |
BEGIN(max2min); | |
} | |
} | |
<min2max>[a-z] { printf("%c", toupper(yytext[0])); } | |
<min2max>\n { ECHO; BEGIN(0); } | |
<max2min>[A-Z] { printf("%c", tolower(yytext[0])); } | |
<max2min>\n { ECHO; BEGIN(0); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment