/* File........ ppmatch.lex * Contents.... SEG2106 - LAB-3 part 2 String Search parser Craig Campbell - 50111 Paul M. Baillot 2273596 */ /* compilation: * flex parser3.lex * gcc -o parser3.exe lexyy.c */ /* probllem definition: pattern1. All words starting with aa. pattern2. All words containing aa. pattern3. All words containing an even number of letters. pattern4. All words containing an even number of letter a. pattern5. All words which length is a multiple of 5. pattern6. All words containing three consecutive a. pattern7. All words which do not contain three consecutive a. */ /* ---------------- Definitions space ----------------- */ %option noyywrap %{ #include #include #include #include int address = 0; %} PATTERN1 (aa)+[a|b]* PATTERN2 [a|b]*(aa)+[a|b]* PATTERN3 ((aa)|(ab)|(ba)|(bb))* PATTERN4 [b]*(aa)*[b]* PATTERN5 ([a|b]{5,5})* PATTERN6 [a]{3,3} PATTERN7 [a-z]* /* ------------------- Rules space -------------------- */ %% {PATTERN1} { ++address; printf( " the match was a pattern type 1 %s \n",yytext); } {PATTERN2} { ++address; printf( " the match was a pattern type 2 %s \n",yytext); } {PATTERN3} { ++address; printf( " the match was a pattern type 3 %s \n",yytext); } {PATTERN4} { ++address; printf( " the match was a pattern type 4 %s \n",yytext); } {PATTERN5} { ++address; printf( " the match was a pattern type 5 %s \n",yytext); } {PATTERN6} { ++address; printf( " the match was a pattern type 6 %s \n",yytext); } {PATTERN7} { ++address; printf( " the match was a pattern type 7 %s \n",yytext); } \n { } . { } %% /* ----------------- User code space ------------------ */ main() { printf("Hit ^Z followed by enter to finish\n"); yylex(); printf("--- The total number of valid patterns found is = : %d\n", address); }