SyntaxTutor
Educational app designed to help compiler students understand LL(1) and SLR(1) parsing algorithms.
 
Loading...
Searching...
No Matches
Lr0Item Struct Reference

Represents an LR(0) item used in LR automata construction. More...

#include <lr0_item.hpp>

Public Member Functions

 Lr0Item (std::string antecedent, std::vector< std::string > consequent, std::string epsilon, std::string eol)
 Constructs an LR(0) item with the dot at position 0.
 
 Lr0Item (std::string antecedent, std::vector< std::string > consequent, unsigned int dot, std::string epsilon, std::string eol)
 Constructs an LR(0) item with a custom dot position.
 
std::string NextToDot () const
 Returns the symbol immediately after the dot, or empty if the dot is at the end.
 
void PrintItem () const
 Prints the LR(0) item to the standard output in a human-readable format.
 
std::string ToString () const
 Converts the item to a string representation, including the dot position.
 
void AdvanceDot ()
 Advances the dot one position to the right.
 
bool IsComplete () const
 Checks whether the dot has reached the end of the production.
 
bool operator== (const Lr0Item &other) const
 Equality operator for comparing two LR(0) items.
 

Public Attributes

std::string antecedent_
 The non-terminal on the left-hand side of the production.
 
std::vector< std::string > consequent_
 The sequence of symbols on the right-hand side of the production.
 
std::string epsilon_
 The symbol representing the empty string (ε).
 
std::string eol_
 The symbol representing end-of-line or end-of-input ($).
 
unsigned int dot_ = 0
 The position of the dot (·) in the production.
 

Detailed Description

Represents an LR(0) item used in LR automata construction.

An LR(0) item has a production of the form A → α·β, where the dot indicates the current parsing position. This structure tracks the antecedent (left-hand side), consequent (right-hand side), the dot position, and special symbols like EPSILON and end-of-line ($).

Constructor & Destructor Documentation

◆ Lr0Item() [1/2]

Lr0Item::Lr0Item ( std::string antecedent,
std::vector< std::string > consequent,
std::string epsilon,
std::string eol )

Constructs an LR(0) item with the dot at position 0.

Parameters
antecedentThe left-hand side non-terminal.
consequentThe right-hand side of the production.
epsilonThe EPSILON symbol.
eolThe end-of-line symbol.
Here is the caller graph for this function:

◆ Lr0Item() [2/2]

Lr0Item::Lr0Item ( std::string antecedent,
std::vector< std::string > consequent,
unsigned int dot,
std::string epsilon,
std::string eol )

Constructs an LR(0) item with a custom dot position.

Parameters
antecedentThe left-hand side non-terminal.
consequentThe right-hand side of the production.
dotThe position of the dot.
epsilonThe EPSILON symbol.
eolThe end-of-line symbol.

Member Function Documentation

◆ AdvanceDot()

void Lr0Item::AdvanceDot ( )

Advances the dot one position to the right.

Here is the caller graph for this function:

◆ IsComplete()

bool Lr0Item::IsComplete ( ) const

Checks whether the dot has reached the end of the production.

Returns
true if the item is complete; false otherwise.
Here is the caller graph for this function:

◆ NextToDot()

std::string Lr0Item::NextToDot ( ) const

Returns the symbol immediately after the dot, or empty if the dot is at the end.

Returns
The symbol after the dot, or an empty string.
Here is the caller graph for this function:

◆ operator==()

bool Lr0Item::operator== ( const Lr0Item & other) const

Equality operator for comparing two LR(0) items.

Parameters
otherThe item to compare with.
Returns
true if both items are equal; false otherwise.
Here is the call graph for this function:

◆ PrintItem()

void Lr0Item::PrintItem ( ) const

Prints the LR(0) item to the standard output in a human-readable format.

◆ ToString()

std::string Lr0Item::ToString ( ) const

Converts the item to a string representation, including the dot position.

Returns
A string representation of the item.
Here is the caller graph for this function:

Member Data Documentation

◆ antecedent_

std::string Lr0Item::antecedent_

The non-terminal on the left-hand side of the production.

◆ consequent_

std::vector<std::string> Lr0Item::consequent_

The sequence of symbols on the right-hand side of the production.

◆ dot_

unsigned int Lr0Item::dot_ = 0

The position of the dot (·) in the production.

◆ eol_

std::string Lr0Item::eol_

The symbol representing end-of-line or end-of-input ($).

◆ epsilon_

std::string Lr0Item::epsilon_

The symbol representing the empty string (ε).


The documentation for this struct was generated from the following files: