本文整理汇总了Python中Analyzer.Analyzer.genWrite方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.genWrite方法的具体用法?Python Analyzer.genWrite怎么用?Python Analyzer.genWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.genWrite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from Analyzer import Analyzer [as 别名]
# 或者: from Analyzer.Analyzer import genWrite [as 别名]
#.........这里部分代码省略.........
self.match('MP_WRITE')
self.match('MP_LPAREN')
self.writeParameter(None)
self.writeParameterTail()
self.match('MP_RPAREN')
elif self.lookahead is 'MP_WRITELN': # 111 WriteStatement -> writeln "(" WriteParameter WriteParameterTail ")"
self.match('MP_WRITELN')
self.match('MP_LPAREN')
self.writeParameter('writeln')
self.writeParameterTail('writeln')
self.match('MP_RPAREN')
else:
self.error("write, writeln")
def writeParameterTail(self, kind):
if self.lookahead is 'MP_COMMA': # 46 WriteParameterTail -> "," WriteParameter
self.match('MP_COMMA')
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')