Beispiel #1
0
	def augment(self):
		if self.is_augmented:
			return
		tmp = self.start_token
		#create a different token for new start state
		self.start_token = fact.create_unterminal(self.start_token.text + "__S")	
		self.expresses.append(e_fact.create_simple(self.start_token, [[tmp]]))
		self.is_augmented = True
Beispiel #2
0
 def augment(self):
     if self.is_augmented:
         return
     tmp = self.start_token
     #create a different token for new start state
     self.start_token = fact.create_unterminal(self.start_token.text +
                                               "__S")
     self.expresses.append(e_fact.create_simple(self.start_token, [[tmp]]))
     self.is_augmented = True
Beispiel #3
0
	def __init__(self, start, others):
		self.is_augmented = False
		self.is_non_left_rec = False
		self.is_expanded = False
		self.normalized_mode = None
		#undeterminal tokens
		self.ut_tokens = set()
		self.expresses = list()
		start = start.strip()
#		start = start.replace(' ', '')
#		others = [itm.replace(' ', '') for itm in others]
		others = [itm.strip() for itm in others]
		for itm in others:
			left, right = itm.split('->')
			left.strip()
			self.ut_tokens.add(fact.create_unterminal(left))
		left, right = start.split('->')
		left.strip()
		self.start_token = fact.create_unterminal(left)
		self.ut_tokens.add(self.start_token)

		others.append(start)

		#merge express whch uses the same left part
		left_right_dict = {}
		for itm in others:
			left, right = itm.split('->')
			right_text_list = right.split('|')
			right_text_list = \
				[itm.strip() for itm in right_text_list]
			if left not in left_right_dict:
				left_right_dict[left] = []
			left_right_dict[left].extend(right_text_list)

		for left, right_text_list in left_right_dict.iteritems():
			tokens_list = []
			for right_text in right_text_list:
				print right_text
				tokens = split_text_by_ut_tokens(right_text, self.ut_tokens)
				tokens_list.append(tokens)
				print tokens
			self.expresses.append( \
					e_fact.create_simple( \
						fact.create_unterminal(left), tokens_list))
Beispiel #4
0
    def __init__(self, start, others):
        self.is_augmented = False
        self.is_non_left_rec = False
        self.is_expanded = False
        self.normalized_mode = None
        #undeterminal tokens
        self.ut_tokens = set()
        self.expresses = list()
        start = start.strip()
        #		start = start.replace(' ', '')
        #		others = [itm.replace(' ', '') for itm in others]
        others = [itm.strip() for itm in others]
        for itm in others:
            left, right = itm.split('->')
            left.strip()
            self.ut_tokens.add(fact.create_unterminal(left))
        left, right = start.split('->')
        left.strip()
        self.start_token = fact.create_unterminal(left)
        self.ut_tokens.add(self.start_token)

        others.append(start)

        #merge express whch uses the same left part
        left_right_dict = {}
        for itm in others:
            left, right = itm.split('->')
            right_text_list = right.split('|')
            right_text_list = \
             [itm.strip() for itm in right_text_list]
            if left not in left_right_dict:
                left_right_dict[left] = []
            left_right_dict[left].extend(right_text_list)

        for left, right_text_list in left_right_dict.iteritems():
            tokens_list = []
            for right_text in right_text_list:
                print right_text
                tokens = split_text_by_ut_tokens(right_text, self.ut_tokens)
                tokens_list.append(tokens)
                print tokens
            self.expresses.append( \
              e_fact.create_simple( \
               fact.create_unterminal(left), tokens_list))