Class: Dendroid::GrmAnalysis::GrmAnalyzer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(aGrammar) ⇒ GrmAnalyzer

Constructor. Build dotted items, first, follow sets for the given grammar

Parameters:



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

#endmarkerDendroid::Syntax::Terminal (readonly)

Returns The pseudo-terminal ‘$$` for end of input stream.

Returns:



20
21
22
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 20

def endmarker
  @endmarker
end

#epsilonDendroid::Syntax::Terminal (readonly)

Returns The pseudo-terminal ‘__epsilon` (for empty string).

Returns:



17
18
19
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 17

def epsilon
  @epsilon
end

#first_setsHash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)

Returns non-terminal to FIRST SETS mapping.

Returns:



23
24
25
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 23

def first_sets
  @first_sets
end

#follow_setsHash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)

Returns non-terminal to FOLLOW SETS mapping.

Returns:



29
30
31
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 29

def follow_sets
  @follow_sets
end

#grammarDendroid::Syntax::Grammar (readonly)

Returns The grammar subjected to analysis.

Returns:



12
13
14
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 12

def grammar
  @grammar
end

#itemsObject (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_setsHash{Syntax::NonTerminal, Array<Syntax::Terminal>} (readonly)

Returns non-terminal to PREDICT SETS mapping.

Returns:



26
27
28
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 26

def predict_sets
  @predict_sets
end

#production2itemsObject (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

Parameters:



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