9from .interpreter_class
import Interpreter_Class
14_sentenceTokenLists = [
15 [ 39, 18, 17, 27, 2, 7, 101 ],
16 [ 32, 17, 1, 0, 34, 2, 1, 37, 101 ],
17 [ 36, 17, 8, 5, 32, 2, 18, 7, 101 ],
18 [ 11, 12, 17, 9, 36, 12, 1, 6, 20, 100 ],
19 [ 26, 27, 7, 21, 36, 17, 27, 10, 101 ],
20 [ 23, 28, 32, 26, 32, 18, 10, 100 ]
33 for index
in range(0, len(tokens)):
34 output.write(
"{0:3}".format(tokens[index]))
35 if index + 1 < len(tokens):
38 return output.getvalue()
60 print(
"Interpreter Exercise")
64 for sentenceIndex
in range(0, len(_sentenceTokenLists)):
65 tokenList = _sentenceTokenLists[sentenceIndex]
69 sentence = interpreter.Interpret(tokenList)
74 print(
" {0:<50} ==> \"{1}\"".format(tokensAsString, sentence))
Representation of a simple interpreter.
def Interpreter_Exercise()
Example of using the Interpreter Pattern.
str _TokensToString(list[int] tokens)
Helper method to convert a list of tokens to a string representation.