From bdcc571b0d5afe6efdf08b890f828a39710129a5 Mon Sep 17 00:00:00 2001 From: Manuel Ramos <129445057+Saik-47@users.noreply.github.com> Date: Tue, 29 Apr 2025 23:47:41 -0600 Subject: [PATCH] A00227837 - Lexical Analyzer Lexical analyzer based on the activity 3.1 Lexycal Analyzer Scanner --- labs/04/Lexical_Analyzer.l | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 labs/04/Lexical_Analyzer.l diff --git a/labs/04/Lexical_Analyzer.l b/labs/04/Lexical_Analyzer.l new file mode 100644 index 0000000..6464ea5 --- /dev/null +++ b/labs/04/Lexical_Analyzer.l @@ -0,0 +1,33 @@ +%{ +#include +%} + +%% +"//". printf("COMMENT\n "); +"f" printf("floatdcl "); +"i" printf("intdcl "); +[a-zA-Z]+ printf("id\n"); +[1-9][0-9]*\.[0-9]+ printf("fnum\n"); +[1-9][0-9]* printf("inum\n"); +"p" printf("print "); +"-" printf("minus "); +"=" printf("assign "); +"+" printf("plus "); +"/" print("divide " ) +"*" print ("multiply ") +[ \t\n]+ { /* empty spaces */ } +. { printf("UNKOWN CHAR '%s'\n", yytext); } +%% + +int main(int argc, char **argv) { + if(argc > 1) { + FILE *file = fopen(argv[1], "r"); + if(!file) { + perror("[!] Couldnt open file"); + return 1; + } + yyin = file; + } + yylex(); + return 0; +} \ No newline at end of file