//解释器 public void Interpreter(PlayContext context) { if (context.PlayText.Length == 0) { return; } string playKey = context.PlayText.Substring(0, 1); context.PlayText = context.PlayText.Substring(2); double playValue = double.Parse(context.PlayText.Substring(0, context.PlayText.IndexOf(" "))); Excute(playKey, playValue); }
void Start() { PlayContext context = new PlayContext(); context.PlayText = "O 2 E 0.5 G 0.5 A 3 E 0.5"; Expression expression = null; while (context.PlayText.Length > 0) { string str = context.PlayText.Substring(0, 1); switch (str) { case "O": expression = new Scale(); break; } expression.Interpreter(context); } }