本文整理汇总了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