-
-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathclient.py
More file actions
20 lines (15 loc) · 578 Bytes
/
client.py
File metadata and controls
20 lines (15 loc) · 578 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"The Interpreter Pattern Use Case Example"
from sentence_parser import Parser
# The sentence complies with a simple grammar of
# Number -> Operator -> Number -> etc,
SENTENCE = "5 + IV - 3 + VII - 2"
# SENTENCE = "V + IV - III + 7 - II"
# SENTENCE= "CIX + V"
# SENTENCE = "CIX + V - 3 + VII - 2"
# SENTENCE = "MMMCMXCIX - CXIX + MCXXII - MMMCDXII - XVIII - CCXXXV"
print(SENTENCE)
AST_ROOT = Parser.parse(SENTENCE)
# Interpret recursively through the full AST starting from the root.
print(AST_ROOT.interpret())
# Print out a representation of the AST_ROOT
print(AST_ROOT)