[Tutor] script still too slow
antonmuhin at rambler.ru
antonmuhin at rambler.ru" <antonmuhin@rambler.ru
Thu Feb 27 13:49:59 2003
Hello, Paul!
This version is approximately 30% faster than yours (token = changed
to return, otherwise it doesn't seem to make sense). Cannot suggest
anything better :(
def evaluate_token1(s,t):
"""Evaluate ts. Return a value if the t is not a
control word. Otherwise, pass t onto another method
for further evaluation."""
if t == '{':
s.bracket_count = s.bracket_count + 1
return 'ob<nu<nu<nu<' + str(s.bracket_count) + '<{\n'
elif t == '}':
s.bracket_count = s.bracket_count - 1
return 'cb<nu<nu<nu<<' + str(s.bracket_count + 1) + 'd}\n'
elif t == r'\{':
return 'tx<es<nu<nu<nu<{\n'
elif t == r'\}':
return 'tx<es<nu<nu<nu<}\n'
elif t == r'\\': # double or escaped \
return 'tx<es<nu<nu<nu<\\\n'
elif t[0] != '\\': # single \
return 'tx<nu<nu<nu<nu<' + t + '\n'
else:
return s.evaluate_cw(t)
--
Best regards,
anton mailto:antonmuhin@rambler.ru