struct CLTK::Parser::State

Overview

The State class is used to represent sets of items and actions to be used during parsing.

Defined in:

cltk/parser/state.cr

Constructors

Instance Method Summary

Instance methods inherited from class Object

in?(collection : Array | Set) in?

Constructor Detail

def self.new(id : Int32, actions : Hash(String, Array(CLTK::Parser::Action)), items : Array(CFG::Item)) #

[View source]
def self.new(tokens : Array(String), items : Array(CLTK::CFG::Item) = [] of CFG::Item) #

Instantiate a new State object.

@param [Array] tokens Tokens that represent this state @param [ArrayCFG::Item] items Items that make up this state


[View source]

Instance Method Detail

def <<(item) #

[View source]
def ==(other) #

Compare one State to another. Two States are equal if they have the same items or, if the items have been cleaned, if the States have the same ID.

@param [State] other Another State to compare to

@return [Boolean]


[View source]
def actions : Hash(String, Array(CLTK::Parser::Action)) #

@return [Hash{Symbol => Array}] Maps lookahead symbols to actions


[View source]
def add_reduction(production) #

Add a Reduce action to the state.

@param [Production] production Production used to perform the reduction

@return [void]


[View source]
def append(item) #

@param [CFG::Item] item Item to add to this state.


[View source]
def clean #

Clean this State by removing the list of {CFG::Item} objects.

@return [void]


[View source]
def close(productions) #

Close this state using productions.

@param [ArrayCFG::Production] productions Productions used to close this state.

@return [vod]


[View source]
def conflict_on?(sym) #

Checks to see if there is a conflict in this state, given a input of sym. Returns :SR if a shift/reduce conflict is detected and :RR if a reduce/reduce conflict is detected. If no conflict is detected nil is returned.

@param [Symbol] sym Symbol to check for conflicts on.

@return [:SR, :RR, nil]


[View source]
def each(&) #

Iterate over the state's items.

@return [void]


[View source]
def id : Int32 #

@return [Integer] State's ID.


[View source]
def id=(id : Int32) #

@return [Integer] State's ID.


[View source]
def items : Array(CLTK::CFG::Item) #

@return [ArrayCFG::Item] Item objects that comprise this state


[View source]
def on(symbol, action : Action) #

Specify an Action to perform when the input token is symbol.

@param [Symbol] symbol Symbol to add action for. @param [Action] action Action for symbol.

@return [void]


[View source]
def on?(symbol) #

Returns that actions that should be taken when the input token is symbol.

@param [Symbol] symbol Symbol we want the actions for.

@return [Array] Actions that should be taken.


[View source]