public override string EvalFor(MoccaFor codeBase) { string ret = "for " + GenerateLoopCounter() + " in " + codeBase.iter + ":\n"; globalIndent++; foreach (MoccaSuite i in codeBase.cmd_list) { ret += Indentation() + EvalSuite(i); } globalIndent--; ret = ret.Replace("__iterator", GenerateLoopCounter()); return(ret + "\n"); }
public abstract string EvalFor(MoccaFor 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); } }