[ Prev ]
2021-09-22

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

-- Sep 22 In-Class Exercise Thread
 lextest.l
 %{
 #include <stdio.h>
 int wordCount = 0;
 %}
 article the|a
 %%
 {article} {wordCount++;}
 %%
 int main()
 {
    yylex(); //call the lexer. Gets input from command line until ^D
    printf("word count: %d", wordCount); return 0;
 }
 
 lextest.c
 #line 2 "lexcounter.c"
 
 #line 4 "lexcounter.c"
 
 #define  YY_INT_ALIGNED short int
 
 /* A lexical scanner generated by flex */
 
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 6
 #define YY_FLEX_SUBMINOR_VERSION 4
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
lextest.l %{ #include <stdio.h> int wordCount = 0; %} article the|a %% {article} {wordCount++;} %% int main() { yylex(); //call the lexer. Gets input from command line until ^D printf("word count: %d", wordCount); return 0; } lextest.c #line 2 "lexcounter.c" #line 4 "lexcounter.c" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 6 #define YY_FLEX_SUBMINOR_VERSION 4 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif

-- Sep 22 In-Class Exercise Thread
{% #include int count = 0; %} word a|(the); %% {word} {count++;} %% int main() { yylex(); printf("There were %d occurrences of 'a' or 'the'", count); return 0; }
(Edited: 2021-09-22)
<nowiki>{% #include <stdio.h> int count = 0; %} word a|(the); %% {word} {count++;} %% int main() { yylex(); printf("There were %d occurrences of 'a' or 'the'", count); 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");} {word} {wordCount++;} %% int main() {
        yylex();
        printf("word count: %d", wordCount); 
        return 0;
    
    }
(Edited: 2021-09-22)
%{ #include <stdio.h> int wordCount = 0; %} word a|the %% [\t\n]+ {printf("I see whitespace\n");} {word} {wordCount++;} %% int main() { yylex(); printf("word count: %d", wordCount); return 0; }

-- Sep 22 In-Class Exercise Thread
 #line 2 "lex.yy.c"
 #line 4 "lex.yy.c"
define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */
 
%{ 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 lexer until ^D
   printf("word count: %d", wordCount); 
   return 0;
}
#line 2 "lex.yy.c" #line 4 "lex.yy.c" define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ %{ 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 lexer until ^D printf("word count: %d", wordCount); return 0; }

-- Sep 22 In-Class Exercise Thread
line 2 "lextest.c"
line 4 "lextest.c"
define YY_INT_ALIGNED short int
%{
 #include <stdio.h>
 int articleCount = 0;
 %}
 article [^a\s\t\n]+
 article [^the\s\t\n]+ 
 %%
 [\t\n ]+ {printf("I see 'a' or 'the'\n");} //what to do if see pattern
 {article} {articleCount++;}
 %%
 int main()
 {
    yylex();
    printf("article count: %d", articleCount);
    return 0;
 } 
(Edited: 2021-09-23)
line 2 "lextest.c" line 4 "lextest.c" define YY_INT_ALIGNED short int %{ #include <stdio.h> int articleCount = 0; %} article [^a\s\t\n]+ article [^the\s\t\n]+ %% [\t\n ]+ {printf("I see 'a' or 'the'\n");} //what to do if see pattern {article} {articleCount++;} %% int main() { yylex(); printf("article count: %d", articleCount); return 0; }

-- Sep 22 In-Class Exercise Thread
lextest.c: #line 1 "lextest.c" #line 3 "lextest.c" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */
lextest.l: %{ #include int articleCount = 0; %} article (a|the) %% [\t\n ]+ {printf("I see whitespace\n");} //what to do if see pattern {article} {articleCount++;} %% int main() { yylex(); //call the lexer. Gets input from command line until ^D printf("article count: %d", articleCount); return 0; }
lextest.c: <nowiki> #line 1 "lextest.c" #line 3 "lextest.c" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ </nowiki> lextest.l: <nowiki> %{ #include <stdio.h> int articleCount = 0; %} article (a|the) %% [\t\n ]+ {printf("I see whitespace\n");} //what to do if see pattern {article} {articleCount++;} %% int main() { yylex(); //call the lexer. Gets input from command line until ^D printf("article count: %d", articleCount); return 0; } </nowiki>
2021-09-26

-- Sep 22 In-Class Exercise Thread
%{ include <stdio.h> int wordCount = 0; %} word a|(the) %% [\t\n ]+ {printf("I see whitespace\n");} {word} {wordCount++;} %% int main() {
   yylex(); 
   printf("word count: %d", wordCount); 
   return 0;
}
%{ include <stdio.h> int wordCount = 0; %} word a|(the) %% [\t\n ]+ {printf("I see whitespace\n");} {word} {wordCount++;} %% int main() { yylex(); printf("word count: %d", wordCount); return 0; }

-- Sep 22 In-Class Exercise Thread
%{
  1. include<stdio.h> int count = 0; %} word a | (the); %% {word} {count++;} %% int main(){ yylex(); printf("count: %d",count); return 0; }
%{ #include<stdio.h> int count = 0; %} word a | (the); %% {word} {count++;} %% int main(){ yylex(); printf("count: %d",count); return 0; }
2021-09-27

-- Sep 22 In-Class Exercise Thread
%{
 #include <stdio.h>
 int wordCount = 0;
 %}
 word a|the
 %%
 [\t\n ]+ {printf("I see whitespace\n");}
 {word} {wordCount++;}
 %%
 int main()
 {
    yylex();
    printf("word count: %d", wordCount); return 0;
 }
<pre> %{ #include <stdio.h> int wordCount = 0; %} word a|the %% [\t\n ]+ {printf("I see whitespace\n");} {word} {wordCount++;} %% int main() { yylex(); printf("word count: %d", wordCount); return 0; } </pre>
[ Next ]
X