Class: ANTLR3::Profile::Profile

Inherits:
Struct
  • Object
show all
Defined in:
lib/antlr3/profile.rb,
lib/antlr3/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProfile

Returns a new instance of Profile.


108
109
110
111
112
113
114
115
# 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

Instance Attribute Details

#characters_matchedObject

Returns the value of attribute characters_matched

Returns:

  • (Object)

    the current value of characters_matched


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def characters_matched
  @characters_matched
end

#cyclic_looksObject

Returns the value of attribute cyclic_looks

Returns:

  • (Object)

    the current value of cyclic_looks


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def cyclic_looks
  @cyclic_looks
end

#fixed_looksObject

Returns the value of attribute fixed_looks

Returns:

  • (Object)

    the current value of fixed_looks


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def fixed_looks
  @fixed_looks
end

#grammar_fileObject

Returns the value of attribute grammar_file

Returns:

  • (Object)

    the current value of grammar_file


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def grammar_file
  @grammar_file
end

#guessing_rule_invocationsObject

Returns the value of attribute guessing_rule_invocations

Returns:

  • (Object)

    the current value of guessing_rule_invocations


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def guessing_rule_invocations
  @guessing_rule_invocations
end

#hidden_characters_matchedObject

Returns the value of attribute hidden_characters_matched

Returns:

  • (Object)

    the current value of hidden_characters_matched


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def hidden_characters_matched
  @hidden_characters_matched
end

#hidden_tokensObject

Returns the value of attribute hidden_tokens

Returns:

  • (Object)

    the current value of hidden_tokens


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def hidden_tokens
  @hidden_tokens
end

#memoization_cache_entriesObject

Returns the value of attribute memoization_cache_entries

Returns:

  • (Object)

    the current value of memoization_cache_entries


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def memoization_cache_entries
  @memoization_cache_entries
end

#memoization_cache_hitsObject

Returns the value of attribute memoization_cache_hits

Returns:

  • (Object)

    the current value of memoization_cache_hits


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def memoization_cache_hits
  @memoization_cache_hits
end

#memoization_cache_missesObject

Returns the value of attribute memoization_cache_misses

Returns:

  • (Object)

    the current value of memoization_cache_misses


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def memoization_cache_misses
  @memoization_cache_misses
end

#parser_classObject

Returns the value of attribute parser_class

Returns:

  • (Object)

    the current value of parser_class


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def parser_class
  @parser_class
end

#reported_errorsObject

Returns the value of attribute reported_errors

Returns:

  • (Object)

    the current value of reported_errors


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def reported_errors
  @reported_errors
end

#rule_invocation_depthObject

Returns the value of attribute rule_invocation_depth

Returns:

  • (Object)

    the current value of rule_invocation_depth


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def rule_invocation_depth
  @rule_invocation_depth
end

#rule_invocationsObject

Returns the value of attribute rule_invocations

Returns:

  • (Object)

    the current value of rule_invocations


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def rule_invocations
  @rule_invocations
end

#semantic_predicatesObject

Returns the value of attribute semantic_predicates

Returns:

  • (Object)

    the current value of semantic_predicates


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def semantic_predicates
  @semantic_predicates
end

#syntactic_predicate_looksObject

Returns the value of attribute syntactic_predicate_looks

Returns:

  • (Object)

    the current value of syntactic_predicate_looks


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def syntactic_predicate_looks
  @syntactic_predicate_looks
end

#syntactic_predicatesObject

Returns the value of attribute syntactic_predicates

Returns:

  • (Object)

    the current value of syntactic_predicates


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def syntactic_predicates
  @syntactic_predicates
end

#tokensObject

Returns the value of attribute tokens

Returns:

  • (Object)

    the current value of tokens


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def tokens
  @tokens
end

#top_ruleObject

Returns the value of attribute top_rule

Returns:

  • (Object)

    the current value of top_rule


96
97
98
# File 'lib/antlr3/profile.rb', line 96

def top_rule
  @top_rule
end

Instance Method Details

#backtracking_decisionsObject


125
126
127
# File 'lib/antlr3/profile.rb', line 125

def backtracking_decisions
  syntactic_predicate_looks.length
end

#cyclic_decisionsObject


121
122
123
# File 'lib/antlr3/profile.rb', line 121

def cyclic_decisions
  cyclic_looks.length
end

#fixed_decisionsObject


117
118
119
# File 'lib/antlr3/profile.rb', line 117

def fixed_decisions
  fixed_looks.length
end

#generate_reportObject


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# 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