Class: Racc::SymbolTable

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/racc/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSymbolTable

Returns a new instance of SymbolTable.



871
872
873
874
875
876
877
# File 'lib/racc/grammar.rb', line 871

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

Instance Attribute Details

#anchorObject (readonly)

Returns the value of attribute anchor.



880
881
882
# File 'lib/racc/grammar.rb', line 880

def anchor
  @anchor
end

#dummyObject (readonly)

Returns the value of attribute dummy.



879
880
881
# File 'lib/racc/grammar.rb', line 879

def dummy
  @dummy
end

#errorObject (readonly)

Returns the value of attribute error.



881
882
883
# File 'lib/racc/grammar.rb', line 881

def error
  @error
end

#nt_baseObject (readonly)

Returns the value of attribute nt_base.



904
905
906
# File 'lib/racc/grammar.rb', line 904

def nt_base
  @nt_base
end

#symbolsObject (readonly) Also known as: to_a

Returns the value of attribute symbols.



896
897
898
# File 'lib/racc/grammar.rb', line 896

def symbols
  @symbols
end

Instance Method Details

#[](id) ⇒ Object



883
884
885
# File 'lib/racc/grammar.rb', line 883

def [](id)
  @symbols[id]
end

#delete(sym) ⇒ Object



899
900
901
902
# File 'lib/racc/grammar.rb', line 899

def delete(sym)
  @symbols.delete sym
  @cache.delete sym.value
end

#each(&block) ⇒ Object



910
911
912
# File 'lib/racc/grammar.rb', line 910

def each(&block)
  @symbols.each(&block)
end

#each_nonterminal(&block) ⇒ Object



926
927
928
# File 'lib/racc/grammar.rb', line 926

def each_nonterminal(&block)
  @nterms.each(&block)
end

#each_terminal(&block) ⇒ Object



918
919
920
# File 'lib/racc/grammar.rb', line 918

def each_terminal(&block)
  @terms.each(&block)
end

#fixObject



930
931
932
933
934
935
936
937
938
# File 'lib/racc/grammar.rb', line 930

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

#intern(val, dummy = false) ⇒ Object



887
888
889
890
891
892
893
894
# File 'lib/racc/grammar.rb', line 887

def intern(val, dummy = false)
  @cache[val] ||=
      begin
        sym = Sym.new(val, dummy)
        @symbols.push sym
        sym
      end
end

#nonterminalsObject



922
923
924
# File 'lib/racc/grammar.rb', line 922

def nonterminals
  @symbols[@nt_base, @symbols.size - @nt_base]
end

#nt_maxObject



906
907
908
# File 'lib/racc/grammar.rb', line 906

def nt_max
  @symbols.size
end

#terminals(&block) ⇒ Object



914
915
916
# File 'lib/racc/grammar.rb', line 914

def terminals(&block)
  @symbols[0, @nt_base]
end