Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the MinusMinusV 4 . zip skeleton under Files in Canvas to create an interpreter for the MinusMinus language. The basic layout of the program

Use the MinusMinusV4.zip skeleton under Files in Canvas to create an interpreter for the MinusMinus
language.
The basic layout of the program is 2 main that loads then executes the program, Program.h and
Program.cpp and Execute cpp which has the MinusMinus program itself with routines for going through
the program (more on that later), SymbolTable.h and SymbolTable.cpp for handling symbol tables for the
functions and procedure and local variables (two separate tables), the utility of Stack h and Stack cpp. The
Execute.cpp is the only file you need to submit. That's where you will change the execute functions (itis a
skeleton for now).
With the execute function, remember it does an emulation of one function or procedure at a time and
needs to have passed to it the startLine (where the current function or procedure starts) and the number
of parameters to match the parameters with stack offsets (that's how parameters are passed). It will create
a local SymbolTable called locals for use for the current function or procedure. And if it needs to execute
another function/procedure, it can use the callTable to find out where the line is that started the
function/procedure.
The basic logic is to set currentLine string to the current line being executed. Then chop parts of it off.
The startParse function needs the current line number, called lineNumber, and it starts the parsing by
copying the current line into currentLine and chops the first part of it - and sets first part of it chopped
to to firstPart. There are several get functions that will chop off parts of currentline and give you a usable
token: getID to get 2 valid identifier, getS to get a string, getE to get an equation (can be a simple variable
or number or an equation). The boolEquation when given your locals SymbolTable will check the next
Boolean equation for you in currentLine (and chop it off, of course). The equation function will take the
equation in a string with the locals and give you back the result. The chopFrontBack will chop off the first
pass value of characters off of currentLine and remove any spaces at the end
I need help to fill in the execute.cpp file for MinusMinusV4 interpreter
//
// execute.cpp
// MinusMinusV4
#include "Program.hpp"
int Program::execute(int startLine, int numParms){
Commands code, scan;
string temp, id, eq;
SymbolTable locals;
Symbol symbol;
int offset, count, value =0, numLocals =0;
int countIf =0, countWhile =0, x;
int skipIf, skipWhile;
bool valid, print = false, function = false;
int lineNumber = startLine;
code = startParse(lineNumber);
if (code == FUNCTION)
function = true;
else if (code != FUNCTION && code != PROCEDURE){
errorMsg("Execute not starting at a procedure nor function");
return 0;
}
if (!getID(temp))
return 0;
getParms(locals, numParms);
// do proc/func
while (errorCount ==0 && code != RETURN &&
++lineNumber < numOfLines){
code = startParse(lineNumber);
switch (code){
case ASSIGN:
// put in assign code
break;
case BLANK:
case COMMENT:
currentLine =""; // no interpreting
break;
case CALL:
// put in call code
break;
case DECLARE:
// put in declare code
break;
case ENDIF:
// put in end if code
break;
case ENDWHILE:
// put in end while code
break;
case ENDPROCEDURE:
// put in end procedure code
break;
case ENDFUNCTION:
// put in end function code
break;
case IF:
// put in if code
break;
case INPUT:
// put in input code
break;
case PRINT:
print = true;
case PRINTLN:
// put in print/println code
break;
case FUNCTION: // has same error as procedure
case PROCEDURE:
getID(temp);
errorMsg(temp +
" cannot be defined inside another function/procedure");
break;
case RETURN:
// put in return code
break;
case UNKNOWN:
errorMsg("Unknown command");
break;
case WHILE:
// put in while code
break;
}
if (currentLine.length()>0){
//cout <<"|"<< currentLine <<"|
";
errorMsg("Misc characters after command");
}
}
// lastly, get rid of the parmeters,
// the local variables, and whiles
stack.pop(numParms + numLocals +
countWhile);
return value;
}
If more info is needed let me know

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

The Millionaire Next Door The Surprising Secrets Of Americas Wealthy

Authors: Thomas J. Stanley, William D. Danko

1st Edition

1589795474, 978-1589795471

Students also viewed these Databases questions