Skip to content

Instantly share code, notes, and snippets.

@dlion
Created November 3, 2015 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlion/2af88b005b338a793898 to your computer and use it in GitHub Desktop.
Save dlion/2af88b005b338a793898 to your computer and use it in GitHub Desktop.
%{
/*
* 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