ITEC 320: Programming Assignment 5
Due Date: 11:59:59 p.m.
5:00 p.m., Friday 4/27/2018
Late programs NOT accepted after 11:59:59 p.m. Saturday
itec320-01 yarc.adb stackpkg.adb stackpkg-print.adb tree_pkg.adb
- 2018 Apr 27 12:15:13 PM: Added a tip about adding "pragma ada_2012" to the tree package body to
avoid a weird compiler error.
- 2018 Apr 26 01:37:23 PM: Changed the due time! Added a Tips section below.
- 2018 Apr 21 11:20:17 PM: Finalized assignment and assignment checker. Added a couple of "Other points" on error checking.
- 2018 Apr 20 09:29:23 PM: Corrected typos in the submit command above
- 2018 Apr 20 09:57:53 AM: Added pragma_Ada_2012 to treepkg and comments to package specs, prettified them, made a few formatting changes and
started (draft) assignment checker
- 2018 Apr 18 12:22:14 PM: Made changes to all 3 ads files. Make sure that you have a current version, and that you don't have
a cached version.
Note: the command j/J may change letters.
I may add some exceptions to the tree package.
- Routine names may still change slightly. Everything should be finalized Thursday
You can see an example of this program at assignment checker (which uses gnoga to
integrate the GUI, web server, and problem solution). On-campus or VPN session required.
- The statement "pragma Ada_2012" may be needed in the tree package body as
well as in the tree package specification. On some compilers,
having the pragma in the spec and not in the body causes a weird compiler error.
- The child stack package (stackpkg.print) needs to be instantiated
using the instantiated parent stack package, not stackpkg.
notes on child generic packages.
- Since the stack is a stack of Trees, it is a stack of pointers to
Tree nodes. When two Trees are popped from the stack and used to
create a new oper Tree node, it is references that are removed from
the stack and stored in the new Tree node.
A diagram showing this is in last picture
(20180425_110002.jpg) from Wednesday.
- Make sure that your pop routine and your clear routine do not
You are to write an Ada program whose input is RPN calculations, along with certain other commands.
Your program will use a stack implemented with linked lists, and it will also use
a linked tree structure to store a calculation.
2 3 4 * + 14 RTIJ q
produces this output:
2 3 4 * +
See the assignment checker for more on the commands. Try h and H for help.
Input comes from standard input and consists of rpn integer calculations
using +, -, *, / (integer division), and (maybe) ^ (exponentiation).
Commands to the calculator include the following:
Print a newline after each command result.
- c - clear the top top element from the stack
- C - clear all elements from the entire stack
- e - evaluate and print the expression tree on top of the stack
- E - evaluate and print the expression trees on the entire stack
- h - help (condensed)
- H - help
- i - print the current top of the stack, as an infix expression
- I - print the entire stack, as a list of infix expressions
- j - print the current top of the stack, as an infix tree
- J - print the entire stack, as a list of infix trees
- n - print number of nodes in the element on the top of the stack
- N - print total number of nodes on all elements of the stack
- p - pretty print (as an expression tree, same as t) the top of the stack
- P - pretty print the entire tree (same as T)
- r - print the stack top as an rpn expression
- R - print the entire tree as rpn expressions
- s - print the size of the stack (ie number of stack elements)
- S - same as s - print the stack size
- t - print the current top of the stack, as an expression tree
- T - print the entire stack, as a list of expression trees
- q - quit
You must implement a dynamic implementation of a stack and a calculation tree,
stack (and prettified) and
stack.print (and prettified) and
tree package specifications (and prettified).
It is important that you do not make any changes to these specification
Also make sure that you have a current version, and not a cached copy, of these routines.
- Your program should be called
- Your program must not create garbage.
- Negative numbers are input using _ (eg -34 is read as _34).
- Errors to catch: invalid characters, overflow, and missing q
- You may choose whether it's an error to print and clear an empty stack.
You will want to structure your program well and make good use of language features.
As always, be sure to use good indentation, descriptive constant, variable,
type, function, procedure, and package names. Use named constants when
appropriate. Also use good commenting style, remembering that the first
thing in any program file should be a comment that gives a brief overview
of what the file contains (and should do). You might find these
commenting guidelines helpful.
When testing, be sure to use lots of different examples.
You can either supply test data at the keyboard (remembering
to end the input with a ^D at the beginning of a line), or by feeding the
contents of a file to it (e.g. calc < test_data) where the use of the
UNIX redirection symbol < causes
the contents of the file test_data to be
feed into the program as if they had been typed in from the keyboard.
When debugging programs, run-time exceptions are a common
occurrence. One way to find the line at which an exception occurs is to
place put statements in your program so you can follow it's execution.
Another way is to use the gdb debugger (ie gnu debugger):
these instructions show you how.
Note that you can also use gvd (the gnu visual debugger) to debug your
program and find the source of an exception as well as other information.
Use the submit command to turn your
program in for grading. You may submit
as many times as you like, but since only the last submission
is kept, if the last one is late, then your assignment is late.
Always remember to use the -ls option of submit to check that your submission
To submit your work you can use the command at page top.