Calculator Assignment Modify a calculator program that currently displays the Abstract Syntax Tree (AST) structure after parsing an input expression. Instead of printing the AST, enhance the program to evaluate the expression and display the result. Add support for the binary "%" remainder (modulo) operator and introduce variables with the assignment operator "=". Key steps to implement the assignment operator and variables: Introduce a new static attribute in the AstNode class to represent variables: Add a method isIdentifier() to the TokenStream class to detect variables: Modify the primaryRule() in AstNode to handle variables and variable assignment: Handle new node types in the AstNode evaluate() method for variables and assignment: These changes allow the calculator to evaluate expressions, support variables, and handle variable assignments. Users can create and use variables in subsequent expressions. EmployeeJava Type:  package week3; import static week3.MainApp.*; public enum EmployeeType {     FULL_TIME  (EMPLOYEE_FULL_TIME),     PART_TIME  (EMPLOYEE_PART_TIME),     CONSULTANT (EMPLOYEE_CONSULTANT);     private int value;     public int getValue() {         return value;     }     private EmployeeType( int value ) {         this.value = value;     }          @Override     public String toString() {         if (this.ordinal() == FULL_TIME.ordinal() ) {             return "FT";         } else if (this.ordinal() == PART_TIME.ordinal() ) {             return "PT";                      } else {             return "CONSULTANT";         }     } } MAINAPP.java package week3; public class MainApp {     public static final int EMPLOYEE_FULL_TIME = 100;     public static final int EMPLOYEE_PART_TIME = 200;     public static final int EMPLOYEE_CONSULTANT = 300;     private static void printEmployeeType(EmployeeType employeeType) {         switch (employeeType) {             case FULL_TIME:                 System.out.println(employeeType.getValue());                 break;             case PART_TIME:                 System.out.println(employeeType.getValue());                 break;             case CONSULTANT:                 System.out.println(employeeType.getValue());                 break;         }     }//printEmployeeType     public static void main(String[] args) {         EmployeeType employeeType = EmployeeType.FULL_TIME;         printEmployeeType( employeeType );                  employeeType = EmployeeType.PART_TIME;         printEmployeeType( employeeType );                  employeeType = EmployeeType.CONSULTANT;         printEmployeeType( employeeType );     }//main

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Calculator Assignment

Modify a calculator program that currently displays the Abstract Syntax Tree (AST) structure after parsing an input expression. Instead of printing the AST, enhance the program to evaluate the expression and display the result. Add support for the binary "%" remainder (modulo) operator and introduce variables with the assignment operator "=".

Key steps to implement the assignment operator and variables:

  1. Introduce a new static attribute in the AstNode class to represent variables:
  2. Add a method isIdentifier() to the TokenStream class to detect variables:
  3. Modify the primaryRule() in AstNode to handle variables and variable assignment:
  4. Handle new node types in the AstNode evaluate() method for variables and assignment:

These changes allow the calculator to evaluate expressions, support variables, and handle variable assignments. Users can create and use variables in subsequent expressions.

EmployeeJava Type: 

package week3;
import static week3.MainApp.*;

public enum EmployeeType {
    FULL_TIME  (EMPLOYEE_FULL_TIME),
    PART_TIME  (EMPLOYEE_PART_TIME),
    CONSULTANT (EMPLOYEE_CONSULTANT);

    private int value;

    public int getValue() {
        return value;
    }

    private EmployeeType( int value ) {
        this.value = value;
    }
    
    @Override
    public String toString() {
        if (this.ordinal() == FULL_TIME.ordinal() ) {
            return "FT";
        } else if (this.ordinal() == PART_TIME.ordinal() ) {
            return "PT";
            
        } else {
            return "CONSULTANT";
        }
    }
}

MAINAPP.java

package week3;

public class MainApp {
    public static final int EMPLOYEE_FULL_TIME = 100;
    public static final int EMPLOYEE_PART_TIME = 200;
    public static final int EMPLOYEE_CONSULTANT = 300;

    private static void printEmployeeType(EmployeeType employeeType) {
        switch (employeeType) {
            case FULL_TIME:
                System.out.println(employeeType.getValue());
                break;
            case PART_TIME:
                System.out.println(employeeType.getValue());
                break;
            case CONSULTANT:
                System.out.println(employeeType.getValue());
                break;
        }
    }//printEmployeeType

    public static void main(String[] args) {
        EmployeeType employeeType = EmployeeType.FULL_TIME;
        printEmployeeType( employeeType );
        
        employeeType = EmployeeType.PART_TIME;
        printEmployeeType( employeeType );
        
        employeeType = EmployeeType.CONSULTANT;
        printEmployeeType( employeeType );
    }//main

}//class MainApp

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education