Define a new run-time exception named LukaSyntaxException

computer science



Edit the Dictionary class to include exceptions so that when you run the class DictionaryTest, all tests pass. For example, the method put in the class Dictionary should include the following exception handling:

public void put(String key, Token value) {
if (key == null || value == null) {
throw new NullPointerException("key or value is null");
if (count == elems.length) {
// Similarly to the array-based implementation
// of a stack, I am adding elements at the end
elems[count] = new Pair(key, value);

  • Define a new run-time exception named LukaSyntaxException.
  • Make changes to the class Interpreter so that when the following situations are detected, an exception of type LukaSyntaxException is thrown.
  • When an illegal symbol has been found. All illegal symbols are symbols that is nor a reserved keyword (operation), nor an existing association in the dictionary.(Note nor is a Boolean operator that gives the value one if and only if all operands have a value of zero and otherwise has a value of zero.)
  • When undefining a non-existing association.
  • When updating a non-existing association.
  • The class Interpreter will display the appropriate messages, including:
  • The symbol table.
  • Operands stack.
  • Make changes to the class Viewer so that exceptions of type LukaSyntaxException are caught. When catching the exception, the method displays the type of the exception and its message. Finally, the application exits.
/x 1 def /y 2 def x y /z 3 set
Dictionary: {elems = [{key=y,value=2}, {key=x,value=1}]}
DynamicArrayStack: {3,z,2,1}
caught LukaSyntaxException


For instance, upon executing the following Luka program:

The application would print the following information and exit.

Related Questions in computer science category

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.