static void Main(string[] args) { PlayContext context = new PlayContext(); Console.WriteLine("上海滩: "); context.PlayText = "O 2 E 0.5 A 3 E 0.5 G 0.5 D 3 E 0.5 G 0.5 A 0.5 O 3 C 1 O 1 A 0.5 G 1 C 0.5 E 0.5 D 3"; try { while (context.PlayText.Length > 0) { string str = context.PlayText.Substring(0, 1); Expression expression = ExpressionFactory.CreateExpression(str); //switch (str) //{ // case "O": // expression = new Sacle(); // break; // case "C": // case "D": // case "E": // case "F": // case "G": // case "A": // case "B": // expression = new Note(); // break; //} expression.Interpret(context); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } Console.Read(); }
public int Interpret(Dictionary <String, Expression> variables) { return(leftOperand.Interpret(variables) + rightOperand.Interpret(variables)); }
public int Interpret(Dictionary <string, Expression> context) { return(syntaxTree.Interpret(context)); }