class Racc::SymbolTable
Attributes
Public Class Methods
# File lib/racc/grammar.rb, line 873 def initialize @symbols = [] # :: [Racc::Sym] @cache = {} # :: {(String|Symbol) => Racc::Sym} @dummy = intern(:$start, true) @anchor = intern(false, true) # Symbol ID = 0 @error = intern(:error, false) # Symbol ID = 1 end
Public Instance Methods
# File lib/racc/grammar.rb, line 885 def [](id) @symbols[id] end
# File lib/racc/grammar.rb, line 901 def delete(sym) @symbols.delete sym @cache.delete sym.value end
# File lib/racc/grammar.rb, line 912 def each(&block) @symbols.each(&block) end
# File lib/racc/grammar.rb, line 928 def each_nonterminal(&block) @nterms.each(&block) end
# File lib/racc/grammar.rb, line 920 def each_terminal(&block) @terms.each(&block) end
# File lib/racc/grammar.rb, line 932 def fix terms, nterms = @symbols.partition {|s| s.terminal? } @symbols = terms + nterms @terms = terms @nterms = nterms @nt_base = terms.size fix_ident check_terminals end
# File lib/racc/grammar.rb, line 889 def intern(val, dummy = false) @cache[val] ||= begin sym = Sym.new(val, dummy) @symbols.push sym sym end end
# File lib/racc/grammar.rb, line 924 def nonterminals @symbols[@nt_base, @symbols.size - @nt_base] end
# File lib/racc/grammar.rb, line 908 def nt_max @symbols.size end
# File lib/racc/grammar.rb, line 916 def terminals(&block) @symbols[0, @nt_base] end