Class: Racc::SymbolTable
- Includes:
- Enumerable
- Defined in:
- lib/racc/grammar.rb
Instance Attribute Summary collapse
-
#anchor ⇒ Object
readonly
Returns the value of attribute anchor.
-
#dummy ⇒ Object
readonly
Returns the value of attribute dummy.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#nt_base ⇒ Object
readonly
Returns the value of attribute nt_base.
-
#symbols ⇒ Object
(also: #to_a)
readonly
Returns the value of attribute symbols.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #delete(sym) ⇒ Object
- #each(&block) ⇒ Object
- #each_nonterminal(&block) ⇒ Object
- #each_terminal(&block) ⇒ Object
- #fix ⇒ Object
-
#initialize ⇒ SymbolTable
constructor
A new instance of SymbolTable.
- #intern(val, dummy = false) ⇒ Object
- #nonterminals ⇒ Object
- #nt_max ⇒ Object
- #terminals(&block) ⇒ Object
Constructor Details
#initialize ⇒ SymbolTable
Returns a new instance of SymbolTable.
873 874 875 876 877 878 879 |
# 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 |
Instance Attribute Details
#anchor ⇒ Object (readonly)
Returns the value of attribute anchor.
882 883 884 |
# File 'lib/racc/grammar.rb', line 882 def anchor @anchor end |
#dummy ⇒ Object (readonly)
Returns the value of attribute dummy.
881 882 883 |
# File 'lib/racc/grammar.rb', line 881 def dummy @dummy end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
883 884 885 |
# File 'lib/racc/grammar.rb', line 883 def error @error end |
#nt_base ⇒ Object (readonly)
Returns the value of attribute nt_base.
906 907 908 |
# File 'lib/racc/grammar.rb', line 906 def nt_base @nt_base end |
#symbols ⇒ Object (readonly) Also known as: to_a
Returns the value of attribute symbols.
898 899 900 |
# File 'lib/racc/grammar.rb', line 898 def symbols @symbols end |
Instance Method Details
#[](id) ⇒ Object
885 886 887 |
# File 'lib/racc/grammar.rb', line 885 def [](id) @symbols[id] end |
#delete(sym) ⇒ Object
901 902 903 904 |
# File 'lib/racc/grammar.rb', line 901 def delete(sym) @symbols.delete sym @cache.delete sym.value end |
#each(&block) ⇒ Object
912 913 914 |
# File 'lib/racc/grammar.rb', line 912 def each(&block) @symbols.each(&block) end |
#each_nonterminal(&block) ⇒ Object
928 929 930 |
# File 'lib/racc/grammar.rb', line 928 def each_nonterminal(&block) @nterms.each(&block) end |
#each_terminal(&block) ⇒ Object
920 921 922 |
# File 'lib/racc/grammar.rb', line 920 def each_terminal(&block) @terms.each(&block) end |
#fix ⇒ Object
932 933 934 935 936 937 938 939 940 |
# 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 |
#intern(val, dummy = false) ⇒ Object
889 890 891 892 893 894 895 896 |
# 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 |
#nonterminals ⇒ Object
924 925 926 |
# File 'lib/racc/grammar.rb', line 924 def nonterminals @symbols[@nt_base, @symbols.size - @nt_base] end |
#nt_max ⇒ Object
908 909 910 |
# File 'lib/racc/grammar.rb', line 908 def nt_max @symbols.size end |
#terminals(&block) ⇒ Object
916 917 918 |
# File 'lib/racc/grammar.rb', line 916 def terminals(&block) @symbols[0, @nt_base] end |