Mercurial > lcfOS
diff python/pyyacc.py @ 395:3b0c495e3008
Speed improvements
author | Windel Bouwman |
---|---|
date | Fri, 23 May 2014 14:28:03 +0200 |
parents | 173e20a47fda |
children |
line wrap: on
line diff
--- a/python/pyyacc.py Thu May 22 08:14:12 2014 +0200 +++ b/python/pyyacc.py Fri May 23 14:28:03 2014 +0200 @@ -302,37 +302,28 @@ assert self.dotpos <= len(self.production.symbols) self.look_ahead = look_ahead self._is_shift = self.dotpos < len(self.production.symbols) - - def getdata(self): - """ Gets the members as a tuple """ - return (self.production, self.dotpos, self.look_ahead) + self.IsShift = self._is_shift + if self.IsShift: + self.Next = self.production.symbols[self.dotpos] + self._data = (self.production, self.dotpos, self.look_ahead) + self._hash = self._data.__hash__() def __eq__(self, other): if type(other) is type(self): - return self.getdata() == other.getdata() + return self._data == other._data return False def __hash__(self): - return self.getdata().__hash__() + return self._hash @property def IsReduce(self): """ Check if this item has the dot at the end """ return not self._is_shift - @property - def IsShift(self): - """ Check if this item is a shift item, i.e. the dot can proceed """ - return self._is_shift - - @property - def Next(self): - """ Returns the symbol after the dot """ - return self.production.symbols[self.dotpos] - def can_shift_over(self, symbol): """ Determines if this item can shift over the given symbol """ - return self.IsShift and self.Next == symbol + return self._is_shift and self.Next == symbol def shifted(self): """ Creates a new item that is shifted one position """ @@ -356,7 +347,9 @@ class LRParser: - """ LR parser automata """ + """ LR parser automata. This class takes goto and action table + and can then process a sequence of tokens. + """ def __init__(self, action_table, goto_table, start_symbol): self.action_table = action_table self.goto_table = goto_table