#!/usr/local/bin/python # -*- coding: utf-8 -*- import elementtree.ElementTree as ET import os, sys sys.path.append(os.getcwd().split('slps')[0] + 'slps/shared/python') import BGF if __name__ == "__main__": g = BGF.Grammar() g.addRoot('foo') p = BGF.Production() p.setNT('foo') t = BGF.Terminal() t.setName('bar') p.setExpr(BGF.Expression(t)) g.addProd(p) ET.ElementTree(g.getXml()).write('baby.bgf')
print 'Lexical nonterminal', nt, 'is disregarded' continue if nt in layouts: print 'Layout-related nonterminal', nt, 'is disregarded' continue for alt in grammar[nt]: while alt[0][0] == '@': print 'Disregarding annotation', alt[0] alt = alt[1:] if prevline: # dead code yet prevline.append('|') prevline.extend(alt) alt = prevline[:] prevline = [] prod = BGF.Production() prod.setNT(nt) while alt and alt[0] in ('bracket', 'left', 'right', 'non-assoc', 'lex', '(', ')'): print 'Skipped a modifier', alt[0], 'at', nt if alt[0] == 'lex': alt = [] else: alt = alt[1:] print 'left:', alt if not alt: continue while len(alt) > 0 and alt[-1] in (';', ''): alt = alt[:-1] while len(alt) > 0 and alt[0] == '': alt = alt[1:]