以下に示すエラーが表示される理由:
lhs_production = self.lhs()
名前エラー:
global name 'self' is not defined
以下は私が書いたコードです:
class Grammar:
def lhs(self):
arrow_position = line.find('->')
if arrow_position == -1:
raise ValueError, 'No arrow position %s is found in %s' % (arrow_position, self.line)
lhs_g = self.line[0:arrow_position].strip(' ')
print "The Lhs for the line is: ", lhs_g
check_space = re.search("\s", lhs, re.M)
if check_space:
raise ValueError, 'There is still some space in the lhs of the line'
return self.lhs_g
def parse_line(line):
if len(line) == 0:
raise ValueError, 'No Line is found %s' % (line)
lhs_production = self.lhs()
rhs_predicates_production = rhs_predicates()
pattern_list_production = pattern_list()
return(lhs_production, rhs_predicates(), patterns())