Class: Dendroid::GrmAnalysis::GrmAnalyzer
- Inherits:
-
Object
- Object
- Dendroid::GrmAnalysis::GrmAnalyzer
- Defined in:
- lib/dendroid/grm_analysis/grm_analyzer.rb
Overview
An analyzer performs an analysis of the grammar rules and build objects (dotted items, first and follow sets) to be used by a recognizer or a parser.
Instance Attribute Summary collapse
-
#endmarker ⇒ Dendroid::Syntax::Terminal
readonly
The pseudo-terminal ‘$$` for end of input stream.
-
#epsilon ⇒ Dendroid::Syntax::Terminal
readonly
The pseudo-terminal ‘__epsilon` (for empty string).
-
#first_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>}
readonly
Non-terminal to FIRST SETS mapping.
-
#follow_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>}
readonly
Non-terminal to FOLLOW SETS mapping.
-
#grammar ⇒ Dendroid::Syntax::Grammar
readonly
The grammar subjected to analysis.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#predict_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>}
readonly
Non-terminal to PREDICT SETS mapping.
-
#production2items ⇒ Object
readonly
Returns the value of attribute production2items.
Instance Method Summary collapse
-
#initialize(aGrammar) ⇒ GrmAnalyzer
constructor
Constructor.
-
#next_item(aDottedItem) ⇒ Object
The next item of a given dotted item.
- #symbol2production(sym) ⇒ Object
Constructor Details
#initialize(aGrammar) ⇒ GrmAnalyzer
Constructor. Build dotted items, first, follow sets for the given grammar
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 34 def initialize(aGrammar) @grammar = aGrammar @items = [] @production2items = {} @epsilon = Syntax::Terminal.new(:__epsilon) @endmarker = Syntax::Terminal.new(:"$$") @first_sets = {} @predict_sets = {} @follow_sets = {} build_dotted_items build_first_sets build_follow_sets end |
Instance Attribute Details
#endmarker ⇒ Dendroid::Syntax::Terminal (readonly)
Returns The pseudo-terminal ‘$$` for end of input stream.
20 21 22 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 20 def endmarker @endmarker end |
#epsilon ⇒ Dendroid::Syntax::Terminal (readonly)
Returns The pseudo-terminal ‘__epsilon` (for empty string).
17 18 19 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 17 def epsilon @epsilon end |
#first_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)
Returns non-terminal to FIRST SETS mapping.
23 24 25 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 23 def first_sets @first_sets end |
#follow_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)
Returns non-terminal to FOLLOW SETS mapping.
29 30 31 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 29 def follow_sets @follow_sets end |
#grammar ⇒ Dendroid::Syntax::Grammar (readonly)
Returns The grammar subjected to analysis.
12 13 14 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 12 def grammar @grammar end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
13 14 15 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 13 def items @items end |
#predict_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)
Returns non-terminal to PREDICT SETS mapping.
26 27 28 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 26 def predict_sets @predict_sets end |
#production2items ⇒ Object (readonly)
Returns the value of attribute production2items.
14 15 16 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 14 def production2items @production2items end |
Instance Method Details
#next_item(aDottedItem) ⇒ Object
The next item of a given dotted item
51 52 53 54 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 51 def next_item(aDottedItem) prod = aDottedItem.rule prod.next_item(aDottedItem) end |
#symbol2production(sym) ⇒ Object
56 57 58 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 56 def symbol2production(sym) grammar.nonterm2production[sym] end |