Ejemplo n.º 1
0
    private void LoadRulesAndMessages(List <string> input)
    {
        var index = 0;

        for (int i = 0; i < input.Count; i++, index++)
        {
            if (input[i].Length == 0)
            {
                index++;
                break;
            }
            else
            {
                var parts      = input[i].Split(": ");
                var ruleNumber = parts[0];
                Rules.Add(parts[0], parts[1]);
                if (parts[1].Contains("a") || parts[1].Contains("b"))
                {
                    ResolvedRules.Add(parts[0], parts[1].Replace("\"", ""));
                }
            }
        }

        for (int i = index; i < input.Count; i++)
        {
            Messages.Add(input[i]);
        }
    }
Ejemplo n.º 2
0
    private string ResolveRule(string ruleNumber)
    {
        if (ResolvedRules.ContainsKey(ruleNumber))
        {
            return(ResolvedRules[ruleNumber]);
        }

        var ruleText      = Rules[ruleNumber];
        var ruleSections  = ruleText.Split(" | ");
        var stringBuilder = new StringBuilder();

        stringBuilder.Append("(");
        for (int i = 0; i < ruleSections.Length; i++)
        {
            var rules = ruleSections[i].Split(" ");
            foreach (var rule in rules)
            {
                stringBuilder.Append(ResolveRule(rule));
            }
            if (i < ruleSections.Length - 1)
            {
                stringBuilder.Append("|");
            }
        }

        stringBuilder.Append(")");
        ResolvedRules.Add(ruleNumber, stringBuilder.ToString());

        return(stringBuilder.ToString());
    }