本文整理汇总了Python中Analyzer.Analyzer.genArithmetic方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.genArithmetic方法的具体用法?Python Analyzer.genArithmetic怎么用?Python Analyzer.genArithmetic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.genArithmetic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from Analyzer import Analyzer [as 别名]
# 或者: from Analyzer.Analyzer import genArithmetic [as 别名]
#.........这里部分代码省略.........
termTailRec = {}
if self.lookahead in ['MP_LPAREN', 'MP_IDENTIFIER', # 77 SimpleExpression -> OptionalSign Term TermTail
'MP_PLUS', 'MP_MINUS',
'MP_FLOAT_LIT', 'MP_FIXED_LIT', 'MP_STRING_LIT',
'MP_NOT', 'MP_INTEGER_LIT',
'MP_TRUE', 'MP_FALSE']:
sign = self.optionalSign()
termRec = self.term()
type = termRec['type']
if sign == "-":
if type == "Integer":
self.analyzer.genNeg()
elif type in ["Float", "Fixed"]:
self.analyzer.genNegf()
termTailRec = termRec
termTailRec = self.termTail(termTailRec)
expressionRec = termTailRec # This is what Rocky suggested
return expressionRec
else:
self.error("(, identifier, +, -, any literal value, not")
def termTail(self, termTailRec = {}):
# Semantic Records
addopRec = {}
termRec = {}
if self.lookahead in ['MP_PLUS', 'MP_MINUS', 'MP_OR']: # 78 TermTail -> AddingOperator Term TermTail
addopRec["lexeme"] = self.addingOperator()
termRec = self.term()
resultRec = self.analyzer.genArithmetic(termTailRec, addopRec, termRec)
self.termTail(resultRec)
termTailRec = resultRec
return termTailRec
elif self.lookahead in ['MP_SCOLON', 'MP_RPAREN', 'MP_END', # 79 TermTail -> lambda
'MP_COMMA', 'MP_THEN', 'MP_ELSE',
'MP_UNTIL', 'MP_DO', 'MP_TO',
'MP_DOWNTO', 'MP_EQUAL', 'MP_LTHAN',
'MP_GTHAN', 'MP_LEQUAL', 'MP_GEQUAL',
'MP_NEQUAL']:
return termTailRec
else:
self.error("+, -, or, ;, ), end, comma, then, else, until, do, to, downto, an equality operator")
def optionalSign(self):
if self.lookahead is 'MP_PLUS': # 80 OptionalSign -> "+"
self.match('MP_PLUS')
elif self.lookahead is 'MP_MINUS': # 81 OptionalSign -> "-"
return self.match('MP_MINUS')
elif self.lookahead in ['MP_LPAREN', 'MP_IDENTIFIER', # 82 OptionalSign -> lambda
'MP_NOT', 'MP_INTEGER_LIT',
'MP_FLOAT_LIT', 'MP_FIXED_LIT', 'MP_STRING_LIT',
'MP_TRUE', 'MP_FALSE']:
return
else:
self.error("+, -, (, identifier, +, -, any literal value, not")