Class: Rley::Syntax::NonTerminal

Inherits:
GrmSymbol show all
Defined in:
lib/rley/syntax/non_terminal.rb

Overview

A non-terminal symbol (sometimes called a syntactic variable) represents a composition of terminal or non-terminal symbols

Instance Attribute Summary collapse

Attributes inherited from GrmSymbol

#generative, #name

Instance Method Summary collapse

Methods inherited from GrmSymbol

#generative?, #terminal?, #to_s

Constructor Details

#initialize(aName) ⇒ NonTerminal

Constructor.

Parameters:

  • aName (String)

    The name of the grammar symbol.



21
22
23
# File 'lib/rley/syntax/non_terminal.rb', line 21

def initialize(aName)
  super(aName)
end

Instance Attribute Details

#nullable=(value) ⇒ Object (writeonly)

A non-terminal symbol is nullable if it can match an empty string.



9
10
11
# File 'lib/rley/syntax/non_terminal.rb', line 9

def nullable=(value)
  @nullable = value
end

#undefined=(value) ⇒ Object (writeonly)

A non-terminal symbol is undefined if no production rule in the grammar has that non-terminal symbol in its left-hand side.



13
14
15
# File 'lib/rley/syntax/non_terminal.rb', line 13

def undefined=(value)
  @undefined = value
end

#unreachable=(value) ⇒ Object (writeonly)

A non-terminal symbol is unreachable if it cannot be reached (derived) from the start symbol.



17
18
19
# File 'lib/rley/syntax/non_terminal.rb', line 17

def unreachable=(value)
  @unreachable = value
end

Instance Method Details

#nullable?false/true

the empty string. As non-terminal symbol is nullable when it can can match to zero input token. The "nullability" of a non-terminal can practically be determined once all the production rules of the grammar are specified.

Returns:

  • (false/true)

    Return true if the symbol derives



30
31
32
# File 'lib/rley/syntax/non_terminal.rb', line 30

def nullable?()
  return @nullable
end

#undefined?false/true

on the left-hand side of any production rule.

Returns:

  • (false/true)

    Return true if the symbol doesn't appear



36
37
38
# File 'lib/rley/syntax/non_terminal.rb', line 36

def undefined?()
  return @undefined
end

#unreachable?false/true

from the start symbol.

Returns:

  • (false/true)

    Return true if the symbol cannot be derived



42
43
44
# File 'lib/rley/syntax/non_terminal.rb', line 42

def unreachable?()
  return @unreachable
end