SyntaxTutor
Educational app designed to help compiler students understand LL(1) and SLR(1) parsing algorithms.
 
Loading...
Searching...
No Matches
state.hpp
Go to the documentation of this file.
1#pragma once
2#include "lr0_item.hpp"
3#include <algorithm>
4#include <cstddef>
5#include <functional>
6#include <numeric>
7#include <unordered_set>
8
16struct state {
20 std::unordered_set<Lr0Item> items_;
21
25 unsigned int id_;
26
32 bool operator==(const state& other) const { return other.items_ == items_; }
33};
34
35namespace std {
36template <> struct hash<state> {
37 size_t operator()(const state& st) const {
38 size_t seed =
39 std::accumulate(st.items_.begin(), st.items_.end(), 0,
40 [](size_t acc, const Lr0Item& item) {
41 return acc ^ (std::hash<Lr0Item>()(item));
42 });
43 return seed;
44 }
45};
46} // namespace std
Represents a state in the LR(0) automaton.
Definition state.hpp:16
bool operator==(const state &other) const
Equality operator for comparing states based on their items.
Definition state.hpp:32
std::unordered_set< Lr0Item > items_
The set of LR(0) items that make up this state.
Definition state.hpp:20
unsigned int id_
Unique identifier of the state.
Definition state.hpp:25