10#include "helpers/formatstring.h"
26 std::ostringstream output;
29 for (
size_t index = 0; index < tokens.size(); ++index)
32 if (index + 1 < tokens.size())
49 { 39, 18, 17, 27, 2, 7, 101 },
50 { 32, 17, 1, 0, 34, 2, 1, 37, 101 },
51 { 36, 17, 8, 5, 32, 2, 18, 7, 101 },
52 { 11, 12, 17, 9, 36, 12, 1, 6, 20, 100 },
53 { 26, 27, 7, 21, 36, 17, 27, 10, 101 },
54 { 23, 28, 32, 26, 32, 18, 10, 100 }
83 std::cout << std::endl;
84 std::cout <<
"Interpreter Exercise" << std::endl;
94 std::string sentence = interpreter.
Interpret(tokenList);
104 std::cout <<
" Done." << std::endl;
Declaration of the Interpreter_Class class used in the Interpreter Pattern.
static int * _sentenceTokenLists[]
A list of pre-defined token lists. Each token list represents a single sentence constructed from the ...
static const char * _TokensToString(int *tokens)
Helper function to convert a list of ints to a string representation.
Representation of a simple interpreter.
std::string Interpret(IntList tokens)
Given an array of integer tokens, convert the tokens into a single std::string of space-delimited wor...
Declaration of the Interpreter_Exercise() function as used in the Interpreter Pattern.
The namespace containing all Design Pattern Examples implemented in C++.
void Interpreter_Exercise()
Example of using the Interpreter design pattern.
std::vector< int > IntList
Alias to make it easier to work with a vector of vectors of int.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....