Answered Essay: All code must be written using C++ programming language.

All code must be written using C++ programming language.

You will construct a class that defines a parser. This parser will be able to break up a string into tokens. A token is a distinct string of text – it can be a word, a symbol, or a combination of these. Your parser will eliminate whitespace and break string snippets into individual tokens (where single-character tokens are defined at runtime).

Your parser should behave as follows:

1) Whitespace (spaces, tabs, and new lines) is used only to separate tokens – otherwise, it is ignored.
2) Most tokens are made up of strings of text separated punctuation and other symbols.
3) In addition, single-character tokens (punctuation and/or other symbols) may be defined.

The parser should treat symbols like any other text character. The default behavior will that all characters not separated by whitespace will be part of the same token. However, the parser will provide several functions that will allow the user to define additional, single-character symbols as token as well.

Target Output:

Input strings
————-
[{Oh what a loon() I am! Don’t you agree?}]
[I’ll sing “Amazing Grace” for $5.
Please call1 the #867-5309.]

Output Delimiting/Parsing by Whitespace only:
—————
[ {Oh what a loon() I am! Don’t you agree?} ]
[ I’ll sing “Amazing Grace” for $5. Please call1 the #867-5309. ]

Output Delimiting/Parsing by Block markers:
————–
[ { Oh what a loon ( ) I am! Don’t you agree? } ]
[ I’ll sing ” Amazing Grace ” for $5. Please call1 the #867-5309. ]

Output Delimiting/Parsing by Punctuation added:
——————
[ { Oh what a loon ( ) I am ! Don ‘ t you agree ? } ]
[ I ‘ ll sing ” Amazing Grace ” for $5 . Please call1 the #867-5309 . ]

Output Delimiting/Parsing by Symbols added:
————–
[ { Oh what a loon ( ) I am ! Don ‘ t you agree ? } ]
[ I ‘ ll sing ” Amazing Grace ” for $ 5 . Please call1 the # 867 – 5309 . ]

Expert Answer

 

//TokenParser.h
//Include the needed header files
#ifndef TokenParserClass_h
#define TokenParserClass_h
#include <iostream>
#include <vector>
using namespace std;

//Class
class TokenParser
{
//Access specifier
private:

//Declare
vector<char> listOfTokens;

//Method declaration tokenize()
vector<string> tokenize(string snippet) const;

//Access specifier
public:

//Default constructor
TokenParser();

//Constructor
TokenParser(const vector<char>& tokens);

//Method declaration setCharacterTokens()
void setCharacterTokens(const vector<char>& tokens);

//Method declaration addCharacterTokens()
void addCharacterTokens(const vector<char>& newTokens);

//Method declaration addCharacterToken()
void addCharacterToken(char newToken);

//Method declaration parse()
vector<string> parse(string input) const;

//Method declaration show()
void show();
};
#endif

//TokenParser.cpp
//Include the needed header files
#include “TokenParser.h”
using namespace std;

//Method definition tokenize()
vector<string> TokenParser::tokenize(string snippet) const
{
//Declare
vector<string> tokens;

//Loop
for(int index = 0; index < snippet.size(); index++)
{
//Push
tokens.push_back(string(1,snippet[index]));
}

//Return
return tokens;
}

//Constructor definition
TokenParser::TokenParser(){}

//Constructor definition
TokenParser::TokenParser(const vector<char>& tokens)
{
//Initialize
listOfTokens = tokens;
}

//Method definition setCharacterTokens()
void TokenParser::setCharacterTokens(const vector<char>& tokens)
{
//Set
listOfTokens = tokens;
}

//Method definition addCharacterTokens()
void TokenParser::addCharacterTokens(const vector<char>& newTokens)
{
//Insert
listOfTokens.insert(listOfTokens.end(), newTokens.cbegin(), newTokens.cend());
}

//Method definition addCharacterToken()
void TokenParser::addCharacterToken(char newToken)
{
//Insert
listOfTokens.push_back(newToken);
}

//Method definition parse()
vector<string> TokenParser::parse(string input) const
{
//Return
return tokenize(input);
}

//Method definition show()
void TokenParser::show()
{
//Loop
for(vector<char>::iterator iter = listOfTokens.begin(); iter != listOfTokens.end(); ++iter)
{
//Display
cout << *iter << ” “;
}
}

//Driver.cpp
//Include the needed header files
#include “TokenParser.h”
#include <iostream>
#include <string>
using namespace std;

//Driver
int main()
{
//Vector 1
vector<char> vector1 = {‘h’, ‘a’, ‘p’, ‘p’,’y’};

//Vector 2
vector<char> vector2 = {‘d’, ‘a’, ‘y’};

//Vector 3
vector<char> vector3 = {‘c’,’o’,’m’, ‘e’};

//Function call
TokenParser parser(vector1);

//Display
cout << “The contents of the parser loaded with the vector ‘vector1’ is ” << endl;

//Function call
parser.show();

//Display
cout << “nAdding the vector ‘vector2’ into the parser” << endl;

//Function call
parser.addCharacterTokens(vector2);

//Function call
parser.show();

//Display
cout << “nSetting the parser tokens to the vector ‘vector3′” << endl;

//Function call
parser.setCharacterTokens(vector3);

//Function call
parser.show();

//Function call
vector<string> vector4 = parser.parse(“again”);

//Display
cout << “nShowing the vector of strings ‘vector4’ created employing parse(“again”)” <<endl;

//Loop
for(vector<string>::iterator iter = vector4.begin(); iter != vector4.end(); ++iter)

//Display
cout << *iter << ” “;

//Display
cout << “nThe End!” <<endl;
}

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?