mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-19 23:10:16 +08:00
Trying to reduce the amount of variables used in first sets
This commit is contained in:
@@ -71,10 +71,8 @@ class Grammar(object):
|
|||||||
# We only need to check the first dfa. All the following ones are not
|
# We only need to check the first dfa. All the following ones are not
|
||||||
# interesting to find first terminals.
|
# interesting to find first terminals.
|
||||||
state = dfas[0]
|
state = dfas[0]
|
||||||
totalset = set()
|
|
||||||
for transition, next_ in state.ilabel_to_plan.items():
|
for transition, next_ in state.ilabel_to_plan.items():
|
||||||
# It's a string. We have finally found a possible first token.
|
# It's a string. We have finally found a possible first token.
|
||||||
totalset.add(transition)
|
|
||||||
first_plans[transition] = [next_.next_dfa]
|
first_plans[transition] = [next_.next_dfa]
|
||||||
|
|
||||||
for nonterminal2, next_ in state.nonterminal_arcs.items():
|
for nonterminal2, next_ in state.nonterminal_arcs.items():
|
||||||
@@ -84,11 +82,9 @@ class Grammar(object):
|
|||||||
fset = self._first_terminals[nonterminal2]
|
fset = self._first_terminals[nonterminal2]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self._calculate_first_terminals(nonterminal2)
|
self._calculate_first_terminals(nonterminal2)
|
||||||
fset = self._first_terminals[nonterminal2]
|
|
||||||
else:
|
else:
|
||||||
if fset is None:
|
if fset is None:
|
||||||
raise ValueError("left recursion for rule %r" % nonterminal)
|
raise ValueError("left recursion for rule %r" % nonterminal)
|
||||||
totalset.update(fset)
|
|
||||||
|
|
||||||
for t, pushes in self._first_plans[nonterminal2].items():
|
for t, pushes in self._first_plans[nonterminal2].items():
|
||||||
check = first_plans.get(t)
|
check = first_plans.get(t)
|
||||||
@@ -100,4 +96,4 @@ class Grammar(object):
|
|||||||
)
|
)
|
||||||
first_plans[t] = [next_] + pushes
|
first_plans[t] = [next_] + pushes
|
||||||
|
|
||||||
self._first_terminals[nonterminal] = totalset
|
self._first_terminals[nonterminal] = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user