public override string EvalEvent(MoccaEvent codeBase) { switch (codeBase.type) { case MoccaEventType.onProgramStart: return("# 프로그램이 시작될 때 호출됩니다.\n"); case MoccaEventType.onKeyPressed: return("# " + codeBase.option + " 키가 눌렸을 때 호출됩니다.\n"); case MoccaEventType.onFunctionCall: return("# " + codeBase.option + " 함수입니다.\n"); case MoccaEventType.onSignalCall: return("# " + codeBase.option + " 신호가 사용되면 호출됩니다.\n"); default: throw new FormatException(); } }
public abstract string EvalEvent(MoccaEvent codeBase);
/* * IDENTIFIER Params SEMICOLON * or * IDENTIFIER Params Block * * SEMICOLON after Block will be allowed * returns MoccaSuite::Something */ public virtual object EvalStatement(ParseTree tree, params object[] paramlist) { string identifier = (string)this.GetValue(tree, TokenType.IDENTIFIER, 0); List <object> param = (List <object>) this.GetValue(tree, TokenType.Params, 0); List <MoccaSuite> block = null; if (this.GetValue(tree, TokenType.Block, 0) != null) { block = (List <MoccaSuite>) this.GetValue(tree, TokenType.Block, 0); } switch (identifier) { case "if": MoccaLogic a = new MoccaLogic(); a.keyword = "if"; if (param[0].ToString().Equals("true")) { a.expression = new MoccaExpression("True"); } else if (param[0].ToString().Equals("false")) { a.expression = new MoccaExpression("False"); } else { a.expression = (MoccaExpression)param[0]; } a.cmd_list = block; return(a); case "elif": MoccaLogic b = new MoccaLogic(); b.keyword = "elif"; if (param[0].ToString().Equals("true")) { b.expression = new MoccaExpression("True"); } else if (param[0].ToString().Equals("false")) { b.expression = new MoccaExpression("False"); } else { b.expression = (MoccaExpression)param[0]; } b.cmd_list = block; return(b); case "else": MoccaLogic c = new MoccaLogic(); c.keyword = "else"; c.cmd_list = block; return(c); case "while": MoccaWhile d = new MoccaWhile(); if (param[0].ToString().Equals("true")) { d.expression = new MoccaExpression("True"); } else if (param[0].ToString().Equals("false")) { d.expression = new MoccaExpression("False"); } else { d.expression = (MoccaExpression)param[0]; } d.cmd_list = block; return(d); case "for": MoccaFor e = new MoccaFor(); e.iter = param[0]; e.cmd_list = block; return(e); case "event": if (param.Count == 1) { return(new MoccaEvent(MoccaEvent.recognizeType(param[0].ToString()), null)); } else { return(new MoccaEvent(MoccaEvent.recognizeType(param[0].ToString()), param[1].ToString())); } default: MoccaCommand f = new MoccaCommand(identifier, param); return(f); } }