Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this problem is to see the use of OO polymorphism/dynamic dispatch in the implementation of interpreters. Consider a CORE-like language with the

The purpose of this problem is to see the use of OO polymorphism/dynamic dispatch in the implementation of interpreters. Consider a CORE-like language with the following syntax for statements: ::= | | | | | ::= ::= while loop end; ::= if then end; | if then else end; The productions for , , and are omitted; assume standard (CORE-like) syntax for those. Note also that there is no here; instead is one alternative for and this gives us the option of using more than one statement in place of a single statement so we dont need ; will be used in place of in the production for as well. Now for the problem: we want to implement an execute() method that can be used to execute such statements; we also have to implement all the related methods (such as execute() method for loops). The key point is that the execute() method of the Stmt class should not explicitly contain a multi-way selection to call the appropriate execute method based on the type of the statement being executed; instead, the dynamic dispatch mechanism of the underlying OO language is used to achieve that. To get you started, here is a possible class (in C++ syntax) for : class Stmt { public: virtual void execute( ) = 0; }; What you have to do is complete the Stmt class (if it needs any completion), and write down the classes corresponding to the different types of statements. Do not worry about the parse and print methods. Make sure that you write down not only the header portions of the classes but also the definitions of the (execute or exec) member methods. Your code does not have to be completely legal C++ but it must be readable and must be conceptually correct for you to get full credit.

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

Students also viewed these Databases questions