[ Prev ]
2021-09-27

-- Sep 22 In-Class Exercise Thread
%{

include <stdio.h>
int wordCount = 0;
%}
word [a\s]
word [the\s]
%%
{word} {wordCount++;}
%%
int main()
{
   yylex(); //call the lexer. Gets input from command line until ^D
   printf("word count: %d", wordCount); return 0;
}
<pre> %{ #include <stdio.h> int wordCount = 0; %} word [a\s] word [the\s] %% {word} {wordCount++;} %% int main() { yylex(); //call the lexer. Gets input from command line until ^D printf("word count: %d", wordCount); return 0; } </pre>

-- Sep 22 In-Class Exercise Thread
%{
  1. include <stdio.h> int wordCount = 0; %} word a|(the); %% {word} {wordCount++;} %% int main() {
       yylex(); 
       // print to console
       printf(“wordCount: %d", wordCount); 
       return 0;
    
    }
%{ #include <stdio.h> int wordCount = 0; %} word a|(the); %% {word} {wordCount++;} %% int main() { yylex(); // print to console printf(“wordCount: %d", wordCount); return 0; }

-- Sep 22 In-Class Exercise Thread
%{ #include int wordCount = 0; %} word a|(the) %% [\t\n ]+ {printf("I see whitespace\n");} //what to do if see pattern {word} {wordCount++;} %% int main() { yylex(); //call the lexer. Gets input from command line until ^D printf("word count: %d", wordCount); return 0; }
<nowiki>%{ #include <stdio.h> int wordCount = 0; %} word a|(the) %% [\t\n ]+ {printf("I see whitespace\n");} //what to do if see pattern {word} {wordCount++;} %% int main() { yylex(); //call the lexer. Gets input from command line until ^D printf("word count: %d", wordCount); return 0; }</nowiki>

-- Sep 22 In-Class Exercise Thread
%{
  1. include <stdio.h> int wordCount = 0; %} word a+|(the)+ %% [\t\n ]+ {printf("I see whitespace\n");} //what to do if see pattern {word} {wordCount++;} %% int main() {
       yylex(); //call the lexer. Gets input from command line until ^D
       printf("word count: %d", wordCount); return 0;
    
    }
%{ #include <stdio.h> int wordCount = 0; %} word a+|(the)+ %% [\t\n ]+ {printf("I see whitespace\n");} //what to do if see pattern {word} {wordCount++;} %% int main() { yylex(); //call the lexer. Gets input from command line until ^D printf("word count: %d", wordCount); return 0; }
X