Example #1
0
 /// <summary>
 /// Build hash tables to optimize term matching, and a linked list that will serve as a execution cache.
 /// </summary>
 private void ClassifyInput()
 {
     executionCache = new List <InterpreterTerm>();
     programRules   = new List <TrsReductionRule>();
     typeChecker    = new InterpreterTypeChecker(initialProgram);
     foreach (var statement in initialProgram.Statements)
     {
         if (statement is TrsTermBase)
         {
             executionCache.Add(new InterpreterTerm(statement as TrsTermBase));
         }
         else if (statement is TrsReductionRule)
         {
             // All rules treated as term prodocuts to simplify rewriting
             var rule = statement as TrsReductionRule;
             if (rule.Head is TrsTermProduct)
             {
                 programRules.Add(statement as TrsReductionRule);
             }
             else
             {
                 programRules.Add(new TrsReductionRule(new TrsTermProduct(new[] { rule.Head }.ToList()), rule.Tail, (AstReductionRule)rule.AstSource));
             }
         }
         else if (!(statement is TrsTypeDefinition) && !(statement is TrsLimitStatement))
         {
             throw new ArgumentException("Unknown statement type.", "programBlockIn");
         }
     }
 }
Example #2
0
 /// <summary>
 /// Build hash tables to optimize term matching, and a linked list that will serve as a execution cache.
 /// </summary>
 private void ClassifyInput()
 {
     executionCache = new List<InterpreterTerm>();
       programRules = new List<TrsReductionRule>();
       typeChecker = new InterpreterTypeChecker(initialProgram);
       foreach (var statement in initialProgram.Statements)
       {
     if (statement is TrsTermBase)
     {
       executionCache.Add(new InterpreterTerm(statement as TrsTermBase));
     }
     else if (statement is TrsReductionRule)
     {
       // All rules treated as term prodocuts to simplify rewriting
       var rule = statement as TrsReductionRule;
       if (rule.Head is TrsTermProduct)
       {
     programRules.Add(statement as TrsReductionRule);
       }
       else
       {
     programRules.Add(new TrsReductionRule(new TrsTermProduct(new[] { rule.Head }.ToList()), rule.Tail, (AstReductionRule)rule.AstSource));
       }
     }
     else if (!(statement is TrsTypeDefinition) && !(statement is TrsLimitStatement))
     {
       throw new ArgumentException("Unknown statement type.", "programBlockIn");
     }
       }
 }