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


Python Analyzer.genBranchFalse方法代码示例

本文整理汇总了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)
开发者ID:agroves333,项目名称:compiler,代码行数:70,代码来源:Parser.py


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