本文整理汇总了Python中Analyzer.Analyzer.genBranchFalse方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.genBranchFalse方法的具体用法?Python Analyzer.genBranchFalse怎么用?Python Analyzer.genBranchFalse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.genBranchFalse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from Analyzer import Analyzer [as 别名]
# 或者: from Analyzer.Analyzer import genBranchFalse [as 别名]
#.........这里部分代码省略.........
else:
self.error("(, identifier, +, -, any literal value, not")
def assignmentStatement(self):
# semantic records
expressionRec = {}
identRec = {}
if self.lookahead is 'MP_IDENTIFIER': # 49 AssignmentStatement -> VariableIdentifier ":=" Expression OR
id = self.variableIdentifier()
identRec = self.analyzer.processId(id)
self.match('MP_ASSIGN')
expressionRec = self.expression()
self.analyzer.genAssign(identRec, expressionRec)
# This doesn't change parsing functionality
# elif self.lookahead is 'MP_IDENTIFIER': # 50 AssignmentStatement -> FunctionIdentifier ":=" Expression
# self.functionIdentifier()
# self.match('MP_ASSIGN')
# self.expression()
else:
self.error("identifier")
def ifStatement(self):
if self.lookahead is 'MP_IF': # 51 IfStatement -> "if" BooleanExpression "then" Statement OptionalElsePart
self.match('MP_IF')
self.booleanExpression()
self.analyzer.incrementLabel()
false_label_number = self.analyzer.getLabel()
self.analyzer.genBranchFalse(false_label_number) # Generate branch to Optional Else if False
self.match('MP_THEN')
self.statement()
self.analyzer.incrementLabel()
skip_else_label_number = self.analyzer.getLabel()
self.analyzer.genBranch(skip_else_label_number) # Generate Branch past optional else if was inside of 'then'
self.analyzer.genLabel(false_label_number)
self.optionalElsePart()
self.analyzer.genLabel(skip_else_label_number)
else:
self.error("if")
def optionalElsePart(self):
#TODO: Table says else is ambiguous? haven't looked at it yet
if self.lookahead is 'MP_ELSE': # 52 OptionalElsePart -> "else" Statement
self.match('MP_ELSE')
self.statement()
elif self.lookahead in ['MP_SCOLON', 'MP_END', 'MP_UNTIL']: # 53 OptionalElsePart -> lambda
return
else:
self.error("else, ;, end, until")
def repeatStatement(self):
if self.lookahead is 'MP_REPEAT': # 54 RepeatStatement -> "repeat" StatementSequence "until" BooleanExpression
self.match('MP_REPEAT')
self.analyzer.incrementLabel()
starting_label = self.analyzer.getLabel()
self.analyzer.genLabel(starting_label)