SyntaxTutor
Educational app designed to help compiler students understand LL(1) and SLR(1) parsing algorithms.
 
Loading...
Searching...
No Matches
lr0_item.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5
14struct Lr0Item {
18 std::string antecedent_;
19
23 std::vector<std::string> consequent_;
24
28 std::string epsilon_;
29
33 std::string eol_;
34
38 unsigned int dot_ = 0;
39
47 Lr0Item(std::string antecedent, std::vector<std::string> consequent,
48 std::string epsilon, std::string eol);
49
58 Lr0Item(std::string antecedent, std::vector<std::string> consequent,
59 unsigned int dot, std::string epsilon, std::string eol);
60
65 std::string NextToDot() const;
66
70 void PrintItem() const;
71
76 std::string ToString() const;
77
81 void AdvanceDot();
82
87 bool IsComplete() const;
88
94 bool operator==(const Lr0Item& other) const;
95};
96
97namespace std {
98template <> struct hash<Lr0Item> {
99 size_t operator()(const Lr0Item& item) const;
100};
101} // namespace std
Represents an LR(0) item used in LR automata construction.
Definition lr0_item.hpp:14
std::string antecedent_
The non-terminal on the left-hand side of the production.
Definition lr0_item.hpp:18
unsigned int dot_
The position of the dot (·) in the production.
Definition lr0_item.hpp:38
bool operator==(const Lr0Item &other) const
Equality operator for comparing two LR(0) items.
Definition lr0_item.cpp:85
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.
Definition lr0_item.cpp:11
std::string epsilon_
The symbol representing the empty string (ε).
Definition lr0_item.hpp:28
std::string NextToDot() const
Returns the symbol immediately after the dot, or empty if the dot is at the end.
Definition lr0_item.cpp:34
bool IsComplete() const
Checks whether the dot has reached the end of the production.
Definition lr0_item.cpp:47
std::vector< std::string > consequent_
The sequence of symbols on the right-hand side of the production.
Definition lr0_item.hpp:23
void PrintItem() const
Prints the LR(0) item to the standard output in a human-readable format.
Definition lr0_item.cpp:54
void AdvanceDot()
Advances the dot one position to the right.
Definition lr0_item.cpp:41
std::string eol_
The symbol representing end-of-line or end-of-input ($).
Definition lr0_item.hpp:33
std::string ToString() const
Converts the item to a string representation, including the dot position.
Definition lr0_item.cpp:68