Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

prog2_1 Create a C++ Tokenizer class. This Tokenizer class will consist of both a header and a class file. You will create the prog2_1.hpp and

image text in transcribedimage text in transcribed

prog2_1 Create a C++ Tokenizer class. This Tokenizer class will consist of both a header and a class file. You will create the prog2_1.hpp and prog2_1.cpp This Tokenizer class will have four public methods. First, the constructor, which will setup/cre- ate any internal data structures you need. Second, the destructor, which will delete any inter- nal data structures you created during the lifetime of the object. Third will be a void function that takes a single string argument name Tokenize. This Tokenize function will tokenize the input string on the space character. Only the following to- kens are valid: push, pop, add, sub, mul, div, mod, skip, save, get and any valid integer. If an input string contains a potential token that is not one of those values the function should throw a std::exception with the message "Unexpected token: " where is re- placed by the unexpected token. (If the input was foobar 3.14" only the first bad token 'foo- bar' should cause the exception, which should read Unexpected token: foobar". Any valid input should then have all of those tokens saved inside the tokenizer in some sort of queue structure that will return them when requested by the GetTokens function. Fourth will be a vector function that takes no arguments named GetTokens. This function will retrieve a single set of input tokens that had previously been passed to the func- tion Tokenize in a queue fashion (the first input to Tokenize is the first output from GetTo- kens). If there are no remaining outputs the function should throw a std::exception with the message "No tokens. This Tokenizer class will be used by prog2_1. prog2_2 Create a driver program that will take a single command line argument which will be the name of a file. Your program should then Tokenize each line of that file. Your program 2 2 should Tokenize all of the input before it outputs anything. If any input line would cause a Tokeniza- tion error, print the following error message: Error on line : Unexpected token: " And stop processing the file. No other output should occur. If there are no tokenization errors, the tokens should be printed to STDOUT comma sepa- rated, line by line. Example compilation: g++ prog2_2.cpp prog2_1.cpp -o prog2_2 Example execution: ./prog2 2 testfile.txt testfile.txt contents: push 3 foobar 3.14 prog2_1 Create a C++ Tokenizer class. This Tokenizer class will consist of both a header and a class file. You will create the prog2_1.hpp and prog2_1.cpp This Tokenizer class will have four public methods. First, the constructor, which will setup/cre- ate any internal data structures you need. Second, the destructor, which will delete any inter- nal data structures you created during the lifetime of the object. Third will be a void function that takes a single string argument name Tokenize. This Tokenize function will tokenize the input string on the space character. Only the following to- kens are valid: push, pop, add, sub, mul, div, mod, skip, save, get and any valid integer. If an input string contains a potential token that is not one of those values the function should throw a std::exception with the message "Unexpected token: " where is re- placed by the unexpected token. (If the input was foobar 3.14" only the first bad token 'foo- bar' should cause the exception, which should read Unexpected token: foobar". Any valid input should then have all of those tokens saved inside the tokenizer in some sort of queue structure that will return them when requested by the GetTokens function. Fourth will be a vector function that takes no arguments named GetTokens. This function will retrieve a single set of input tokens that had previously been passed to the func- tion Tokenize in a queue fashion (the first input to Tokenize is the first output from GetTo- kens). If there are no remaining outputs the function should throw a std::exception with the message "No tokens. This Tokenizer class will be used by prog2_1. prog2_2 Create a driver program that will take a single command line argument which will be the name of a file. Your program should then Tokenize each line of that file. Your program 2 2 should Tokenize all of the input before it outputs anything. If any input line would cause a Tokeniza- tion error, print the following error message: Error on line : Unexpected token: " And stop processing the file. No other output should occur. If there are no tokenization errors, the tokens should be printed to STDOUT comma sepa- rated, line by line. Example compilation: g++ prog2_2.cpp prog2_1.cpp -o prog2_2 Example execution: ./prog2 2 testfile.txt testfile.txt contents: push 3 foobar 3.14

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

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

Be able to differentiate between arbitration and mediation

Answered: 1 week ago