예제 #1
0
파일: converter.py 프로젝트: plusgood/lithp
	def make_func_declarations(self):
		"""Creates function declarations with parameter
		types and return types. Higher order functions
		are supported. Function declarations are also
		used as function signatures.

		Precondition: make_func_dict must have been called
		"""

		for name in self.func_dict:
			body = Lexer(self.func_dict[name]).get_tokens()
			i = body.index('\\')  + 1 #Start of parameters
			j = body.match_paren(i)
			param_tokens = body[i + 1: j] #Stuff inside parentheses
			#			print "param list:", param_tokens

			params = self.split_params(param_tokens)
			params = map(lambda n: n.split(':'), params)
			#params is now [[<name>,<type>],...]
			c_types = map(lambda n: self.convert_type(*n), params)
			#			print c_types

			return_type = ''
			#     +2 to skip over ")" and ":"
			if body[j+2] == '(': #Function returns another function
				#                                  +3 for [")","->","<type>"]
				for x in xrange(j+2, body.match_paren(j+2)+3):
					return_type += body[x]
			else: #Function returns a concrete type
				return_type = body[j+2] #+2 to skip over ")" and ":"

			func_type = self.convert_type(name, return_type)
			#			print "params", params
			#			print "c_types", c_types
			#while True:exec raw_input() in globals(), locals()
			self.cpp_declarations[name] = func_type + '(' + ', '.join(c_types) + ')'

		self.cpp_declarations['main'] = 'int main()' #actually this isn't used
예제 #2
0
def start(name):
    print('%s %s' % (name, '-'*(60-(len(name)+1))))
    return (name, time.time())

def stop(s):
    o = "%sms" % (int((time.time() - s[1]) * 1000))
    print('%s: %s %s' % (s[0], o, '-'*(60-(len(o)+len(s[0])+1))))

# start timer
s = start('Indexing')
sources = os.listdir('sources')
for file in sources:
    if file.endswith('.txt'):
        print("Indexing [%s/%s]" % (sources.index(file)+1, len(sources)+1))
        l.index('sources/'+file)
    else:
        print("Skipped non-source: %s" % (file))

# Stop timer
stop(s)

print("\n")
s = start('Statistics')
print("\tTokens: %s" % (len(l.tokens)))
print("\tDocuments: %s" % (len(l.documents)))

range = (0,5)

print("\n")
print("Finding %s-%s most seen tokens" % (range[0], range[1]))