#!/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')
cx += 1 continue if alt[cx] == 'lex': cx += 1 continue if alt[cx][0].islower(): typ = sym sym = BGF.Selectable() sym.setExpr(typ) sym.setName(alt[cx]) cx += 1 continue if alt[cx][0] == '"': if sym: seq.add(sym) sym = BGF.Terminal() term = alt[cx][1:-1].replace('\\\\', '\\').replace( '\\>', '>').replace('\\<', '<').replace('\\\'', '\'').replace('\\"', '"') sym.setName(term) cx += 1 print 'Found a terminal', term continue if alt[cx][0] == '[' or alt[cx][:2] == '![': # not quite correct #print alt if sym: seq.add(sym) if alt[cx][-1] == ']':