private object Apply(ParseTreeNode x) { object result = null; object o = Evaluate(x[0]); if (o is MethodInfo) { MethodInfo meth = (MethodInfo)o; object[] paras = new object[x.Arity - 1]; for (int i = 1; i < x.Arity; i++) { paras[i - 1] = x[i]; } try { result = meth.Invoke(this, paras); } catch (TargetInvocationException ex1) { MethodTracer.LogWarning(ex1.Message); MethodTracer.LogWarning(ex1.InnerException.Message); MethodTracer.LogWarning(ex1.InnerException.StackTrace); } } return(result); }
void BuildComprehension() { MethodTracer.Enter(); while (true) { MethodTracer.LogMessage("{0}", parser.Token); if (parser.Token.type != TokenType.Identifier) { MethodTracer.LogWarning("First part in comprehension must be an identifier."); break; } Name = "LISTCOMPREHENSION"; this[1] = new Operator() { Name = parser.Token.value }; parser.Advance(); parser.Advance(TokenType.Symbol, ":"); this[2] = parser.Expression(0); } MethodTracer.Exit(); }
public void Advance() { if (EndOfStreamReached) { _token = null; _op = new Operator() { Name = "", lbp = 0, parser = this }; } else { _token = _tokens.ReadToken(); if (_token.type == TokenType.DoubleQuotedString) { _op = new Operator() { Name = "STRING" }; _op[0] = new Operator() { Name = _token.value }; } else if (_token.type == TokenType.Number) { _op = new Operator() { Name = "NUMBER" }; _op[0] = new Operator() { Name = _token.value }; } else if (_token.type == TokenType.Identifier || _token.type == TokenType.Symbol) { if (_top.ContainsKey(_token)) { _op = _top[_token].Copy(); _op.parser = this; } else { int lbp = 1; if (_token.type == TokenType.Symbol) { lbp = 0; } _op = new Operator() { Name = _token.value, lbp = lbp, parser = this }; } } else { MethodTracer.LogWarning("Unhandled Token:{0}", _token); } } }