Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me Write the program in C++ is an interpreter, below this part of the program. I need you to do the , and

Please help me

Write the program in C++ is an interpreter, below this part of the program. I need you to do the , and . In the same format as the other programs with bool and etc.

image text in transcribed

image text in transcribed

image text in transcribed

#include #include #include

using namespace std;

bool isSign(char);

bool isDigit(char);

bool isDecimalPoint(char);

bool isInt(const string&);

bool isUnsign(const string&);

bool decPart(const string&);

bool isReal(const string&);//still needs implementation

bool isExponent(const string&);

bool expPart(const string&);

bool isNumber(const string&);//still needs implementation

int main()

{

const string num = "e";

cout

cout

cin.get();

}

bool isSign(const char ch)

{

return ch == '+' || ch == '-';

}

bool isDigit(const char ch)

{

return std::isdigit(static_cast(ch));

}

bool isDecimalPoint(const char ch)

{

return ch == '.';

}

bool isInt(const string& str)

{

if (str.length() == 1)

return isUnsign(str);

if (isSign(str[0]) || isDigit(str[0]))

{

if (isSign(str[0]) && !isDigit(str[1]))

return false;

const auto temp = str.substr(1);

return isUnsign(temp);

}

return false;

}

bool isUnsign(const string& str)

{

if (str.length() == 0)

return false;

for (const auto& i : str)

if (!isDigit(i))

return false;

return true;

}

bool decPart(const string& str)

{

if (isDecimalPoint(str[0]) && str.length() >= 2)

{

const auto temp = str.substr(1);

return isUnsign(temp);

}

return false;

}

bool isReal(const string&)//still needs implementation

{

return true;

}

bool isExponent(const string& input)

{

return (input[0] == 'E' || input[0] == 'e') && (input.length() == 1);

}

bool expPart(const string& str)

{

if(isExponent(str.substr(0,1)) && str.length()>1)

{

const auto pos = str.find('.');

if (pos == string::npos)

return false;

const auto temp = str.substr(1, pos - 1);

if(isInt(temp))

{

const auto temp2 = str.substr(pos);

if (decPart(temp2))

return true;

}

}

return false;

}

bool isNumber(const string&)//still needs implementation

{

return true;

}

#include #include

using namespace std;

bool isRead(const string &);

bool isString(const string &);

bool isLetter(char);

bool isLetter(string);

string askInput();

bool isExponent(const string & input);

bool isRem(const string & input); //for comment statements

int main() {

while (true) {

string input = askInput();

cout

if (isString(input))

cout

//if (isLetter(input)) cout

if (isRead(input)) cout

if (isExponent(input)) cout

if (isRem(input)) cout

}

}

bool isRead(const string & input) {

const string read = "read";

if (read.compare(input) == 0)

return true;

else return false;

}

bool isString(const string & input) {

if (input[0] == '"' && input[input.length() - 1] == '"')

return true;

else return false;

}

string askInput() {

string in;

cout

getline(cin, in);

return in;

}

bool isLetter(char ch) {

if (isalpha(ch)) {

return true;

}

else return false;

//return isalpha(static_cast(ch)); puedes usar esto (Joseph)

}

bool isLetter(string s) {

if (s.length() == 1 && isalpha(s[0])) {

return true;

}

else return false;

}

bool isExponent(const string & input) {

if ((input[0] == 'E' || input[0] == 'e') && (input.length()==1))

{

return true;

}

else return false;

}

bool isRem(const string & input) {

if (input.compare("rem") == 0)

return true;

else return false;

}

//

//

#include #include

using namespace std;

bool isVariable(string);

bool isLetter(char var1)

{

if (isalpha(var1))

{

return true;

}

else return false;

}

//Variables

int main()

{

int i;

string var1;

cout

cout

cin >> var1;

if(isVariable(var1)){

cout

}

else cout

cin.get();

return 0;

}

bool isVariable(string s){

for(int i = 0; i

{

if (!(isalpha(s[i])))

{

return false;

}

}

return true;

}

//

#include

#include

using namespace std;

/*

::= =

*/

//Variables

int main()

{

char var1;

cout

cout

cin >> var1;

if(var1 != '=')

{

cout

}

else

{

cout

}

cin.get();

return 0;

}

//Relational and Logical Operator

#include

#include

using namespace std;

bool isLogical(string var1)

{

if(var1 == ".or." || var1 == ".and." || var1 == ".not.")

{

return true;

}

else

{

return false;

}

}

bool isRelational(string var1)

{

if(var1 == ".gt." || var1 == ".lt." || var1 == ".eq." || var1 == ".ge." || var1 == ".le." || var1 == ".ne.")

{

return true;

}

else

{

return false;

}

}

int main()

{

string var1;

cout

cout

cin >> var1;

if(var1 == ".or." || var1 == ".and." || var1 == ".not.")

{

if(isLogical(var1) == 1)

{

cout

}

else if (isLogical(var1) == 0)

{

cout

}

}

else

{

if(isRelational(var1) == 1)

{

cout

}

else if (isRelational(var1) == 0)

{

cout

}

}

cin.get();

return 0;

}

// ::= + | -

#include

#include

using namespace std;

bool isSign(string var1)

{

if(var1 == "-" || var1 == "+" )

{

return true;

}

else

{

return false;

}

}

int main()

{

string var1;

cout

cout

cin >> var1;

if(isSign(var1) == 1)

cout

else

cout

cin.get();

return 0;

}

Design and implement an interpreter that executes the code written in LAO language. The statements in LAO language are: comment statement> ::-REM I REM any string> assignment statement> ::variable>-arithmetic ::-PRINT PRINT PRINT 1 PRINT READ variable> if statement> ::-1F TEENthen statement> . . ::-REM I REM any string> assignment statement> ::variable>-arithmetic ::-PRINT PRINT PRINT 1 PRINT READ variable> if statement> ::-1F TEENthen statement> . .

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

Students also viewed these Databases questions