def p_field_access_id(p): 'field_access : ID' vname = p[1] v = current_vartable.find_in_scope(vname) if (v != None): # local variable in current scope p[0] = ast.VarExpr(v, p.lineno(1)) else: c = ast.lookup(ast.classtable, vname) if (c != None): # there is a class with this name p[0] = ast.ClassReferenceExpr(c, p.lineno(1)) else: # reference to a non-local var; assume field p[0] = ast.FieldAccessExpr(ast.ThisExpr(p.lineno(1)), vname, p.lineno(1))
def p_field_access_dot(p): 'field_access : primary DOT ID' p[0] = ast.FieldAccessExpr(p[1], p[3], p.lineno(2))