8 args = argparse.ArgumentParser()
9 args.add_argument(
'input')
11 args = args.parse_args()
14 separators_reached = 0
16 symbol = re.compile(
'[_A-Za-z]+:')
17 first_production = re.compile(
'([^|][^{]*)({.*)?')
25 for line
in open(args.input):
26 if line.strip() ==
'%%':
27 separators_reached += 1
30 if separators_reached != 1:
35 if symbol.match(line):
37 symbols.append((current_symbol, productions))
40 current_symbol = line[:-1]
44 in_code =
'}' not in line
47 match = first_production.match(line)
49 (variables, code) = match.groups()
51 variables = [ v
for v
in variables.split()
if v !=
';' ]
52 if len(variables) > 0:
53 assert len(productions) == 0
54 productions = [ variables ]
56 print(
'%s -> %s' % (current_symbol, productions))
58 if code
and '}' not in code: