Skip to content

Commit d939e61

Browse files
author
Rodrigo Chavez
committed
A01635547-homework-04
Signed-off-by: Rodrigo Chavez <rodrigo.chavez@oracle.com>
1 parent 88a21fc commit d939e61

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

labs/04/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
LDFLAGS = -L/opt/homebrew/opt/flex/lib
2+
CPPFLAGS = -I/opt/homebrew/opt/flex/include
3+
4+
# generate
5+
example: code_generator.py
6+
python3 code_generator.py > example.ac
7+
8+
# compile
9+
gen_lex:
10+
lex language_ac.l
11+
gcc $(CPPFLAGS) $(LDFLAGS) lex.yy.c -o lexical_scan -lfl
12+
13+
test: example.ac
14+
./lexical_scan < example.ac
15+
# run lex, then compile lex.yy.c then run lexical_scan
16+
#
17+
stress:
18+
lex language_ac.l
19+
gcc $(CPPFLAGS) $(LDFLAGS) lex.yy.c -o lexical_scan -lfl
20+
python3 code_generator.py --stress
21+
./lexical_scan < random_code.ac
22+
run:
23+
lex language_ac.l
24+
gcc $(CPPFLAGS) $(LDFLAGS) lex.yy.c -o lexical_scan -lfl
25+
python3 code_generator.py > example.ac
26+
./lexical_scan < example.ac
27+
28+
# Limpiar archivos generados
29+
clean:
30+
rm -f lex.yy.c lexical_scan example.ac

labs/04/language_ac.l

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
%{
2+
#include <stdio.h>
3+
%}
4+
5+
%option noyywrap
6+
7+
letter [a-zA-Z]
8+
digit [0-9]
9+
number {digit}+
10+
11+
%%
12+
\/{2}.* { printf("COMMENT "); }
13+
^f { printf("floatdcl "); }
14+
^i { printf("intdcl "); }
15+
= { printf("assign "); }
16+
\+ { printf("plus "); }
17+
\- { printf("minus "); }
18+
\* { printf("multiplication "); }
19+
\/ { printf("division "); }
20+
^p { printf("print "); }
21+
({letter}{digit}*)+ { printf("id "); }
22+
(0|([1-9]{digit}*))\.(({digit}*[1-9])|0) { printf("fnum "); }
23+
{number} { printf("inum "); }
24+
[ \t]+ /* ignore whitespace */
25+
%%
26+
27+
int main() {
28+
yylex();
29+
return 0;
30+
}

0 commit comments

Comments
 (0)