cobol-interpreter-lab/lab-5
vel 1e4c127762
Merge branch 'josh_11_7' of gitlab.cs.wallawalla.edu:lustje/language-interpreter-lab
2024-11-15 10:09:23 -08:00
..
samples ast for quadratic is correct 2024-11-15 02:53:17 -08:00
Makefile we now strip characters in strings 2024-11-15 00:53:39 -08:00
README.md lab 5 2024-10-31 11:08:06 -07:00
expr.c Merge branch 'josh_11_7' of gitlab.cs.wallawalla.edu:lustje/language-interpreter-lab 2024-11-15 10:09:23 -08:00
expr.h Merge branch 'josh_11_7' of gitlab.cs.wallawalla.edu:lustje/language-interpreter-lab 2024-11-15 10:09:23 -08:00
main.c make it compile on code.cs 2024-11-14 17:47:59 -08:00
main_test.c Updating testing to use fixtures 2024-11-08 11:42:13 -08:00
parser.bison partial if implementation 2024-11-15 09:05:03 -08:00
parser.bison.new start work on getting hello world interpreting 2024-11-13 21:22:40 -08:00
parser_test.c hello world partially parses 2024-11-13 22:42:07 -08:00
scanner.flex we now strip characters in strings 2024-11-15 00:53:39 -08:00
scanner_test.c we now strip characters in strings 2024-11-15 00:53:39 -08:00
symbol_map.c lab 5 2024-10-31 11:08:06 -07:00
symbol_map.h lab 5 2024-10-31 11:08:06 -07:00
token.h make it compile on code.cs 2024-11-14 17:47:59 -08:00
utest.h Updating testing to use fixtures 2024-11-08 11:42:13 -08:00

README.md

Bison Interpreter

Create an interpreter for your sample programs. See the example lab for Python.

In this lab, you will focus on basic operations that support your sample code.

  • 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. To build the scanner.c run the following flex command.

flex -o scanner.c scanner.flex

The parser is built using bison. Note this command also builds the token.h.

bison --defines=token.h --output=parser.c parser.bison

Then build the main.c, expr.c, parcer.c and scanner.c using gcc. Note that you may get a few warnings that can be ignored.

gcc *.c -o interpreter.out

Then execute the test suite using ./interpreter.out and pass in the input from your sample program. For example here is a command for samples/program.c

./interpreter.out < samples/program.c

Single line command:

flex -o scanner.c scanner.flex && \
bison --defines=token.h --output=parser.c parser.bison && \
gcc *.c -o interpreter.out && ./interpreter.out < samples/program.c

Building with Make

To simplify the process a Makefile has been supplied.

make && ./interpreter.out < samples/program.c

To remove the build files, use make clean.

make clean

Assignment Steps

  1. Start by confirming these commands work for the sample code provided.

  2. Next copy over your scanner.flex, parser.bison and sample programs from lab 5.

  3. 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


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

Please submit the URL of your GitLab project to D2L's Brightspace with your report. On GitLab update the lab-5 folder to have your report and code snippets before the due date.