Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java code needed give me the code what you understood from this question Introduction We have now completed the parser! We have a complete AST.

image text in transcribed

image text in transcribed

image text in transcribed

java code needed

give me the code what you understood from this question

Introduction We have now completed the parser! We have a complete AST. One thing that is important to remember as we write the interpreter is that the AST is now read only. We cannot make any changes to it as we interpret. Overall, the interpreter will feel a lot like the parser. It is a class with a lot of methods, almost the same methods as the parser. Which makes sense - the parser made (for example) IfNode. The interpreter needs to process IfNode. One of the key things that we must do in the interpreter is deal with variables. The AST declares the variables, but we need to be able to create and reference the variables as we find VariableReferenceNodes in the AST. We will create new classes to hold each of the data types that Shank knows about. Finally, one thing that we haven't talked about at all is the built-in functions. We will create a class for each of the built-in functions. Built in functions can do something that user-defined functions cannot accept any number of parameters of any type (like read and write do). This is called variadic. C and Java both do this. Details IDTs Create a new class, InterpreterDataType. It is an abstract class with two methods: public abstract String Tostring(); public abstract void Fromstring(String input); Details IDTs Create a new class, InterpreterDataType. It is an abstract class with two methods: public abstract String Tostring(); public abstract void Fromstring(String input); Note - FromString is only to be used for Read (which we will see later). Now create subclasses of InterpreterDataType: IntegerDataType, RealDataType, ArrayDataType, StringDataType, CharacterDataType, BooleanDataType. They need storage and constructors as well as implementing the two abstract methods mentioned above. ArrayDataType should be generic to accept an InterpreterDataType derived class. Build the Built-Ins There are a number of built-in functions in the Language Definition Document. These need to be built. For each of these functions, we will be making a class that is a sub-class of FunctionNode. So, for example, BuiltInRead extends FunctionNode. Each of these new classes will need an execute method. That method will do the actual work. Execute has no return type and everyone accepts a collection of InterpreterDataType. Remember that Shank functions have no return type. Add an isVariadic method to FunctionNode. It defaults to return false, but in the case of read and write. should be overridden to return true. For the "actual work", check the IDT types to make sure that they are correct, then use Java to do the work. While there are a lot of these, they are very short because the work to be done has Java methods that you can use. For the "var" parameters, change the value in the IDT. After parse() is called and you have a ProgramNode, create one of each of the built-in nodes and insert it into the FunctionNode hash map by name

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago