|
3 | 3 | from syntactes import Grammar, Token |
4 | 4 | from syntactes._action import Action |
5 | 5 | from syntactes._state import LR0State |
| 6 | +from syntactes.parsing_table import Entry |
6 | 7 |
|
7 | 8 | Row: TypeAlias = dict[Token, list[Action]] |
8 | 9 |
|
9 | 10 |
|
10 | | -class Entry: |
11 | | - """ |
12 | | - An entry of the parsing table. Holds the information of a transition from |
13 | | - a state to another state via a symbol. |
14 | | - """ |
15 | | - |
16 | | - def __init__(self, from_state: LR0State, token: Token, action: Action) -> None: |
17 | | - self.from_state = from_state |
18 | | - self.token = token |
19 | | - self.action = action |
20 | | - |
21 | | - def __repr__(self) -> str: |
22 | | - return f"<Entry: {str(self)}>" |
23 | | - |
24 | | - def __str__(self) -> str: |
25 | | - return f"{self.from_state.number}, {self.action}, {self.token}" |
26 | | - |
27 | | - def __hash__(self) -> int: |
28 | | - return hash((self.from_state, self.token, self.action)) |
29 | | - |
30 | | - def __eq__(self, other) -> bool: |
31 | | - if not isinstance(other, Entry): |
32 | | - return False |
33 | | - |
34 | | - return ( |
35 | | - self.from_state == other.from_state |
36 | | - and self.token == other.token |
37 | | - and self.action == other.action |
38 | | - ) |
39 | | - |
40 | | - |
41 | 11 | class LR0ParsingTable: |
42 | 12 | """ |
43 | 13 | Table that contains all the transitions from state to state with a symbol. |
@@ -94,6 +64,11 @@ def pretty_str(self) -> str: |
94 | 64 | """ |
95 | 65 | return self._rules_pretty_str() + "\n\n" + self._table_pretty_str() |
96 | 66 |
|
| 67 | + def conflicts(self) -> list: |
| 68 | + """ |
| 69 | + Retuns a list with all the conflicts in the parsing table. |
| 70 | + """ |
| 71 | + |
97 | 72 | def _rules_pretty_str(self) -> str: |
98 | 73 | rules = [str(i) + ". " + str(r) for i, r in enumerate(self._grammar.rules)] |
99 | 74 | rules_str = "\n".join(rules) |
|
0 commit comments