diff --git a/labs/04/Makefile b/labs/04/Makefile new file mode 100644 index 0000000..e63cf85 --- /dev/null +++ b/labs/04/Makefile @@ -0,0 +1,20 @@ +LDFLAGS="-L/opt/homebrew/opt/flex/lib" +CPPFLAGS="-I/opt/homebrew/opt/flex/include" + +python: + rm -f example.ac + python3 code_generator.py > example.ac + +stress: + python3 code_generator.py --stress + lex lexic_analyzer.l + gcc $(CPPFLAGS) $(LDFLAGS) lex.yy.c -o lexical_scan -lfl + ./lexical_scan < random_code.ac + +run: + lex lexic_analyzer.l + gcc $(CPPFLAGS) $(LDFLAGS) lex.yy.c -o lexical_scan -lfl + ./lexical_scan < example.ac + +clean: + rm -f lex.yy.c lexical_scan diff --git a/labs/04/lexic_analyzer.l b/labs/04/lexic_analyzer.l new file mode 100644 index 0000000..9506435 --- /dev/null +++ b/labs/04/lexic_analyzer.l @@ -0,0 +1,32 @@ +%{ +#include +%} + +%option noyywrap + +letter [a-eg-hj-opq-z] +digit [0-9] +integer {digit}+ +float (0|[1-9]{digit}*)\.({digit}*[1-9]|0) +comment \/{2}.* +id {letter}({letter}|{digit})* + +%% +^i {printf("INT_DEC ");} +^f {printf("FLOAT_DEC ");} +^p {printf("PRINT ");} +\= {printf("ASSIGN ");} +\- {printf("MINUS ");} +\+ {printf("PLUS ");} +\/ {printf("DIVI ");} +\* {printf("MULTI ");} +{id} {printf("ID ");} +{integer} {printf("INT ");} +{float} {printf("FLOAT ");} +{comment} {printf("COMMENT ");} +%% + +int main(){ + yylex(); + return 0; +}