Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Question Please help!!! Please include screen shots of code compiling using strings that are provided in question and use the given methods. All code

C++ Question Please help!!!

Please include screen shots of code compiling using strings that are provided in question and use the given methods. 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: (will be stored as a character type vector)

--------------

[ { 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: (will be stored as a character type vector)

------------------

[ { 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: (will be stored as a character type vector)

--------------

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

PLEASE READ AND FOLLOW:

The parser for this assignment will, by default, treat symbols like any other text character in other words, 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 (detailed below) that will allow the user to definie additional, single character symbols as tokens as well.

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.

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

Describe loss aversion and myopic loss aversion.

Answered: 1 week ago

Question

2. Are my sources up to date?

Answered: 1 week ago