Example #1
0
        /**
         * Returns a result if the specified symbol matchs the left and right context of the Rule
         *
         *
         */
        public override Word Rewrite(Symbol symbol, int SymbolIndex, Word word)
        {
            //check if that rule could be applied for the specified symbol
            if (predecessor.Equals(symbol))
            {
                //TODO: use regex
                //string sPattern = "^\\d{3}-\\d{3}-\\d{4}$";
                //if(System.Text.RegularExpressions.Regex.IsMatch(s, sPattern)

                //check if the context matches
                String symbolLeft  = word.ToString().Substring(0, SymbolIndex);
                String symbolRight = word.ToString().Substring(SymbolIndex, word.ToString().Length - 1);
                if (symbolLeft.EndsWith(leftContext.ToString()) && symbolRight.StartsWith(rightContext.ToString()))
                {
                    return(successor);
                }
                else
                {
                    return(null);//context do not matches
                }
            }
            else
            {
                //throw new System.InvalidOperationException("This rule is not meant to be used with symbol: " + Symbol);
                return(null);
            }
        }
Example #2
0
        public override String ToString()
        {
            StringBuilder LSystemDescription = new StringBuilder();

            LSystemDescription.AppendLine("LSystem")
            .Append("Axiom: ").AppendLine(Axiom.ToString())
            .AppendLine("Production Rules: ");

            //describe rules used
            foreach (ProductionRule rule in ProductionRules)
            {
                LSystemDescription.AppendLine(rule.ToString());
            }

            //print out the generated language
            foreach (Word word in words)
            {
                LSystemDescription.AppendLine(word.ToString());
            }

            return(LSystemDescription.ToString());
        }
Example #3
0
 public override String ToString()
 {
     StringBuilder ruleDescription = new StringBuilder();
     ruleDescription.Append(predecessor.ToString()).Append(" = ").Append(successor.ToString());
     return ruleDescription.ToString();
 }