From 3fd1c05c8cee445119374fb2a771aaec87f12511 Mon Sep 17 00:00:00 2001 From: Jenessy Lustre Date: Tue, 5 Nov 2024 15:26:53 -0800 Subject: [PATCH] Revert "Merge branch 'main' of gitlab.cs.wallawalla.edu:lustje/language-interpreter-lab" --- lab-4/parser.bison | 2 - lab-4/scanner.flex | 2 - lab-5/README.md | 52 +++++++++++++------------- lab-5/samples/array_assignment.c | 1 + lab-5/samples/array_read.c | 2 + lab-5/samples/array_write.c | 4 ++ lab-5/samples/assignment_statement.c | 1 + lab-5/samples/hello-world.cbl | 5 --- lab-5/samples/multiple_statements.c | 2 + lab-5/samples/print_if_equal.c | 6 +++ lab-5/samples/print_if_false.c | 5 +++ lab-5/samples/print_if_true.c | 5 +++ lab-5/samples/print_statement.c | 1 + lab-5/samples/print_variable.c | 2 + lab-5/samples/program.c | 2 + lab-5/samples/quadratic-snippet.cbl | 35 ------------------ lab-5/samples/sorting-snippet.cbl | 55 ---------------------------- 17 files changed, 58 insertions(+), 124 deletions(-) create mode 100644 lab-5/samples/array_assignment.c create mode 100644 lab-5/samples/array_read.c create mode 100644 lab-5/samples/array_write.c create mode 100644 lab-5/samples/assignment_statement.c delete mode 100644 lab-5/samples/hello-world.cbl create mode 100644 lab-5/samples/multiple_statements.c create mode 100644 lab-5/samples/print_if_equal.c create mode 100644 lab-5/samples/print_if_false.c create mode 100644 lab-5/samples/print_if_true.c create mode 100644 lab-5/samples/print_statement.c create mode 100644 lab-5/samples/print_variable.c create mode 100644 lab-5/samples/program.c delete mode 100644 lab-5/samples/quadratic-snippet.cbl delete mode 100644 lab-5/samples/sorting-snippet.cbl diff --git a/lab-4/parser.bison b/lab-4/parser.bison index ea371e0..e4c4b6f 100644 --- a/lab-4/parser.bison +++ b/lab-4/parser.bison @@ -28,8 +28,6 @@ int yylex(); %token TOKEN_UNTIL %token TOKEN_END_PERFORM %token TOKEN_IF -%token TOKEN_ELSE -%token TOKEN_ELSE_IF %token TOKEN_END_IF %token TOKEN_SPACE %token TOKEN_KEYWORD_OCCURS diff --git a/lab-4/scanner.flex b/lab-4/scanner.flex index b6843eb..4a3e7e4 100644 --- a/lab-4/scanner.flex +++ b/lab-4/scanner.flex @@ -27,8 +27,6 @@ PERFORM { return TOKEN_PERFORM; } END-PERFORM { return TOKEN_END_PERFORM; } IF { return TOKEN_IF; } END-IF { return TOKEN_END_IF; } -ELSE { return TOKEN_ELSE; } -ELSE-IF { return TOKEN_ELSE_IF; } SPACE { return TOKEN_SPACE; } PIC { return TOKEN_PICTURE; } OCCURS { return TOKEN_KEYWORD_OCCURS; } diff --git a/lab-5/README.md b/lab-5/README.md index 41ea8ad..b9e30d0 100644 --- a/lab-5/README.md +++ b/lab-5/README.md @@ -5,23 +5,24 @@ See the [example lab for Python](https://gitlab.cs.wallawalla.edu/cptr354/langua In this lab, you will focus on basic operations that support your sample code. -- Arithmetic operations - Jenessy - - add - - subtract - - multiple - - divide -- Functions (but implemented directly in the language) - - Printing - Josh - - Square root - Jenessy -- Variable for numbers - Riley -- Variable for lists (or arrays) - Riley -- Branching statements - Josh -- Looping statements - Riley +* Arithmetic operations + * add + * subtract + * multiple + * divide +* Functions (but implemented directly in the language) + * Printing + * Square root +* Variable for numbers +* Variable for lists (or arrays) +* Branching statements +* Looping statements Notice you will find a new file `expr.c`. The file is used to implement the parser rule. Inside these functions, you will create the runtime code that is the interpreter. + ## Build Process The process is similar to prior labs. @@ -74,30 +75,31 @@ To remove the build files, use make clean. make clean ``` + ## Assignment Steps -1. Start by confirming these commands work for the sample code provided. +1. Start by confirming these commands work for the sample code provided. -1. Next copy over your `scanner.flex`, `parser.bison` and sample programs from lab 5. +1. Next copy over your `scanner.flex`, `parser.bison` and sample programs from lab 5. 1. Start working on your bison `parser.bison` and `expr.c` files to implement the interpreter part of your parser. + ## Grading Rubric The grading will be over the following categories. -Points Description +Points Description +----------- ------------------------------------ +30 points Ability to interpret — Hello world +30 points Ability to interpret — Quadratic equation +30 points Ability to interpret — Arithmetic operations +30 points Ability to interpret — Integer Sort example +20 points Ability to interpret — Looping operations +20 points Ability to interpret — Branching operations +20 points Ability to interpret — Array variables +10 points Report formatting and readability ---- - -30 points Ability to interpret — Hello world -30 points Ability to interpret — Quadratic equation -30 points Ability to interpret — Arithmetic operations -30 points Ability to interpret — Integer Sort example -20 points Ability to interpret — Looping operations -20 points Ability to interpret — Branching operations -20 points Ability to interpret — Array variables -10 points Report formatting and readability ## Turn In diff --git a/lab-5/samples/array_assignment.c b/lab-5/samples/array_assignment.c new file mode 100644 index 0000000..cce2d38 --- /dev/null +++ b/lab-5/samples/array_assignment.c @@ -0,0 +1 @@ +a = [ 4, 8, 12 ]; diff --git a/lab-5/samples/array_read.c b/lab-5/samples/array_read.c new file mode 100644 index 0000000..db30710 --- /dev/null +++ b/lab-5/samples/array_read.c @@ -0,0 +1,2 @@ +a = [ 3, 5 ]; +print a[0]; \ No newline at end of file diff --git a/lab-5/samples/array_write.c b/lab-5/samples/array_write.c new file mode 100644 index 0000000..4f81214 --- /dev/null +++ b/lab-5/samples/array_write.c @@ -0,0 +1,4 @@ +a = [ 3, 5, 7, 9, 11]; +print a[1]; +a[1] = 6; +print a[1]; diff --git a/lab-5/samples/assignment_statement.c b/lab-5/samples/assignment_statement.c new file mode 100644 index 0000000..a5a2277 --- /dev/null +++ b/lab-5/samples/assignment_statement.c @@ -0,0 +1 @@ +a = 5; \ No newline at end of file diff --git a/lab-5/samples/hello-world.cbl b/lab-5/samples/hello-world.cbl deleted file mode 100644 index 737f19e..0000000 --- a/lab-5/samples/hello-world.cbl +++ /dev/null @@ -1,5 +0,0 @@ -IDENTIFICATION DIVISION. -PROGRAM-ID. HELLO-WORLD. -PROCEDURE DIVISION. - DISPLAY 'Hello World!' -STOP RUN. diff --git a/lab-5/samples/multiple_statements.c b/lab-5/samples/multiple_statements.c new file mode 100644 index 0000000..b31de4e --- /dev/null +++ b/lab-5/samples/multiple_statements.c @@ -0,0 +1,2 @@ +print 5; +print 6; diff --git a/lab-5/samples/print_if_equal.c b/lab-5/samples/print_if_equal.c new file mode 100644 index 0000000..e4a42e4 --- /dev/null +++ b/lab-5/samples/print_if_equal.c @@ -0,0 +1,6 @@ +if 3==3 then + print 3; +endif +if 3==4 then + print 4; +endif diff --git a/lab-5/samples/print_if_false.c b/lab-5/samples/print_if_false.c new file mode 100644 index 0000000..5340a03 --- /dev/null +++ b/lab-5/samples/print_if_false.c @@ -0,0 +1,5 @@ +if 0 then + print 5; + print 3; + print 1; +endif diff --git a/lab-5/samples/print_if_true.c b/lab-5/samples/print_if_true.c new file mode 100644 index 0000000..7848347 --- /dev/null +++ b/lab-5/samples/print_if_true.c @@ -0,0 +1,5 @@ +if 1 then + print 5; + print 3; + print 1; +endif diff --git a/lab-5/samples/print_statement.c b/lab-5/samples/print_statement.c new file mode 100644 index 0000000..1748ba7 --- /dev/null +++ b/lab-5/samples/print_statement.c @@ -0,0 +1 @@ +print 5; diff --git a/lab-5/samples/print_variable.c b/lab-5/samples/print_variable.c new file mode 100644 index 0000000..28aae29 --- /dev/null +++ b/lab-5/samples/print_variable.c @@ -0,0 +1,2 @@ +a = 4 + 4; +print a; diff --git a/lab-5/samples/program.c b/lab-5/samples/program.c new file mode 100644 index 0000000..f1f084a --- /dev/null +++ b/lab-5/samples/program.c @@ -0,0 +1,2 @@ +a=(101*20)+4; +print(a); diff --git a/lab-5/samples/quadratic-snippet.cbl b/lab-5/samples/quadratic-snippet.cbl deleted file mode 100644 index ab76e40..0000000 --- a/lab-5/samples/quadratic-snippet.cbl +++ /dev/null @@ -1,35 +0,0 @@ - *> Code altered from https://www.quora.com/What-is-a-COBOL-program-that-will-solve-a-quadratic-equation - *> Program finds the roots to a simple quadratic equation - - IDENTIFICATION DIVISION. - PROGRAM-ID. QuadraticSolver. - DATA DIVISION. - WORKING-STORAGE SECTION. - 77 a PIC S9(5)V9(5) COMP-3 VALUE 1. - 77 b PIC S9(5)V9(5) COMP-3 VALUE 5. - 77 c PIC S9(5)V9(5) COMP-3 VALUE 6. - 77 discriminant PIC S9(5)V9(5) COMP-3. - 77 root1 PIC S9(5)V9(5) COMP-3. - 77 root2 PIC S9(5)V9(5) COMP-3. - 77 square-root-discriminant PIC S9(5)V9(5) COMP-3. - - PROCEDURE DIVISION. *> program begins here - DISPLAY "EQUATION: (1x^2) + 5x + 6 = 0" - COMPUTE discriminant = (b ** 2) - (4 * a * c) - - IF discriminant > 0 - COMPUTE square-root-discriminant = FUNCTION SQRT(discriminant) - COMPUTE root1 = (-b + square-root-discriminant) / (2 * a) - COMPUTE root2 = (-b - square-root-discriminant) / (2 * a) - DISPLAY "The equation has two distinct real roots: " - DISPLAY "Root 1: " root1 - DISPLAY "Root 2: " root2 - - ELSE IF discriminant = 0 - COMPUTE root1 = -b / (2 * a) - DISPLAY "The equation has one real root: " - DISPLAY "Root: " root1 - ELSE - DISPLAY "The equation has no real roots." - - STOP RUN. diff --git a/lab-5/samples/sorting-snippet.cbl b/lab-5/samples/sorting-snippet.cbl deleted file mode 100644 index 8324e47..0000000 --- a/lab-5/samples/sorting-snippet.cbl +++ /dev/null @@ -1,55 +0,0 @@ -IDENTIFICATION DIVISION. -PROGRAM-ID. sorting. -DATA DIVISION. -WORKING-STORAGE SECTION. - 01 WS-SORT-AREA. - 05 WS-SORT-TABLE. - 10 WS-SORT-ROW PIC X(10) OCCURS 100. - 05 WS-TEMP-ROW PIC X(10). - 05 WS-ROW-MAX PIC S9(4) COMP VALUE 100. - 05 WS-SORT-MAX PIC S9(4) COMP. - 05 WS-I PIC S9(4) COMP. - 05 WS-J PIC S9(4) COMP. - 05 WS-INDEX PIC S9(4) COMP. - -PROCEDURE DIVISION. -*> Initialize test data - MOVE "30" TO WS-SORT-ROW(1) - MOVE "10" TO WS-SORT-ROW(2) - MOVE "50" TO WS-SORT-ROW(3) - MOVE "20" TO WS-SORT-ROW(4) - MOVE "40" TO WS-SORT-ROW(5) - MOVE 5 TO WS-SORT-MAX - -*> * Display original array - DISPLAY "Original Array Contents:" - DISPLAY "---------------------" - PERFORM VARYING WS-INDEX FROM 1 BY 1 - UNTIL WS-INDEX > WS-SORT-MAX - DISPLAY "Element " WS-INDEX ": " WS-SORT-ROW(WS-INDEX) - END-PERFORM - DISPLAY SPACE - -*> * Simplified bubble sort - PERFORM VARYING WS-I FROM 1 BY 1 - UNTIL WS-I > WS-SORT-MAX - 1 - PERFORM VARYING WS-J FROM 1 BY 1 - UNTIL WS-J > WS-SORT-MAX - WS-I - IF WS-SORT-ROW(WS-J) > WS-SORT-ROW(WS-J + 1) - MOVE WS-SORT-ROW(WS-J) TO WS-TEMP-ROW - MOVE WS-SORT-ROW(WS-J + 1) TO WS-SORT-ROW(WS-J) - MOVE WS-TEMP-ROW TO WS-SORT-ROW(WS-J + 1) - END-IF - END-PERFORM - END-PERFORM - -*> * Display sorted array - DISPLAY "Sorted Array Contents:" - DISPLAY "--------------------" - PERFORM VARYING WS-INDEX FROM 1 BY 1 - UNTIL WS-INDEX > WS-SORT-MAX - DISPLAY "Element " WS-INDEX ": " WS-SORT-ROW(WS-INDEX) - END-PERFORM. - - STOP RUN. - \ No newline at end of file