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.
-
#symbol2productions ⇒ Object
readonly
Returns the value of attribute symbol2productions.
Instance Method Summary collapse
-
#initialize(aGrammar) ⇒ GrmAnalyzer
constructor
Constructor.
-
#next_item(aDottedItem) ⇒ Object
The next item of a given dotted item.
Constructor Details
#initialize(aGrammar) ⇒ GrmAnalyzer
Constructor. Build dotted items, first, follow sets for the given grammar
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 36 def initialize(aGrammar) @grammar = aGrammar @items = [] @production2items = {} @symbol2productions = {} @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.
22 23 24 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 22 def endmarker @endmarker end |
#epsilon ⇒ Dendroid::Syntax::Terminal (readonly)
Returns The pseudo-terminal ‘__epsilon` (for empty string).
19 20 21 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 19 def epsilon @epsilon end |
#first_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)
Returns non-terminal to FIRST SETS mapping.
25 26 27 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 25 def first_sets @first_sets end |
#follow_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)
Returns non-terminal to FOLLOW SETS mapping.
31 32 33 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 31 def follow_sets @follow_sets end |
#grammar ⇒ Dendroid::Syntax::Grammar (readonly)
Returns The grammar subjected to analysis.
13 14 15 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 13 def grammar @grammar end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
14 15 16 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 14 def items @items end |
#predict_sets ⇒ Hash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)
Returns non-terminal to PREDICT SETS mapping.
28 29 30 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 28 def predict_sets @predict_sets end |
#production2items ⇒ Object (readonly)
Returns the value of attribute production2items.
15 16 17 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 15 def production2items @production2items end |
#symbol2productions ⇒ Object (readonly)
Returns the value of attribute symbol2productions.
16 17 18 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 16 def symbol2productions @symbol2productions end |
Instance Method Details
#next_item(aDottedItem) ⇒ Object
The next item of a given dotted item
54 55 56 57 |
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 54 def next_item(aDottedItem) prod = aDottedItem.rule prod.next_item(aDottedItem) end |