Exemple #1
0
 public Object Clone()
 {
     try
     {
         GrammarParser other = (GrammarParser)base.MemberwiseClone();
         other._rules = (Hashtable)_rules.Clone();
         // we'll pointer-copy the root
         return(other);
     }
     catch (CloneNotSupportedException e)
     {
         return(null); // never happens
     }
 }
Exemple #2
0
        /// <summary>
        /// A simple testing fcility.
        /// </summary>
        public static void Main(string[] args)
        {
            // make a dummy EvolutionState that just has an output for testing
            var state = new EvolutionState {
                Output = new Output(true)
            };

            state.Output.AddLog(Log.D_STDOUT, false);
            state.Output.AddLog(Log.D_STDERR, true);

            var gp = new GrammarParser();

            gp.ParseRules(state,
                          new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.Read)), null);
            gp.ValidateRules();
            Console.WriteLine(gp);
        }
Exemple #3
0
        /**
         * The LL(1) parsing algorithm to parse the lisp tree, the lisp tree is actually
         * fed as a flattened list, the parsing code uses the "exact" (and as-is) procedure
         * described in the dragon book.
         **/
        public int[] ParseSexp(ArrayList flatSexp, GrammarParser gp)
        {
            throw new NotImplementedException();

            /*
             * // We can't use array here, because we don't know how we are going to traverse
             * // the grammar tree, so the length is not known beforehand.
             * ArrayList intList = new ArrayList();
             * Queue input = new Queue((ArrayList)flatSexp.Clone());
             * Stack stack = new Stack();
             * stack.Push(((GrammarNode)gp.ProductionRuleList.get(0)).GetHead());
             * int index = 0;
             * while (input.Count != 0)
             * {
             * String token = (String)input.Remove();
             * while (true)
             * {
             * if (stack.Peek().Equals(token))
             * {
             *  // if found a match, pop it from the stack
             *  stack.Pop();
             *  // if the stack top is an ERC, read the next token
             *  if (token.Equals("ERC"))
             *  {
             *      token = (String)input.Remove();
             *      intList.Add(Integer.valueOf(token));
             *  }
             *  break;
             * }
             * else
             * {
             *  int rIndex = ((Integer)gp.RuleHeadToIndex.get(stack.peek())).intValue();
             *  int fIndex = ((Integer)gp.FunctionHeadToIndex.get(token)).intValue();
             *  Integer ruleIndex = new Integer(gp.PredictiveParseTable[rIndex][fIndex]);
             *  // get the action (rule) to expand
             *  GrammarNode action = (GrammarNode)gp.IndexToRule.get(ruleIndex);
             *  // if the index is still in the range of minGene.Length, use it.
             *  // otherwise use the minGene[0] value.
             *  int minIndex = 0; if (index < MinGenes.Length) minIndex = index;
             *  // now add
             *  intList.Add(new Integer(((Integer)gp.AbsIndexToRelIndex.get(ruleIndex)).intValue() + (int)MinGenes[minIndex]));
             *  index++;
             *  stack.Pop();
             *  action = action.Children[0];
             *  if (action is GrammarFunctionNode)
             *          {
             *      // push the rule (action) arguments in reverse way
             *      for (int i = ((GrammarFunctionNode)action).GetNumArguments() - 1
             *              ; i >= 0; i--)
             *          stack.Push(((GrammarFunctionNode)action).GetArgument(i).GetHead());
             *      // the rule (action) head should be on the top
             *      stack.Push(action.GetHead());
             *  }
             *      else if (action is GrammarRuleNode) // push as usual
             *          stack.Push(((GrammarRuleNode)action).GetHead());
             * }
             * }
             * }
             * // now convert the list into an array
             * int[] genomeVals = new int[intList.Count];
             * for (int i = 0; i < intList.Count; i++) { genomeVals[i] = ((Int32)intList[i]).intValue(); }
             * return genomeVals;
             */
        }