CS 3040, Exercise 7: a tiny ANTLR project

This exercise will get you set up with ANTLR using a VM and then have you modify an existing ANTLR file. You may work with others if you find it helpful, but each student must submit their own solution.

Installing Virtual Box and the VM

  1. Download and install VirtualBox from here. You will likely want the version for Windows unless you are using a different environment.
  2. Search lower on the page for "VirtualBox Extension Pack" and download that as well.
  3. Run the VirtualBox installer using the defaults. Then run the extension pack installer.
  4. Download the Ubuntu22Antlr image from here. This is a shareable link within Box, but you may need to log in to Box to access it.
  5. Start VirtualBox.
  6. Click on the Import icon (the yellow arrow) at the top of the screen.
  7. Check that Source is Local File System, and click on the picture of the folder to browse to where you download Ubuntu22Antlr.ova. Open that file.
  8. Click on Import
  9. Start Ubuntu. The password is the default, vmboxes. You can use the passwd command at the terminal prompt to change it.
  10. Select Insert Guest Additions CD Image from the Devices menu at the top of the Ubuntu window. This will enable using cut and paste between windows.
  11. Within Ubuntu, open settings and set the Display to a reasonable resolution such as 1200 by 800.
In this VM, use antlr4 as the command:
     antlr4 -Dlanguage=Python3 adder.g4
Note the 4 in this command!

Example

Modify the Adder example to include an average command that will average a list of numbers. The average is to both allow floating-point values and compute a floating-point result. Do not change the add command; that should still take and produce an integer. (The two have different types so you can get experience with multiple types in this sort of application.) For example,
        ave 3.5, 4.8, 2
        add 3, 5, 2
        ave 8
would print something like
        Average: 3.43333333
        Sum: 10
        Average: 8.0
There is no need to control the number of decimal places printed for ave.

The only file you should need to modify is adder.g4. In a perfect world you would rename this file to something more general than "adder", but it is probably simpler if you do not.

Feel free to ask for help with any Python questions you might have in addition to help with ANTLR and installation.

Additional Notes

Submission

Submit an evidence document showing your solution working on relevant cases. You should include easy-to-compute results, more extensive results, and a case with a single value. Include results for both the ave and add cases. Submit this as a PDF. In addition, submit any ANTLR and Python files you modify. Do not submit files that are generated by ANTLR.