All files / NCalc/Domain EvaluationVisitor.ts

85.76% Statements 241/281
70.07% Branches 89/127
94.73% Functions 18/19
85.66% Lines 239/279

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713                  2x 1x           124x       73x       124x 124x           50x 50x       486x       1x 1x   148x 147x   16x 16x   224x 224x   40x 39x   57x 57x               1x 1x   1x     1x       2x                                       51x       51x       51x       51x 47x 31x 16x 6x   10x   4x             7x   7x         148x 148x 178x 148x 148x   178x       148x 148x 142x 142x 142x   142x       148x   31x 31x     5x 5x     7x       7x       5x 5x       2x 2x       4x 4x       3x 3x       4x 4x     2x 2x     3x 3x       27x 27x     23x 3x   20x     22x     17x 17x     1x 1x     1x 1x     1x 1x     1x 1x     1x 1x     10x 10x           16x   16x   4x 4x     9x 9x     1x 1x       2x         224x       40x 40x         40x 67x 67x 67x     67x       40x           40x 7x 7x     33x     4x   3x     3x   3x           1x   1x     1x   1x           1x   1x     1x   1x           1x   1x     1x   1x                                           1x   1x     1x   1x             1x   1x     1x   1x           1x   1x     1x   1x           2x   2x     2x   2x                                       1x   1x     1x   1x           1x   1x     1x       1x           1x   1x     1x   1x           3x   3x     3x         3x             1x   1x         1x       1x           1x   1x     1x   1x           1x   1x     1x   1x           1x   1x     1x   1x           1x   1x     1x   1x           1x   1x     1x   1x           1x   1x     1x 1x   1x 1x           1x   1x     1x 1x   1x 1x           5x   5x     5x 5x   5x     5x           2x   2x     2x 2x     2x 6x 6x 2x 2x       2x 2x                   33x 1x 1x           32x 1x       124x   124x 124x     40x   7x         5x 5x         57x   52x   2x     2x 4x     2x 2x   2x   50x       5x     5x   5x     5x      
import { ArgumentException, BinaryExpression, BinaryExpressionType, Identifier, LogicalExpressionVisitor, NCalcFunction, TernaryExpression, UnaryExpression, UnaryExpressionType } from '@/NCalc/Domain';
import { EvaluateOptions } from '@/NCalc/EvaluationOptions';
import { Numbers, TypeCode } from '@/NCalc/Numbers';
import { Expression } from '@/NCalc/Expression';
import { FunctionArgs } from '@/NCalc//FunctionArgs';
import { ParameterArgs } from '@/NCalc//ParameterArgs';
import { EvaluateFunctionHandler, EvaluateParameterHandler } from '@/NCalc//types';
import { ValueExpression } from '@/NCalc/Domain/ValueExpression';
 
const equalsIgnoringCase = (text, other) => {
    return text.localeCompare(other, undefined, {sensitivity: 'base'}) === 0;
};
 
export class EvaluationVisitor extends LogicalExpressionVisitor {
    // private delegate T Func<T>();
 
    private readonly _options: EvaluateOptions = EvaluateOptions.None;
    // private readonly CultureInfo _cultureInfo;
 
    private get IgnoreCase() {
        return this._options & EvaluateOptions.IgnoreCase;
    }
 
    public constructor(options: EvaluateOptions) {
        super();
        this._options = options;
    }
 
    public Result: any;
 
    private Evaluate(expression: any): any {
        expression.Accept(this);
        return this.Result;
    }
 
    public Visit(expression: any): void {
        switch (expression.constructor.name) {
        case 'LogicalExpression':
            throw new Error();
        case 'TernaryExpression':
            this.VisitTernary(expression);
            break;
        case 'BinaryExpression':
            this.VisitBinaryExpression(expression);
            break;
        case 'UnaryExpression':
            this.VisitUnaryExpression(expression);
            break;
        case 'ValueExpression':
            this.VisitValueExpression(expression);
            break;
        case 'NCalcFunction':
            this.VisitNCalcFunction(expression);
            break;
        case 'Identifier':
            this.VisitIdentifier(expression);
            break;
        default:
            throw new Error(`Invalid expression type: ${expression.constructor.name}`);
        }
    }
 
    public VisitTernary(expression: TernaryExpression) {
    // Evaluates the left expression and saves the value
        expression.LeftExpression.Accept(this);
        const left = this.Result == true;
 
        Iif (left) {
            expression.MiddleExpression.Accept(this);
        } else {
            expression.RightExpression.Accept(this);
        }
    }
 
    private static CommonTypes: string[] = ['number', 'boolean', 'string', 'bigint'];
 
    /// <summary>
    /// Gets the the most precise type.
    /// </summary>
    /// <param name="a">Type a.</param>
    /// <param name="b">Type b.</param>
    /// <returns></returns>
    private static GetMostPreciseType(a: string, b: string): string {
        for (const t in this.CommonTypes) {
            Iif (typeof a == t || typeof b == t) {
                return t;
            }
        }
 
        return a;
    }
 
    // @todo Revisit this function for equality
    public CompareUsingMostPreciseType(a: any, b: any): number {
        Iif (a == null && b == null) {
            return 0;
        }
 
        Iif (a == null) {
            return -1;
        }
 
        Iif (b == null) {
            return 1;
        }
 
        if (typeof a == 'number' || typeof b == 'number') {
            if (a < b) {
                return -1;
            } else if (a > b) {
                return 1;
            }
            return 0;
        } else {
            return a == b ? 0 : 1;
        }
 
    // return Comparer.Default.Compare(Convert.ChangeType(a, mpt), Convert.ChangeType(b, mpt));
    }
 
    private static IsReal(value: object): boolean {
        const typeCode = typeof value;
 
        return typeCode == TypeCode.Decimal;
    }
 
    public VisitBinaryExpression(expression: BinaryExpression): void {
    // simulate Lazy<Func<>> behavior for late evaluation
        let leftValue = null;
        const left = (): any => {
            if (leftValue == null) {
                expression.LeftExpression.Accept(this);
                leftValue = this.Result;
            }
            return leftValue;
        };
 
        // simulate Lazy<Func<>> behavior for late evaluations
        let rightValue = null;
        const right = (): any => {
            if (rightValue == null) {
                expression.RightExpression.Accept(this);
                rightValue = this.Result;
            }
            return rightValue;
        };
 
        // @todo re-evaluate this implementation
        switch (expression.Type) {
        case BinaryExpressionType.And:
            this.Result = left() == true && right() == true;
            break;
 
        case BinaryExpressionType.Or:
            this.Result = left() == true || right() == true;
            break;
 
        case BinaryExpressionType.Div:
            this.Result =
          EvaluationVisitor.IsReal(left()) || EvaluationVisitor.IsReal(right())
              ? Numbers.Divide(left(), right())
              : Numbers.Divide(parseFloat(left()) as unknown as any, right());
            break;
 
        case BinaryExpressionType.Equal:
        // Use the type of the left operand to make the comparison
            this.Result = this.CompareUsingMostPreciseType(left(), right()) == 0;
            break;
 
        case BinaryExpressionType.Greater:
        // Use the type of the left operand to make the comparison
            this.Result = this.CompareUsingMostPreciseType(left(), right()) > 0;
            break;
 
        case BinaryExpressionType.GreaterOrEqual:
        // Use the type of the left operand to make the comparison
            this.Result = this.CompareUsingMostPreciseType(left(), right()) >= 0;
            break;
 
        case BinaryExpressionType.Lesser:
        // Use the type of the left operand to make the comparison
            this.Result = this.CompareUsingMostPreciseType(left(), right()) < 0;
            break;
 
        case BinaryExpressionType.LesserOrEqual:
        // Use the type of the left operand to make the comparison
            this.Result = this.CompareUsingMostPreciseType(left(), right()) <= 0;
            break;
 
        case BinaryExpressionType.Minus:
            this.Result = Numbers.Subtract(left(), right());
            break;
 
        case BinaryExpressionType.Modulo:
            this.Result = Numbers.Modulo(left(), right());
            break;
 
        case BinaryExpressionType.NotEqual:
        // Use the type of the left operand to make the comparison
            this.Result = this.CompareUsingMostPreciseType(left(), right()) != 0;
            break;
 
        case BinaryExpressionType.Plus:
            if (typeof left() == 'string') {
                this.Result = left().concat(right());
            } else {
                this.Result = Numbers.Add(left(), right());
            }
 
            break;
 
        case BinaryExpressionType.Times:
            this.Result = Numbers.Multiply(left(), right());
            break;
 
        case BinaryExpressionType.BitwiseAnd:
            this.Result = parseInt(left()) & parseInt(right());
            break;
 
        case BinaryExpressionType.BitwiseOr:
            this.Result = parseInt(left()) | parseInt(right());
            break;
 
        case BinaryExpressionType.BitwiseXOr:
            this.Result = parseInt(left()) ^ parseInt(right());
            break;
 
        case BinaryExpressionType.LeftShift:
            this.Result = parseInt(left()) << parseInt(right());
            break;
 
        case BinaryExpressionType.RightShift:
            this.Result = parseInt(left()) >> parseInt(right());
            break;
 
        case BinaryExpressionType.Exponentiation:
            this.Result = Math.pow(parseFloat(left()), parseFloat(right()));
            break;
        }
    }
 
    public VisitUnaryExpression(expression: UnaryExpression): void {
    // Recursively evaluates the underlying expression
        expression.Expression.Accept(this);
 
        switch (expression.Type) {
        case UnaryExpressionType.Not:
            this.Result = !(this.Result == true);
            break;
 
        case UnaryExpressionType.Negate:
            this.Result = Numbers.Subtract(0 as unknown as object, this.Result);
            break;
 
        case UnaryExpressionType.BitwiseNot:
            this.Result = ~parseInt(this.Result);
            break;
 
        case UnaryExpressionType.Positive:
        // No-op
            break;
        }
    }
 
    public VisitValueExpression(expression: ValueExpression): void {
        this.Result = expression.Value;
    }
 
    public VisitNCalcFunction(func: NCalcFunction): void {
        const args = new FunctionArgs();
        args.Parameters = [];
 
        // Don't call parameters right now, instead let the func do it as needed.
        // Some parameters shouldn't be called, for instance, in a if(), the "not" value might be a division by zero
        // Evaluating every value could produce unexpected behaviour
        for (let i = 0; i < func.Expressions.length; i++) {
            args.Parameters[i] = new Expression(func.Expressions[i], this._options);
            args.Parameters[i].EvaluateFunction = this.EvaluateFunction;
            args.Parameters[i].EvaluateParameter = this.EvaluateParameter;
 
            // Assign the parameters of the Expression to the arguments so that custom funcs and Parameters can use them
            args.Parameters[i].Parameters = this.Parameters;
        }
 
        // Calls external implementation
        this.OnEvaluateFunction(
            this.IgnoreCase ? func.Identifier.Name.toLowerCase() : func.Identifier.Name,
            args
        );
 
        // // If an external implementation was found get the result back
        if (args.HasResult) {
            this.Result = args.Result;
            return;
        }
 
        switch (func.Identifier.Name.toLowerCase()) {
        // Start Abs
        case 'abs':{
            this.CheckCase('Abs', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Abs() takes exactly 1 argument');
 
            this.Result = Math.abs(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Acos
        case 'acos':{
            this.CheckCase('Acos', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Acos() takes exactly 1 argument');
 
            this.Result = Math.acos(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Asin
        case 'asin':{
            this.CheckCase('Asin', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Asin() takes exactly 1 argument');
 
            this.Result = Math.asin(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Atan
        case 'atan':{
            this.CheckCase('Atan', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Atan() takes exactly 1 argument');
 
            this.Result = Math.atan(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Atan2
        case 'atan2':{
            this.CheckCase('Atan2', func.Identifier.Name);
 
            Iif (func.Expressions.length != 2)
                throw new ArgumentException('Atan2() takes exactly 2 argument');
 
            this.Result = Math.atan2(
                parseFloat(this.Evaluate(func.Expressions[0])),
                parseFloat(this.Evaluate(func.Expressions[1]))
            );
 
            break;
        }
        // end
 
        // Start Ceiling
        case 'ceiling':{
            this.CheckCase('Ceiling', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Ceiling() takes exactly 1 argument');
 
            this.Result = Math.ceil(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Cos
 
        case 'cos':{
            this.CheckCase('Cos', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Cos() takes exactly 1 argument');
 
            this.Result = Math.cos(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Exp
        case 'exp':{
            this.CheckCase('Exp', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Exp() takes exactly 1 argument');
 
            this.Result = Math.exp(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Floor
        case 'floor':{
            this.CheckCase('Floor', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Floor() takes exactly 1 argument');
 
            this.Result = Math.floor(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // // Start IEEERemainder
        // case "ieeeremainder":
 
        //     this.CheckCase("IEEERemainder", func.Identifier.Name);
 
        //     if (func.Expressions.length != 2)
        //         throw new ArgumentException("IEEERemainder() takes exactly 2 arguments");
 
        //     Result = Math.IEEERemainder(parseFloat(this.Evaluate(func.Expressions[0])), parseFloat(this.Evaluate(func.Expressions[1])));
 
        //     break;
 
        // // end
 
        // Start Ln
        case 'ln':{
            this.CheckCase('Ln', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Ln() takes exactly 1 argument');
 
            this.Result = Math.log(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Log
        case 'log':{
            this.CheckCase('Log', func.Identifier.Name);
 
            Iif (func.Expressions.length != 2)
                throw new ArgumentException('Log() takes exactly 2 arguments');
 
            this.Result =
          Math.log(parseFloat(this.Evaluate(func.Expressions[0]))) /
          Math.log(parseFloat(this.Evaluate(func.Expressions[1])));
 
            break;
        }
        // end
 
        // Start Log10
        case 'log10':{
            this.CheckCase('Log10', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Log10() takes exactly 1 argument');
 
            this.Result = Math.log10(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Pow
        case 'pow':{
            this.CheckCase('Pow', func.Identifier.Name);
 
            Iif (func.Expressions.length != 2)
                throw new ArgumentException('Pow() takes exactly 2 arguments');
 
            this.Result = Math.pow(
                parseFloat(this.Evaluate(func.Expressions[0])),
                parseFloat(this.Evaluate(func.Expressions[1]))
            );
 
            break;
        }
        // end
 
        // Start Round
        // @todo Implementation is incorrect!
        case 'round':{
            this.CheckCase('Round', func.Identifier.Name);
 
            Iif (func.Expressions.length != 2)
                throw new ArgumentException('Round() takes exactly 2 arguments');
 
            // const rounding = (this._options & EvaluateOptions.RoundAwayFromZero) == EvaluateOptions.RoundAwayFromZero ? MidpointRounding.AwayFromZero : MidpointRounding.ToEven;
 
            this.Result = Math.round(parseFloat(this.Evaluate(func.Expressions[0]))).toFixed(
                this.Evaluate(func.Expressions[1])
            );
 
            break;
        }
        // end
 
        // Start Sign
        case 'sign':{
            this.CheckCase('Sign', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Sign() takes exactly 1 argument');
 
            this.Result = Math.sign(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Sin
        case 'sin':{
            this.CheckCase('Sin', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Sin() takes exactly 1 argument');
 
            this.Result = Math.sin(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Sqrt
        case 'sqrt':{
            this.CheckCase('Sqrt', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Sqrt() takes exactly 1 argument');
 
            this.Result = Math.sqrt(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Tan
        case 'tan':{
            this.CheckCase('Tan', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Tan() takes exactly 1 argument');
 
            this.Result = Math.tan(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Truncate
        case 'truncate':{
            this.CheckCase('Truncate', func.Identifier.Name);
 
            Iif (func.Expressions.length != 1)
                throw new ArgumentException('Truncate() takes exactly 1 argument');
 
            this.Result = Math.trunc(parseFloat(this.Evaluate(func.Expressions[0])));
 
            break;
        }
        // end
 
        // Start Max
        case 'max':{
            this.CheckCase('Max', func.Identifier.Name);
 
            Iif (func.Expressions.length != 2)
                throw new ArgumentException('Max() takes exactly 2 arguments');
 
            const maxleft = this.Evaluate(func.Expressions[0]);
            const maxright = this.Evaluate(func.Expressions[1]);
 
            this.Result = Numbers.Max(maxleft, maxright);
            break;
        }
        // end
 
        // Start Min
        case 'min':{
            this.CheckCase('Min', func.Identifier.Name);
 
            Iif (func.Expressions.length != 2)
                throw new ArgumentException('Min() takes exactly 2 arguments');
 
            const minleft = this.Evaluate(func.Expressions[0]);
            const minright = this.Evaluate(func.Expressions[1]);
 
            this.Result = Numbers.Min(minleft, minright);
            break;
        }
        // end
 
        // Start if
        case 'if': {
            this.CheckCase('if', func.Identifier.Name);
 
            Iif (func.Expressions.length != 3)
                throw new ArgumentException('if() takes exactly 3 arguments');
 
            const val = this.Evaluate(func.Expressions[0]);
            const cond = val == true ? true : false;
 
            this.Result = cond
                ? this.Evaluate(func.Expressions[1])
                : this.Evaluate(func.Expressions[2]);
            break;
        }
        // end
 
        // Start in
        case 'in': {
            this.CheckCase('in', func.Identifier.Name);
 
            Iif (func.Expressions.length < 2)
                throw new ArgumentException('in() takes at least 2 arguments');
 
            const parameter = this.Evaluate(func.Expressions[0]);
            let evaluation = false;
 
            // Goes through any values, and stop whe one is found
            for (let i = 1; i < func.Expressions.length; i++) {
                const argument = this.Evaluate(func.Expressions[i]);
                if (this.CompareUsingMostPreciseType(parameter, argument) == 0) {
                    evaluation = true;
                    break;
                }
            }
 
            this.Result = evaluation;
            break;
        }
        // end
 
        default:
            throw new ArgumentException(`Function ${func.Identifier.Name} was not found.`);
        }
    }
 
    private CheckCase(func: string, called: string): void {
        if (this.IgnoreCase) {
            if (equalsIgnoringCase(func, called)) {
                return;
            }
 
            throw new ArgumentException(`Function '${called}' not found`);
        }
 
        if (func != called) {
            throw new Error(`Function not found ${called}. Try ${func} instead.`);
        }
    }
 
    public Parameters: {[key: string]: any} = {};
 
    public EvaluateFunction: {[key: string]: EvaluateFunctionHandler} = {};
    public EvaluateParameter: {[key: string]: EvaluateParameterHandler} = {};
 
    private OnEvaluateFunction(name: string, args: FunctionArgs): void {
        if (Object.prototype.hasOwnProperty.call(this.EvaluateFunction, name)) {
            // @todo
            this.EvaluateFunction[name](args);
        }
    }
 
    private OnEvaluateParameter(name: string, args: ParameterArgs): void {
        if (Object.prototype.hasOwnProperty.call(this.EvaluateParameter, name)) {
            this.EvaluateParameter[name](args);
        }
    }
 
    public VisitIdentifier(parameter: Identifier): void {
        if (Object.prototype.hasOwnProperty.call(this.Parameters, parameter.Name)) {
            // The parameter is defined in the hashtable
            if (this.Parameters[parameter.Name].constructor.name == 'Expression') {
                // The parameter is itself another Expression
                const expression = this.Parameters[parameter.Name];
 
                // Overloads parameters
                for (const p in this.Parameters) {
                    expression.Parameters[p] = this.Parameters[p];
                }
 
                expression.EvaluateFunction = this.EvaluateFunction;
                expression.EvaluateParameter = this.EvaluateParameter;
 
                this.Result = this.Parameters[parameter.Name].Evaluate();
            } else {
                this.Result = this.Parameters[parameter.Name];
            }
        } else {
            // The parameter should be defined in a call back method
            const args = new ParameterArgs();
 
            // Calls external implementation
            this.OnEvaluateParameter(parameter.Name, args);
 
            Iif (!args.HasResult)
                throw new ArgumentException(`Parameter '${parameter.Name}' was not defined `);
 
            this.Result = args.Result;
        }
    }
}