本文整理汇总了Python中tree.Node.subtype方法的典型用法代码示例。如果您正苦于以下问题:Python Node.subtype方法的具体用法?Python Node.subtype怎么用?Python Node.subtype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Node
的用法示例。
在下文中一共展示了Node.subtype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: p_formalDecl
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import subtype [as 别名]
def p_formalDecl(p):
'''formalDecl : typeSpecifier IDENTIFIER
| typeSpecifier IDENTIFIER LBRACKET RBRACKET'''
varName = p[2]
varType = p[1].children[0].type
for item in global_scope:
if item[1] == varName:
if item[0] == varType:
print "Warning : Shadowing global variable %s near line %s.\n" % (varName, p.lexer.lineno)
match = False
for item in local_scope:
if item[1] == varName: #same identifier
if item[0] == varType: #same type
print "Syntax Error: Redefinition of local variable %s with type %s near line %s.\n" % \
(varName, varType, p.lexer.lineno)
else:
print "Syntax Error: Redefinition of local variable %s with type %s (originally type %s) near line %s.\n" % \
(varName, varType, item[0], p.lexer.lineno)
global syntaxerrs
syntaxerrs += 1
match = True
if not match:
if DEBUG:
print "New local variable %s %s declared near line %s.\n" % (varType, varName, p.lexer.lineno)
if len(p) > 3:
local_scope.append((varType, varName, "array"))
else:
local_scope.append((varType, varName))
p[0] = Node("formalDecl", p[1:])
if len(p) > 3:
p[0].subtype = 'array'
示例2: p_varDecl
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import subtype [as 别名]
def p_varDecl(p):
'''varDecl : typeSpecifier IDENTIFIER LBRACKET INT_LITERAL RBRACKET SEMICOLON
| typeSpecifier IDENTIFIER SEMICOLON'''
p[0] = Node("varDecl", p[1:])
if len(p) > 4:
p[0].subtype = "array"