public INode Match(Lookahead2Enumerator <Token> it, IGrammarParser parser) { Token token = it.PeekNext(); if (token == null) { return(null); } if (!token.IsFunction()) { return(null); } string source = token.GetSource(); IPostfixMathCommand pfmc = ((FunctionToken)token).GetPfmc(); if (!this.open.Equals(it.PeekNextnext())) { return(null); } it.Consume(); it.Consume(); if (this.close.Equals(it.PeekNext())) { if (!pfmc.CheckNumberOfParameters(0)) { throw new Colosoft.Text.Jep.ParseException("Function " + pfmc + " invalid number of arguments 0"); } it.Consume(); return(this.nf.BuildFunctionNode(source, pfmc, new INode[0])); } List <INode> list = new List <INode>(); while (true) { INode item = parser.ParseSubExpression(); list.Add(item); if (this.close.Equals(it.PeekNext())) { it.Consume(); if (!pfmc.CheckNumberOfParameters(list.Count)) { throw new Colosoft.Text.Jep.ParseException(string.Concat(new object[] { "Function ", pfmc, " invalid number of arguments ", list.Count })); } return(this.nf.BuildFunctionNode(source, pfmc, list.ToArray())); } if (!this.comma.Equals(it.PeekNext())) { break; } it.Consume(); } throw new Colosoft.Text.Jep.ParseException("Closing bracket not found. Next token is " + it.PeekNext()); }
public ASTFunNode BuildFunctionNode(string name, IPostfixMathCommand pfmc, INode[] arguments) { if (!pfmc.CheckNumberOfParameters(arguments.Length)) { throw new Colosoft.Text.Jep.ParseException(string.Concat(new object[] { "Incorrect number of parameters ", arguments.Length, " for ", name, " " })); } ASTFunNode node = new ASTFunNode(JJTFUNNODE); node.SetFunction(name, pfmc); this.CopyChildren(node, arguments); return(node); }