Mercurial > lcfOS
comparison python/pyyacc.py @ 240:6259856841a0
Remove project
author | Windel Bouwman |
---|---|
date | Mon, 22 Jul 2013 22:37:33 +0200 |
parents | 494828a7adf1 |
children | e84047f29c78 |
comparison
equal
deleted
inserted
replaced
239:63bb40758066 | 240:6259856841a0 |
---|---|
1 """ | 1 """ |
2 Parser generator script | 2 Parser generator script |
3 """ | 3 """ |
4 | 4 |
5 import shelve | |
6 import hashlib | 5 import hashlib |
7 from ppci import Token | 6 from ppci import Token |
8 | 7 |
9 EPS = 'EPS' | 8 EPS = 'EPS' |
10 EOF = 'EOF' | 9 EOF = 'EOF' |
168 signature = m.hexdigest() | 167 signature = m.hexdigest() |
169 | 168 |
170 def genParser(self): | 169 def genParser(self): |
171 """ Generates a parser from the grammar (using a caching algorithm) """ | 170 """ Generates a parser from the grammar (using a caching algorithm) """ |
172 signature = self.getSignature() | 171 signature = self.getSignature() |
173 cache = shelve.open('__grammar_cache__.shelve') | 172 action_table, goto_table = self.doGenerate() |
174 # TODO: fix caching. | |
175 if ('signature1' in cache) and cache['signature'] == signature: | |
176 goto_table = cache['goto_table'] | |
177 action_table = cache['action_table'] | |
178 else: | |
179 action_table, goto_table = self.doGenerate() | |
180 cache['goto_table'] = goto_table | |
181 cache['action_table'] = action_table | |
182 cache['signature'] = signature | |
183 cache.close() | |
184 p = LRParser(action_table, goto_table, self.start_symbol) | 173 p = LRParser(action_table, goto_table, self.start_symbol) |
185 p.grammar = self | 174 p.grammar = self |
186 return p | 175 return p |
187 | 176 |
188 def doGenerate(self): | 177 def doGenerate(self): |