7using System.Collections.Generic;
10using System.Threading.Tasks;
41 StringBuilder output =
new StringBuilder();
44 for (
int index = 0; index < tokens.Length; ++index)
46 output.AppendFormat(
"{0,3}", tokens[index]);
47 if (index + 1 < tokens.Length)
53 return output.ToString();
64 new int[] { 39, 18, 17, 27, 2, 7, 101 },
65 new int[] { 32, 17, 1, 0, 34, 2, 1, 37, 101 },
66 new int[] { 36, 17, 8, 5, 32, 2, 18, 7, 101 },
67 new int[] { 11, 12, 17, 9, 36, 12, 1, 6, 20, 100 },
68 new int[] { 26, 27, 7, 21, 36, 17, 27, 10, 101 },
69 new int[] { 23, 28, 32, 26, 32, 18, 10, 100 }
79 Console.WriteLine(
"Interpreter Exercise");
89 string sentence = interpreter.
Interpret(tokenList);
94 Console.WriteLine(
" {0,-50} ==> \"{1}\"", tokensAsString, sentence);
96 Console.WriteLine(
" Done.");
Representation of a simple interpreter.
string Interpret(int[] tokens)
Given an array of integer tokens, convert the tokens into a single string of space-delimited words,...
Example of using the Interpreter Pattern in C#.
string _TokensToString(int[] tokens)
Helper method to convert a list of ints to a string representation.
static int[][] _sentenceTokenLists
A list of pre-defined token lists. Each token list represents a single sentence constructed from the ...
void Run()
Executes the example for the Interpreter Pattern in C#.
The namespace containing all Design Pattern Examples implemented in C#.