+1 (315) 557-6473 

Program To Create an Interpreter, Using Java Programming Language Assignment Solutions.


Instructions

Objective
Write a java assignment program to create an interpreter.

Requirements and Specifications

Program to create a interpreter in Java programming language

Source Code

package interpreter;

import interpreter.loaders.ByteCodeLoader;

import interpreter.loaders.CodeTable;

import interpreter.loaders.InvalidProgramException;

import interpreter.virtualmachine.Program;

import interpreter.virtualmachine.VirtualMachine;

/**

 *

 * Interpreter class runs the interpreter:

 * 1. Perform all initializations

 * 2. Load the ByteCodes from file

 * 3. Run the virtual machine

 *

 * THIS FILE CANNOT BE MODIFIED. DO NOT

 * LET ANY EXCEPTIONS REACH THE

 *

 *

 */

public class Interpreter {

    private ByteCodeLoader byteCodeLoader;

    public Interpreter(String codeFile) {

        CodeTable.init();

        byteCodeLoader = new ByteCodeLoader(codeFile);

    }

    void run() {

        Program program = null;

        try{

            program = byteCodeLoader.loadCodes();

        } catch(InvalidProgramException ex){

            System.out.println(ex);

            ex.printStackTrace();

            System.exit(-2);

        }

        program.resolveAddress();

        VirtualMachine virtualMachine = new VirtualMachine(program);

        virtualMachine.executeProgram();

    }

    public static void main(String args[]) {

        if (args.length == 0) {

            System.out.println("***Incorrect usage, try: java interpreter.Interpreter ");

            System.exit(1);

        }

        (new Interpreter(args[0])).run();

    }

}