Beispiel #1
0
		/// <summary>
		/// 評価用メソッド.
		/// </summary>
		/// <param name="context">コンテキストオブジェクト.</param>
		public override void Interpret(GeneratorContext context) {
			// 戻り値の準備
			Result result = new Result(Name);

			Token<TokenType> token = context.Current;
			if (token == null) {
				context.PushResult(result);
				return;
			}

			result.IsMatch = token.Type.Name == Name;
			if (result.IsMatch) {
				result.Matches.AddToken(token);
				context.Next();
			}
			DebugLog(string.Format(
				"TerminalExpression.Interpret(): {0} = {1}, {2}",
				token.Type.Name,
				Name,
				result.IsMatch
			));

			// 戻り値
			context.PushResult(result);
		}
Beispiel #2
0
        /// <summary>
        /// 評価用メソッド.
        /// </summary>
        /// <param name="context">コンテキストオブジェクト.</param>
        public override void Interpret(GeneratorContext context)
        {
            DebugLog("NonterminalExpression.Interpret(): " + Name);

            // 戻り値の準備
            Result result = new Result(Name);

            //Matches = new TokenMatches(Name);
            //IsMatch = false;

            if (context.Fields.ContainsKey(Name) == false)
            {
                throw new InterpreterException("NonterminalExpression.Interpret() Error");
            }

            GeneratedExpression exp = context.Fields[Name];

            exp.Interpret(context);
            Result itemResult = context.PopResult();

            result.IsMatch = itemResult.IsMatch;
            result.Matches.ConcatTokens(itemResult.Matches);

            context.PushResult(result);
        }
Beispiel #3
0
        /// <summary>
        /// 評価用メソッド.
        /// </summary>
        /// <param name="context">コンテキストオブジェクト.</param>
        public override void Interpret(GeneratorContext context)
        {
            DebugLog("GroupExpression.Interpret(): " + Name + ", " + Expressions.Count);

            // 戻り値の準備
            Result result = new Result(Name);

            //Matches = new TokenMatches(Name);
            //IsMatch = false;

            foreach (GeneratedExpression exp in Expressions)
            {
                exp.Interpret(context);
                Result itemResult = context.PopResult();

                result.Matches.ConcatTokens(itemResult.Matches);
                if (itemResult.IsMatch == false)
                {
                    if (exp.Type == ExpressionType.Option)
                    {
                        continue;
                    }
                    result.IsMatch = false;
                    //throw new InterpreterException("FieldExpression.Interpret() Error");
                    break;
                }
                else
                {
                    result.IsMatch = true;
                }
            }

            context.PushResult(result);
        }
Beispiel #4
0
        /// <summary>
        /// 評価用メソッド.
        /// </summary>
        /// <param name="context">コンテキストオブジェクト.</param>
        public override void Interpret(GeneratorContext context)
        {
            DebugLog("OrExpression.Interpret(): " + Name + ", " + Expressions.Count);

            // 戻り値の準備
            Result result = new Result(Name);

            //Matches = new TokenMatches(Name);
            //IsMatch = false;

            foreach (GeneratedExpression exp in Expressions)
            {
                //Console.WriteLine("*** OrExpression.Interpret(): " + exp.Name);
                exp.Interpret(context);
                //Console.WriteLine("*** OrExpression.Interpret(): " + exp.IsMatch);
                Result itemResult = context.PopResult();

                if (itemResult.IsMatch)
                {
                    result.IsMatch = true;
                    result.Matches.ConcatTokens(itemResult.Matches);
                    break;
                }
            }

            context.PushResult(result);
        }
Beispiel #5
0
        /// <summary>
        /// 評価用メソッド.
        /// </summary>
        /// <param name="context">コンテキストオブジェクト.</param>
        public override void Interpret(GeneratorContext context)
        {
            DebugLog("OptionExpression.Interpret(): " + Name);

            // 戻り値の準備
            Result result = new Result(Name);

            //Matches = new TokenMatches(Name);
            //IsMatch = false;

            foreach (GeneratedExpression exp in Expressions)
            {
                exp.Interpret(context);
                Result itemResult = context.PopResult();

                if (itemResult.IsMatch)
                {
                    result.IsMatch = true;
                    result.Matches.ConcatTokens(itemResult.Matches);
                    //Matches.ConcatTokens(exp.Matches);
                    //break;
                }
                else
                {
                    result.Matches.ConcatTokens(itemResult.Matches);
                    //Matches.ConcatTokens(exp.Matches);
                    break;
                }
            }

            context.PushResult(result);
        }
Beispiel #6
0
        /// <summary>
        /// 評価用メソッド.
        /// </summary>
        /// <param name="context">コンテキストオブジェクト.</param>
        public override void Interpret(GeneratorContext context)
        {
            DebugLog("FieldExpression.Interpret(): " + Name);

            // 戻り値の準備
            Result result = new Result(Name);

            // 子要素を巡回する
            foreach (GeneratedExpression exp in Expressions)
            {
                DebugLog("-\tFieldExpression.Expressions : (" + exp.Name + ")");
                exp.Interpret(context);
                Result itemResult = context.PopResult();

                result.Matches.ConcatTokens(itemResult.Matches);
                if (itemResult.IsMatch == false)
                {
                    DebugLog("-\texp.IsMatch == false : (" + exp.Name + ")");
                    if (exp.Type == ExpressionType.Option)
                    {
                        continue;
                    }
                    result.IsMatch = false;
                    //throw new InterpreterException("FieldExpression.Interpret() Error");
                    break;
                }
                else
                {
                    result.IsMatch = true;
                }
            }

            // マッチしたらイベントを発生させる
            if (result.IsMatch)
            {
                context.OnMatchField(Name, result.Matches);
            }

            context.PushResult(result);
        }
Beispiel #7
0
        /// <summary>
        /// 評価用メソッド.
        /// </summary>
        /// <param name="context">コンテキストオブジェクト.</param>
        public override void Interpret(GeneratorContext context)
        {
            DebugLog("LoopExpression.Interpret(): " + Name + ", " + Expressions.Count);

            // 戻り値の準備
            Result result = new Result(Name);

            int maxCount = 0;

            foreach (GeneratedExpression exp in Expressions)
            {
                if (exp.Type != ExpressionType.Option)
                {
                    maxCount++;
                }
            }

            bool loop = true;

            while (loop)
            {
                int count = 0;
                GeneratedExpression exp2 = null;
                foreach (GeneratedExpression exp in Expressions)
                {
                    exp2 = exp;
                    DebugLog("LoopExpression.Expressions : (" + exp.Name + ")");
                    exp.Interpret(context);
                    Result itemResult = context.PopResult();

                    result.IsMatch = itemResult.IsMatch;
                    if (itemResult.IsMatch == false)
                    {
                        if (exp.Type == ExpressionType.Option)
                        {
                            continue;
                        }
                        DebugLog("-\texp.IsMatch == false : (" + exp.Name + ")");
                        break;
                    }
                    result.Matches.ConcatTokens(itemResult.Matches);
                    //Matches.ConcatTokens(exp.Matches);
                    count++;
                }
                if (count == 0)
                {
                    //Console.WriteLine("LoopExpression: count == 0: " + exp2.Type + ", " + exp2.Name);
                    break;
                }
                if (count == maxCount)
                {
                }
                if (count != maxCount)
                {
                    ThrowParseException(
                        ErrorMessages.UnexpectedToken, context.Current
                        );
                }

                Token <TokenType> token = context.Current;
                if (token == null)
                {
                    loop = false;
                    break;
                }
            }

            context.PushResult(result);
            //Matches = matches;
        }