-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInterpreter.py
More file actions
43 lines (36 loc) · 1.14 KB
/
Interpreter.py
File metadata and controls
43 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Time : 2022/08/27 14:32:38
# @Author : Gary
# @Email : None
class PlayContext():
# 环境类
play_text = None
class Expression():
# 抽象表达式类
def interpret(self, context):
if len(context.play_text) == 0:
return
else:
play_segs = context.play_text.split(" ")
for play_seg in play_segs:
pos = 0
for ele in play_seg:
if ele.isalpha():
pos += 1
continue
break
play_chord = play_seg[0:pos]
play_value = play_seg[pos:]
self.execute(play_chord, play_value)
def execute(self, play_key, play_value):
pass
class NormGuitar(Expression):
# 具体表达式类
def execute(self, key, value):
print("Normal Guitar Playing--Chord:%s Play Tune:%s" % (key, value))
if __name__ == "__main__":
context = PlayContext()
context.play_text = "C53231323 Em43231323 F43231323 G63231323"
guitar = NormGuitar()
guitar.interpret(context)