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


Python Analyzer.genAssign方法代码示例

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


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

示例1: Parser

# 需要导入模块: from Analyzer import Analyzer [as 别名]
# 或者: from Analyzer.Analyzer import genAssign [as 别名]

#.........这里部分代码省略.........
            self.writeParameter(kind)
            self.writeParameterTail(kind)
        elif self.lookahead is 'MP_RPAREN':  # 47 WriteParameterTail -> lambda
            return
        else:
            self.error("comma, )")
    
    
    def writeParameter(self, kind):
        if self.lookahead in ['MP_LPAREN', 'MP_IDENTIFIER',  # 48 WriteParameter -> OrdinalExpression
                              'MP_PLUS', 'MP_MINUS',
                              'MP_FLOAT_LIT', 'MP_FIXED_LIT', 'MP_STRING_LIT',
                              'MP_NOT', 'MP_INTEGER_LIT',
                              'MP_TRUE', 'MP_FALSE']:
            self.ordinalExpression()
            self.analyzer.genWrite()
            if kind == 'writeln':
                self.analyzer.genWriteln()
        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")
    
    
   
   
开发者ID:agroves333,项目名称:compiler,代码行数:66,代码来源:Parser.py


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