Added 10 more gists.

This commit is contained in:
Miguel Astor
2023-06-20 22:03:49 -04:00
parent 1400a87eab
commit 22ff5bfa25
19 changed files with 1642 additions and 0 deletions

1
piglatin.l/README.md Normal file
View File

@@ -0,0 +1 @@
A Lex program that converts an input text to piglatin.

46
piglatin.l/piglatin.l Normal file
View File

@@ -0,0 +1,46 @@
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
bool isconsonant(int);
%}
%option outfile="piglatin.c"
%option always-interactive
%option nounput noinput
word [a-zA-Z]+
%%
{word} { if (isconsonant(yytext[0])) {
int numcons = 0;
while (isconsonant(yytext[numcons++]) && numcons < strlen(yytext))
yytext[numcons - 1] = tolower(yytext[numcons - 1]);
printf("%s", &yytext[--numcons]);
yytext[numcons] = '\0';
printf("%say", yytext);
yytext[numcons] = ' ';
} else
printf("%sway", yytext);
}
"\n" { putc('\n', stdout); }
. { putc(yytext[0], stdout); }
%%
bool isconsonant(int c) {
if (!isalpha(c))
return false;
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
return false;
return true;
}