Revert "Merge branch 'main' of gitlab.cs.wallawalla.edu:lustje/language-interpreter-lab"
This commit is contained in:
parent
16274068ed
commit
3fd1c05c8c
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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. 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
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
a = [ 4, 8, 12 ];
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
a = [ 3, 5 ];
|
||||
print a[0];
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
a = [ 3, 5, 7, 9, 11];
|
||||
print a[1];
|
||||
a[1] = 6;
|
||||
print a[1];
|
||||
|
|
@ -0,0 +1 @@
|
|||
a = 5;
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. HELLO-WORLD.
|
||||
PROCEDURE DIVISION.
|
||||
DISPLAY 'Hello World!'
|
||||
STOP RUN.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
print 5;
|
||||
print 6;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if 3==3 then
|
||||
print 3;
|
||||
endif
|
||||
if 3==4 then
|
||||
print 4;
|
||||
endif
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if 0 then
|
||||
print 5;
|
||||
print 3;
|
||||
print 1;
|
||||
endif
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if 1 then
|
||||
print 5;
|
||||
print 3;
|
||||
print 1;
|
||||
endif
|
||||
|
|
@ -0,0 +1 @@
|
|||
print 5;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
a = 4 + 4;
|
||||
print a;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
a=(101*20)+4;
|
||||
print(a);
|
||||
|
|
@ -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.
|
||||
|
|
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue