Question: I need to construct a c++ class that defines a parser. This parser will be able to break up a string into tokens. A token

I need to construct a c++ 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.

How can I do this by making use of the algoritms module, std::find, std::vector, and iterator types.

The class TokenParser should be declared in TokenParser.h and contain the following methods:

// Default constructor TokenParser() Default constructor for this class; creates a parser with no initial single-character tokens.

TokenParser(const vector<char>& tokens) Constructor for this class; creates a parser with the provided single-character tokens defined.

void setCharacterTokens(const vector<char>& tokens) Resets this parsers single-character tokens to the provided list of tokens.

void addCharacterTokens(const vector<char>& newTokens) Adds the provided single-character tokens to the set of tokens this parser recognizes.

void addCharacterToken(char newToken) Adds the provided single-character token to the set of tokens this parser recognizes.

vector<string> parse(string input) const Parses the string and returns a vector of tokens in string form.

You may, at our option, add any private class methods that help you accomplish this goal. DO NOT add any additional public methods or variables, as this violates encapsulation safety.

It is suggested that students consider using a following private helper method similar to the following:

vector<string> tokenize(string snippet) dBreaks a whitespace-free snippet into tokens by finding and splitting at single-character tokens.

How can I do this?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!