What about the parse method


Problem

Consider the "object-oriented" implementation of the Core interpreter with classes such as Stmt, SS, etc. corresponding, respectively, to , , , etc. For this problem, you have to show how you can use (subtype-) polymorphism in the implementation of the Stmt class, with classes such as Assign, If, corresponding to the various alternative types of statements being derived classes of the Stmt class. The Print, and Execute, of Stmt will both be abstract (or, in C++ terminology, pure virtual) methods.

What about the Parse method? There are a couple of different approaches. The first one would be based on the observation that a node in an abstract parse tree of Core must necessarily be the child of a node. Given that fact, we could have the parseSS() method construct. on the basis of OTLA, an instance of the appropriate derived class of the Stmt class. While this approach would work, I don't recommend it because it "pollutes" the SS class with information about different types of Stmt.

A better approach would be to define parseStmt() as a static method of the Stmt class and have it behave in a way that may be reminiscent of the parseId() method. What parseStmt() should do is construct, on the basis of OTLA, an object of type Assign or If or Loop or In or Out and then call the parseSt() method (which will be defined in the individual derived classes) on this object. Note that parseSt() will also be a method of the Stmt class but there it will be an abstract method. The reason for having this abstract method is to take advantage of (subtype) polymorphism.

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: What about the parse method
Reference No:- TGS03264440

Expected delivery within 24 Hours