pastebin

Paste Search Dynamic
Recent pastes
yytext
  1. {
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. int shape_count;
  7. }
  8.  
  9. letter [A-Z];
  10.  
  11.  
  12. "triangle" { shape_count = 3; }
  13. "square"   { shape_count = 4; }
  14. "pentagon" { shape_count = 5; }
  15. "hexagon"  { shape_count = 6; }
  16. "heptagon" { shape_count = 7; }
  17. "octagon"  { shape_count = 8; }
  18.  
  19. {letter}+ {
  20.   int len = strlen(yytext);
  21.   if (len != shape_count) {
  22.     printf("Invalid definition: %s. ", yytext);
  23.     return 1;
  24.   }
  25.  
  26.   int symbol_count[26] = {0};
  27.   for (int i = 0; i < len; i++) {
  28.     int index = toupper(yytext[i]) - 'A';
  29.     symbol_count[index]++;
  30.     if (symbol_count[index] > 1) {
  31.       printf("Invalid definition: %s. ", yytext);
  32.       return 1;
  33.     }
  34.   }
  35. }
  36.  
  37.  
  38. int main(int argc, char** argv) {
  39.   yylex();
  40.   return 0;
  41. }
  42.  
Parsed in 0.003 seconds