Implementation of the Interpreter_Interpret() function used in the Interpreter Pattern. More...
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include "helpers/titlecase.h"
#include "Interpreter_Interpreter.h"
Go to the source code of this file.
Functions | |
static const char * | _InterpretToken (int token) |
Helper function to convert the token into its corresponding word or punctuation mark. | |
bool | Interpreter_Interpret (const int *tokenList, DynamicString *output) |
This function is a simple interpreter. | |
Variables | |
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. | |
Implementation of the Interpreter_Interpret() function used in the Interpreter Pattern.
Definition in file Interpreter_Interpreter.c.
|
static |
Helper function to convert the token into its corresponding word or punctuation mark.
token | The token to interpret. |
Definition at line 72 of file Interpreter_Interpreter.c.
References _commonwords, PERIOD, and QUESTION.
Referenced by Interpreter_Interpret().
bool Interpreter_Interpret | ( | const int * | tokenList, |
DynamicString * | output | ||
) |
This function is a simple interpreter.
The 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:
tokenList | List of integer tokens to be interpreted. The list is assumed to be terminated by -1 (EOL). |
output | A DynamicString object returning the sentence created through interpreting the tokens. Call DynamicString_Clear() when done with the string. |
Definition at line 117 of file Interpreter_Interpreter.c.
References _InterpretToken(), DynamicString_Append(), EOL, and titlecase().
Referenced by Interpreter_Exercise().
|
static |
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 20 of file Interpreter_Interpreter.c.
Referenced by _InterpretToken().