class ANTLR3::Profile::Profile

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/antlr3/profile.rb, line 108
def initialize
  init_values = Array.new( self.class.members.length, 0 )
  super( *init_values )
  self.top_rule = self.parser_class = self.grammar_file = nil
  self.fixed_looks = DataSet.new
  self.cyclic_looks = DataSet.new
  self.syntactic_predicate_looks = DataSet.new
end

Public Instance Methods

backtracking_decisions() click to toggle source
# File lib/antlr3/profile.rb, line 125
def backtracking_decisions
  syntactic_predicate_looks.length
end
cyclic_decisions() click to toggle source
# File lib/antlr3/profile.rb, line 121
def cyclic_decisions
  cyclic_looks.length
end
fixed_decisions() click to toggle source
# File lib/antlr3/profile.rb, line 117
def fixed_decisions
  fixed_looks.length
end
generate_report() click to toggle source
# File lib/antlr3/profile.rb, line 129
def generate_report
  report = '+' << '-' * 78 << "+\n"
  report << '| ' << "ANTLR Rule Profile".center( 76 ) << " |\n"
  report << '+' << '-' * 78 << "+\n"
  report << "| Generated at #{ Time.now }".ljust( 78 ) << " |\n"
  report << "| Profiled #{ parser_class.name }##{ top_rule }".ljust( 78 ) << " |\n"
  report << "| Rule source generated from grammar file #{ grammar_file }".ljust( 78 ) << " |\n"
  report << '+' << '-' * 78 << "+\n"
  
  report << '| ' << "Rule Invocations".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Total Invocations", rule_invocations ]
  report << "| %-66s | %7i |\n" % [ "``Guessing'' Invocations", guessing_rule_invocations ]
  report << "| %-66s | %7i |\n" % [ "Deepest Level of Invocation", rule_invocation_depth ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  report << '| ' << "Execution Events".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Semantic Predicates Evaluated", semantic_predicates ]
  report << "| %-66s | %7i |\n" % [ "Syntactic Predicates Evaluated", syntactic_predicates ]
  report << "| %-66s | %7i |\n" % [ "Errors Reported", reported_errors ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  report << '| ' << "Token and Character Data".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Tokens Consumed", tokens ]
  report << "| %-66s | %7i |\n" % [ "Hidden Tokens Consumed", hidden_tokens ]
  report << "| %-66s | %7i |\n" % [ "Characters Matched", characters_matched ]
  report << "| %-66s | %7i |\n" % [ "Hidden Characters Matched", hidden_characters_matched ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  report << '| ' << "Memoization".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Cache Entries", memoization_cache_entries ]
  report << "| %-66s | %7i |\n" % [ "Cache Hits", memoization_cache_hits ]
  report << "| %-66s | %7i |\n" % [ "Cache Misses", memoization_cache_misses ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  [ 
    [ 'Fixed Lookahead (k)', fixed_looks ],
    [ 'Arbitrary Lookahead (k)', cyclic_looks ],
    [ 'Backtracking (Syntactic Predicate)', syntactic_predicate_looks ]
  ].each do |name, set|
    mean, stdev = '%4.2f' % set.average, '%4.2f' % set.standard_deviation
    report << '| ' << "#{ name } Decisions".center( 76 ) << " |\n"
    report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
    report << "| %-66s | %7i |\n" % [ "Count", set.length ]
    report << "| %-66s | %7i |\n" % [ "Minimum k", set.min ]
    report << "| %-66s | %7i |\n" % [ "Maximum k", set.max ]
    report << "| %-66s | %7s |\n" % [ "Average k", mean ]
    report << "| %-66s | %7s |\n" % [ "Standard Deviation of k", stdev ]
    report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  end
  return( report )
end