Representation of a simple interpreter. More...
#include <Interpreter_Class.h>
Public Member Functions | |
std::string | Interpret (IntList tokens) |
Given an array of integer tokens, convert the tokens into a single std::string of space-delimited words, following simple rules of formatting. | |
Public Attributes | |
const int | PERIOD = 100 |
const int | QUESTION = 101 |
Private Member Functions | |
std::string | _InterpretToken (int token) |
Helper method to convert the token into its corresponding word or punctuation mark. | |
Static Private Attributes | |
static const char * | _commonwords [] |
The 40 most common words in English (in order but that doesn't really matter here). A token is nothing more than an index into this list. | |
Representation of a simple interpreter.
This interpreter takes an array of integer tokens and converts each token into a word or punctuation mark. The interpreter then arranges the words into a space-separated list in a single string. In other words, the tokens are converted into a sentence, with the first word capitalized and no space between the last two "words" under the assumption the last word is actually a punctuation mark.
Interpreter Rules:
Definition at line 38 of file Interpreter_Class.h.
|
private |
Helper method to convert the token into its corresponding word or punctuation mark.
token | The token to interpret. |
A std::string containing the corresponding word or punctuation. If the token is not recognized, the std::string returns "<UNKNOWN TOKEN #>", where
Definition at line 62 of file Interpreter_Class.cpp.
References Interpreter_Class::_commonwords, _countof, Helpers::formatstring(), Interpreter_Class::PERIOD, and Interpreter_Class::QUESTION.
Referenced by Interpreter_Class::Interpret().
std::string Interpret | ( | IntList | tokens | ) |
Given an array of integer tokens, convert the tokens into a single std::string of space-delimited words, following simple rules of formatting.
tokens | The list of integers to interpret. |
Definition at line 93 of file Interpreter_Class.cpp.
References Interpreter_Class::_InterpretToken(), and Helpers::titlecase().
Referenced by DesignPatternExamples_cpp::Interpreter_Exercise().
|
staticprivate |
The 40 most common words in English (in order but that doesn't really matter here). A token is nothing more than an index into this list.
Definition at line 49 of file Interpreter_Class.h.
Referenced by Interpreter_Class::_InterpretToken().
const int PERIOD = 100 |
Definition at line 41 of file Interpreter_Class.h.
Referenced by Interpreter_Class::_InterpretToken().
const int QUESTION = 101 |
Definition at line 42 of file Interpreter_Class.h.
Referenced by Interpreter_Class::_InterpretToken().