From e7d9fdb1d1604bb0fd4471151df6e4f923aaa877 Mon Sep 17 00:00:00 2001 From: tecservicesgda <112429879+tecservicesgda@users.noreply.github.com> Date: Tue, 29 Apr 2025 23:59:37 -0600 Subject: [PATCH 1/7] Create a01641645_ --- labs/04/a01641645_ | 1 + 1 file changed, 1 insertion(+) create mode 100644 labs/04/a01641645_ diff --git a/labs/04/a01641645_ b/labs/04/a01641645_ new file mode 100644 index 0000000..a1e98e8 --- /dev/null +++ b/labs/04/a01641645_ @@ -0,0 +1 @@ +jsjsj From 3e1f17ffb350381ec2744b476279cbe9024a062a Mon Sep 17 00:00:00 2001 From: tecservicesgda <112429879+tecservicesgda@users.noreply.github.com> Date: Wed, 30 Apr 2025 00:17:58 -0600 Subject: [PATCH 2/7] Create lex_analaizer.l --- labs/04/a01641645_ | 1 - labs/04/lex_analaizer.l | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) delete mode 100644 labs/04/a01641645_ create mode 100644 labs/04/lex_analaizer.l diff --git a/labs/04/a01641645_ b/labs/04/a01641645_ deleted file mode 100644 index a1e98e8..0000000 --- a/labs/04/a01641645_ +++ /dev/null @@ -1 +0,0 @@ -jsjsj diff --git a/labs/04/lex_analaizer.l b/labs/04/lex_analaizer.l new file mode 100644 index 0000000..a86a255 --- /dev/null +++ b/labs/04/lex_analaizer.l @@ -0,0 +1,61 @@ +%{ +#include +%} + +// Token definitions +COMMENT //.* +FLOATDCL f +INTDCL i +PRINT p +ID [a-zA-Z][a-zA-Z0-9]* +ASSIGN = +PLUS \+ +INUM [0-9]+ +FNUM [0-9]+\.[0-9]+ + +%% +// Comment line +{COMMENT} { printf("COMMENT\n"); } + +// Declarations +{FLOATDCL} { printf("floatdcl id\n"); } +{INTDCL} { printf("intdcl id\n"); } + +// Print command +{PRINT} { printf("print id\n"); } + +// Identifiers and assignments +{ID} { printf("id "); yymore(); } +{ASSIGN} { printf("assign "); yymore(); } +{INUM} { printf("inum\n"); } +{FNUM} { printf("fnum\n"); } +{PLUS} { printf("plus "); } + +// Whitespace and ignored tokens +[ \t\n]+ { /* Ignore whitespace */ } + +. { printf("Unrecognized token: %s\n", yytext); } + +%% + +int main(int argc, char **argv) { + if (argc != 2) { + printf("Usage: %s \n", argv[0]); + return 1; + } + + FILE *file = fopen(argv[1], "r"); + if (!file) { + perror("Error opening file"); + return 1; + } + + yyin = file; + yylex(); + fclose(file); + return 0; +} + +int yywrap() { + return 1; +} From d344a47ff687ea2729850365a1d27a3bd8d0c0f2 Mon Sep 17 00:00:00 2001 From: tecservicesgda <112429879+tecservicesgda@users.noreply.github.com> Date: Wed, 30 Apr 2025 00:56:01 -0600 Subject: [PATCH 3/7] Delete labs/04/lex_analaizer.l --- labs/04/lex_analaizer.l | 61 ----------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 labs/04/lex_analaizer.l diff --git a/labs/04/lex_analaizer.l b/labs/04/lex_analaizer.l deleted file mode 100644 index a86a255..0000000 --- a/labs/04/lex_analaizer.l +++ /dev/null @@ -1,61 +0,0 @@ -%{ -#include -%} - -// Token definitions -COMMENT //.* -FLOATDCL f -INTDCL i -PRINT p -ID [a-zA-Z][a-zA-Z0-9]* -ASSIGN = -PLUS \+ -INUM [0-9]+ -FNUM [0-9]+\.[0-9]+ - -%% -// Comment line -{COMMENT} { printf("COMMENT\n"); } - -// Declarations -{FLOATDCL} { printf("floatdcl id\n"); } -{INTDCL} { printf("intdcl id\n"); } - -// Print command -{PRINT} { printf("print id\n"); } - -// Identifiers and assignments -{ID} { printf("id "); yymore(); } -{ASSIGN} { printf("assign "); yymore(); } -{INUM} { printf("inum\n"); } -{FNUM} { printf("fnum\n"); } -{PLUS} { printf("plus "); } - -// Whitespace and ignored tokens -[ \t\n]+ { /* Ignore whitespace */ } - -. { printf("Unrecognized token: %s\n", yytext); } - -%% - -int main(int argc, char **argv) { - if (argc != 2) { - printf("Usage: %s \n", argv[0]); - return 1; - } - - FILE *file = fopen(argv[1], "r"); - if (!file) { - perror("Error opening file"); - return 1; - } - - yyin = file; - yylex(); - fclose(file); - return 0; -} - -int yywrap() { - return 1; -} From 7ade00346b895958ff80cb833ca4c1182e211ea2 Mon Sep 17 00:00:00 2001 From: tecservicesgda <112429879+tecservicesgda@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:07:49 -0600 Subject: [PATCH 4/7] A01641645-homework-04 --- labs/04/lex_analyzer.l | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 labs/04/lex_analyzer.l diff --git a/labs/04/lex_analyzer.l b/labs/04/lex_analyzer.l new file mode 100644 index 0000000..c93cee7 --- /dev/null +++ b/labs/04/lex_analyzer.l @@ -0,0 +1,42 @@ +%{ +#include +%} + + // Token definitions +%% +"//"[^\n]* { printf("COMMENT\n"); } // Match comments +"f" { printf("floatdcl \n"); } // Match float declarations +"i" { printf("intdcl \n"); } // Match integer declarations +"p" { printf("print \n"); } // Match print commands +[a-zA-Z][a-zA-Z0-9]* { printf("id "); } // Match identifiers (no newline here) +"=" { printf("assign "); } // Match assignment operator (no newline) +[0-9]+ { printf("inum\n"); } // Match integers +[0-9]+\.[0-9]+ { printf("fnum\n"); } // Match floating-point numbers +\+ { printf("plus "); } // Match the plus operator (no newline) +[ \t]+ { /* Ignore spaces and tabs */ } // Ignore spaces and tabs explicitly +\n { /* Ignore standalone newlines */ } +. { printf("Unrecognized token: %s\n", yytext); } // Handle unrecognized tokens + +%% + +int main(int argc, char **argv) { + if (argc != 2) { + printf("Usage: %s \n", argv[0]); + return 1; + } + + FILE *file = fopen(argv[1], "r"); + if (!file) { + perror("Error opening file"); + return 1; + } + + yyin = file; + yylex(); + fclose(file); + return 0; +} + +int yywrap() { + return 1; +} From aac8fe688dcaafe5de14247d9c7f24b090628d97 Mon Sep 17 00:00:00 2001 From: tecservicesgda <112429879+tecservicesgda@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:09:30 -0600 Subject: [PATCH 5/7] A01641645-homework-04 --- labs/04/code_generator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 labs/04/code_generator.py diff --git a/labs/04/code_generator.py b/labs/04/code_generator.py new file mode 100644 index 0000000..842c99c --- /dev/null +++ b/labs/04/code_generator.py @@ -0,0 +1,19 @@ +import random + +lines = [ + "// basic code\n", + "//float b\n", + "f b\n", + "// integer a\n", + "i a\n", + "// a = 5\n", + "a = 5\n", + "// b = a + 3.2\n", + "b = a + 3.2\n", + "//print 8.5\n", + "p b\n" +] + +with open("example.ac", "w") as f: + for line in lines: + f.write(line) From de8b3d42ea22f93d235d4c7445778c524f0402dc Mon Sep 17 00:00:00 2001 From: tecservicesgda <112429879+tecservicesgda@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:11:41 -0600 Subject: [PATCH 6/7] A01641645-homework-04 --- labs/04/example.ac | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 labs/04/example.ac diff --git a/labs/04/example.ac b/labs/04/example.ac new file mode 100644 index 0000000..b8d4eab --- /dev/null +++ b/labs/04/example.ac @@ -0,0 +1,11 @@ +// basic code +//float b +f b +// integer a +i a +// a = 5 +a = 5 +// b = a + 3.2 +b = a + 3.2 +//print 8.5 +p b From 12f91d2111a4aed6f7f1d121a9c939f8a9402df3 Mon Sep 17 00:00:00 2001 From: tecservicesgda <112429879+tecservicesgda@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:12:24 -0600 Subject: [PATCH 7/7] A01641645-homework-04 --- labs/04/makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 labs/04/makefile diff --git a/labs/04/makefile b/labs/04/makefile new file mode 100644 index 0000000..9f43ee1 --- /dev/null +++ b/labs/04/makefile @@ -0,0 +1,12 @@ +LEX = flex +CC = gcc +OUTPUT = lex_analyzer + +all: $(OUTPUT) + +$(OUTPUT): lex_analyzer.l + $(LEX) lex_analyzer.l + $(CC) lex.yy.c -o $(OUTPUT) + +clean: + rm -f lex.yy.c $(OUTPUT)