- {
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int shape_count;
- }
- letter [A-Z];
- "triangle" { shape_count = 3; }
- "square" { shape_count = 4; }
- "pentagon" { shape_count = 5; }
- "hexagon" { shape_count = 6; }
- "heptagon" { shape_count = 7; }
- "octagon" { shape_count = 8; }
- {letter}+ {
- int len = strlen(yytext);
- if (len != shape_count) {
- printf("Invalid definition: %s. ", yytext);
- return 1;
- }
- int symbol_count[26] = {0};
- for (int i = 0; i < len; i++) {
- int index = toupper(yytext[i]) - 'A';
- symbol_count[index]++;
- if (symbol_count[index] > 1) {
- printf("Invalid definition: %s. ", yytext);
- return 1;
- }
- }
- }
- int main(int argc, char** argv) {
- yylex();
- return 0;
- }
Parsed in 0.003 seconds