mirror of
https://github.com/RustyRaptor/compilers.git
synced 2026-12-03 15:15:17 -07:00
LAB1 Start
This commit is contained in:
1 parent
714c0e4a9a
commit
ce94eed32b
2 files changed
+64
No files matched your search
@@ -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
@@ -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();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user