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:



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

#endmarkerDendroid::Syntax::Terminal (readonly)

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

Returns:



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

def endmarker
  @endmarker
end

#epsilonDendroid::Syntax::Terminal (readonly)

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

Returns:



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

def epsilon
  @epsilon
end

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

Returns non-terminal to FIRST SETS mapping.

Returns:



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

def first_sets
  @first_sets
end

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

Returns non-terminal to FOLLOW SETS mapping.

Returns:



31
32
33
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 31

def follow_sets
  @follow_sets
end

#grammarDendroid::Syntax::Grammar (readonly)

Returns The grammar subjected to analysis.

Returns:



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

def grammar
  @grammar
end

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

Returns non-terminal to PREDICT SETS mapping.

Returns:



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

def predict_sets
  @predict_sets
end

#production2itemsObject (readonly)

Returns the value of attribute production2items.



15
16
17
# File 'lib/dendroid/grm_analysis/grm_analyzer.rb', line 15

def production2items
  @production2items
end

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

Parameters:



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