LAB1 Start

This commit is contained in:
RustyRaptor committed 2021-01-16 23:31:57 -07:00
1 parent 714c0e4a9a
commit ce94eed32b
2 files changed
+64

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
# FLAGS = -O0 -Wall -Wextra -pedantic
FLAGS = -O0 -Wextra -pedantic
all: lab1
lab1: lex.yy.o
gcc $(FLAGS) -o lab1 lex.yy.o
lex.yy.o: lex.yy.c
gcc $(FLAGS) -c lex.yy.c
lex.yy.c: lab1.l
lex lab1.l
reset: clean
rm lab1 lex.yy.c
clean:
rm -rf *.o
memcheck:
valgrind ./lab1 < /etc/passwd -s
test:
./lab1 < /etc/passwd
+38
View File
@@ -0,0 +1,38 @@
/* This lex routine uses a counting array to match alphabeticstrings
and make a frequency count.
The real item to notice is that yywrap() is called at EOF and then is run
to do what we need to do. yywrap() returns true when we have a successful
end to the program. We may want to return false (0) if we want to lexing process
to fail
Shaun Cooper
January 2015
*/
int lgths[100];
int cnt = 0;
%%
[a-zA-Z]+ lgths[yyleng]++;
[0-9]+ cnt++;
. |
\n ;
%%
int yywrap()
{
int i;
printf("Length No. words\n");
for (i=1; i<100; i++) {
if (lgths[i] > 0) {
printf("%5d%10d\n",i,lgths[i]);
}
}
printf("\n\n\n-------------\n");
printf("There are %d numbers\n", cnt);
return(1);
}
int main()
{ yylex();
}