当前位置: 首页>>代码示例>>Python>>正文


Python Stack.toString方法代码示例

本文整理汇总了Python中stack.Stack.toString方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.toString方法的具体用法?Python Stack.toString怎么用?Python Stack.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stack.Stack的用法示例。


在下文中一共展示了Stack.toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_file

# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import toString [as 别名]
	def parse_file(self, filename):
		scanner = Scanner_Class(filename)
		self.source_text = scanner.source()
		self.clear_messages()
		ret = 1
			
		stack = Stack()
		stack.push(1)
		current_token = scanner.next_token()
		
		while not stack.empty():
			# Skip comments
			if current_token.type == 8:
				current_token = scanner.next_token()
				continue		
			
			# Map all terminals to an integer
			token_number = self.translate(current_token)
			
			# Get head of the stack
			stacktop = stack.head.value;
			
			# Stats
			self.log("current_token: "+str(current_token.toString()), self.L_DEBUG)
			self.log("token_number: "+str(token_number), self.L_DEBUG)
			#self.log("stacktop: "+str(stacktop), self.L_DEBUG)
			#self.log("stack count: "+str(stack.count()), self.L_DEBUG)
			self.log("current stack: "+str(stack.toString()), self.L_DEBUG)

			# Non-terminal symbols
			if stacktop > 0:
				table_entry = self.next_table_entry(stacktop, abs(token_number))
				
				if table_entry == 98:
					self.log("Scan error: dropping "+current_token.value, self.L_ERROR)
					current_token = scanner.next_token()

				elif table_entry == 99:
					self.log("Pop Error: popping "+str(stack.head.value), self.L_ERROR)
					stack.pop()
				
				elif table_entry <= len(self.stack_pushes):
					self.log("Fire "+str(table_entry), 
						self.L_MATCH)
					stack.pop()
					
					for i in self.pushes(table_entry-1):
						if i != 0:
							stack.push(i)
				else:
					self.log("Error!", self.L_ERROR)
			
			# Terminals - Match and pop
			elif stacktop == token_number:
				self.log("Match and pop "+
					str(current_token.value), self.L_MATCH)
				stack.pop()
				current_token = scanner.next_token()
			
			# Terminals - No Match :(
			else:
				self.log("Error -- Not Accepted", self.L_MATCH)
				break;

			# Success message
			if stack.empty():
				self.log("Accept", self.L_MATCH)
				ret = 0
		
		# End While

		return ret
开发者ID:btelle,项目名称:cecs-444,代码行数:74,代码来源:parser_class.py


注:本文中的stack.Stack.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。