parameters: (lst)
docstring: Evaluate an expression recursively, for example::
  
  		1+1+1 -> 2+1 -> 3
  
  	:param lst: list of tokens
  	:type lst: list of tuple(token, value)
  	:return: the value and the remaining tokens
  	:rtype: value, list
docstring_summary: Evaluate an expression recursively, for example::
docstring_tokens: Evaluate an expression recursively for example ::
function: def get_term(lst):
  	"""
  	Evaluate an expression recursively, for example::
  
  		1+1+1 -> 2+1 -> 3
  
  	:param lst: list of tokens
  	:type lst: list of tuple(token, value)
  	:return: the value and the remaining tokens
  	:rtype: value, list
  	"""
  
  	if not lst:
  		raise PreprocError('empty list for get_term')
  	num, lst = get_num(lst)
  	if not lst:
  		return (num, [])
  	(p, v) = lst[0]
  	if p == OP:
  		if v == ',':
  			# skip
  			return get_term(lst[1:])
  		elif v == '?':
  			count_par = 0
  			i = 1
  			while i < len(lst):
  				(p, v) = lst[i]
  
  				if p == OP:
  					if v == ')':
  						count_par -= 1
  					elif v == '(':
  						count_par += 1
  					elif v == ':':
  						if count_par == 0:
  							break
  				i += 1
  			else:
  				raise PreprocError('rparen expected %r' % lst)
  
  			if int(num):
  				return get_term(lst[1:i])
  			else:
  				return get_term(lst[i+1:])
  
  		else:
  			num2, lst = get_num(lst[1:])
  
  			if not lst:
  				# no more tokens to process
  				num2 = reduce_nums(num, num2, v)
  				return get_term([(NUM, num2)] + lst)
  
  			# operator precedence
  			p2, v2 = lst[0]
  			if p2 != OP:
  				raise PreprocError('op expected %r' % lst)
  
  			if prec[v2] >= prec[v]:
  				num2 = reduce_nums(num, num2, v)
  				return get_term([(NUM, num2)] + lst)
  			else:
  				num3, lst = get_num(lst[1:])
  				num3 = reduce_nums(num2, num3, v2)
  				return get_term([(NUM, num), (p, v), (NUM, num3)] + lst)
  
  
  	raise PreprocError('cannot reduce %r' % lst)
function_tokens: def get_term ( lst ) : if not lst : raise PreprocError ( 'empty list for get_term' ) num , lst = get_num ( lst ) if not lst : return ( num , [ ] ) ( p , v ) = lst [ 0 ] if p == OP : if v == ',' : # skip return get_term ( lst [ 1 : ] ) elif v == '?' : count_par = 0 i = 1 while i < len ( lst ) : ( p , v ) = lst [ i ] if p == OP : if v == ')' : count_par -= 1 elif v == '(' : count_par += 1 elif v == ':' : if count_par == 0 : break i += 1 else : raise PreprocError ( 'rparen expected %r' % lst ) if int ( num ) : return get_term ( lst [ 1 : i ] ) else : return get_term ( lst [ i + 1 : ] ) else : num2 , lst = get_num ( lst [ 1 : ] ) if not lst : # no more tokens to process num2 = reduce_nums ( num , num2 , v ) return get_term ( [ ( NUM , num2 ) ] + lst ) # operator precedence p2 , v2 = lst [ 0 ] if p2 != OP : raise PreprocError ( 'op expected %r' % lst ) if prec [ v2 ] >= prec [ v ] : num2 = reduce_nums ( num , num2 , v ) return get_term ( [ ( NUM , num2 ) ] + lst ) else : num3 , lst = get_num ( lst [ 1 : ] ) num3 = reduce_nums ( num2 , num3 , v2 ) return get_term ( [ ( NUM , num ) , ( p , v ) , ( NUM , num3 ) ] + lst ) raise PreprocError ( 'cannot reduce %r' % lst )