/// <summary> /// Reduces this node to a simpler expression with additional symbol tables. /// </summary> /// <param name="symbols">The additional symbol table for reducing.</param> /// <param name="expectedType">The type which is expected as the type of reduced expression.</param> /// <returns>The reduced expression.</returns> protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType) { if (symbols.ResolveMatch(DispatchTypes.Member, this.Name) != null || symbols.Missing != DispatchExpression.DefaultMissing ) { return Variable(symbols, this.Name) .ReduceOnce(symbols, expectedType) .Let(e => (e as MacroExpression).Null(m => m.Evaluate(symbols)) ?? e); } else { throw new ParseException("Identifier evaluation failed: " + this, this); } }
/// <summary> /// Reduces this node to a simpler expression with additional symbol tables. /// </summary> /// <param name="symbols">The additional symbol table for reducing.</param> /// <param name="expectedType">The type which is expected as the type of reduced expression.</param> /// <returns>The reduced expression.</returns> protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType) { Expression value = null; if (this.Elements.IsEmpty()) { return Empty(); } if (!(this[0] is IdentifierExpression) || symbols.ResolveMatch(DispatchTypes.Member, this[0].Id()) != null ) { value = this[0].TryReduce(symbols); if (value is MacroExpression) { return ((MacroExpression) value).Evaluate(symbols, this.Elements.Skip(1)); } if (value != null && value.Type(symbols).GetDelegateSignature() != null) { return Invoke(value, this.Elements.Skip(1).ReduceAll(symbols)); } if (value is TypeCandidateExpression) { return Dispatch( symbols, DispatchTypes.Constructor, value, null, this.Elements.Skip(1) ); } } if (this[0] is IdentifierExpression && symbols.ResolveMatch(DispatchTypes.Method, this[0].Id()) != null || symbols.Missing != DispatchExpression.DefaultMissing ) { return Function( symbols, this[0].Id(), this.Elements.Skip(1) ); } if (value != null && this.Length == 1) { return value; } throw new ParseException("List evaluation failed: " + this, this); }
// this._left and Candidate.Arguments is already reduced with symbols. /// <summary> /// Reduces this node to a simpler expression with additional symbol tables. /// </summary> /// <param name="symbols">The additional symbol table for reducing.</param> /// <param name="expectedType">The type which is expected as the type of reduced expression.</param> /// <returns>The reduced expression.</returns> protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType) { this._left = this.Left.Reduce(symbols); return symbols.ResolveMatch(this) .If(d => d == null, d => symbols.Missing) (this, symbols, expectedType); }