public override int Interpret(ITerminalListExpression <string> creditsIntergalacticWordsList)
        {
            ContractUtility.Requires <ArgumentOutOfRangeException>(creditsIntergalacticWordsList != null && creditsIntergalacticWordsList.DataList != null &&
                                                                   creditsIntergalacticWordsList.DataList.Count > 0, "normalIntergalacticWordsList and normalIntergalacticWordsList.DataList cannot be null" +
                                                                   "and normalIntergalacticWordsList.DataList should be > 0");
            var creditsTypeInputWordJustBeforeIs = creditsIntergalacticWordsList.DataList.LastOrDefault();
            var allowedCreditTypes = Enum.GetNames(typeof(CreditsType));

            ContractUtility.Requires <ArgumentException>(!String.IsNullOrEmpty(creditsTypeInputWordJustBeforeIs) && allowedCreditTypes.Contains(creditsTypeInputWordJustBeforeIs), "The last word must be any one of " + allowedCreditTypes.Aggregate((a, b) => a + " , " + b) + " .");

            ITerminalIsExpression <string, decimal> terminalIsExpression = null;

            ContractUtility.Requires <InvalidOperationException>(creditsInputMappingsWithTerminalIsExpressions.TryGetValue(creditsTypeInputWordJustBeforeIs, out terminalIsExpression), creditsTypeInputWordJustBeforeIs + " was not supplied in the input provided earlier while storing.");

            var normalInputWordsListBeforeCreditsType = creditsIntergalacticWordsList.DataList.Except(new List <string> {
                creditsTypeInputWordJustBeforeIs
            }).ToList();
            var normalInputWordsListBeforeCreditsTypeNumberFormatValue = 1;

            if (normalInputWordsListBeforeCreditsType.Count > 0)
            {
                var normalInputSemanticLanguageExpression = new NormalInputSemanticLanguageExpression(numberFormatCalculator, symbolValues);
                var normalIntergalacticWordsList          = new TerminalListExpression <string>(normalInputWordsListBeforeCreditsType);
                normalInputWordsListBeforeCreditsTypeNumberFormatValue = normalInputSemanticLanguageExpression.Interpret(normalIntergalacticWordsList);
            }

            return(Convert.ToInt32(normalInputWordsListBeforeCreditsTypeNumberFormatValue * terminalIsExpression.RightExpressionData.Data));
        }
Ejemplo n.º 2
0
        public override int Interpret(ITerminalListExpression <string> normalIntergalacticWordsList)
        {
            ContractUtility.Requires <ArgumentOutOfRangeException>(normalIntergalacticWordsList != null && normalIntergalacticWordsList.DataList != null &&
                                                                   normalIntergalacticWordsList.DataList.Count > 0, "normalIntergalacticWordsList and normalIntergalacticWordsList.DataList cannot be null" +
                                                                   "and normalIntergalacticWordsList.DataList should be > 0");

            var accumulatedNumberFormat = new StringBuilder();

            normalIntergalacticWordsList.DataList.ForEach(x =>
            {
                ITerminalIsExpression <string, string> terminalIsExpression = null;
                ContractUtility.Requires <InvalidOperationException>(normalInputMappingsWithTerminalIsExpressions.TryGetValue(x, out terminalIsExpression), x + " was not supplied in the input provided earlier while storing.");
                var numberFormat = terminalIsExpression.RightExpressionData.Data;
                accumulatedNumberFormat.Append(numberFormat);
            }
                                                          );
            return(numberFormatCalculator.ToNumber(accumulatedNumberFormat.ToString()));
        }
Ejemplo n.º 3
0
 public abstract int Interpret(ITerminalListExpression <string> intergalacticWordsList);