def internalizeBNF (self, stream): """BasilGrammarModelFactory.internalizeBnf """ from basil.parsing import bnf from basil.models.grammar.InternalizeBNF import BNFInternalizer if type(stream) == types.StringType: text = stream else: text = stream.read() grammarMap = bnf.get_prods(text) internalizer = BNFInternalizer(self) return internalizer(grammarMap)
def main (fileName = None): """main() Read a BNF input grammar from the given file name and print the XML representation of the corresponding Basil grammar model. """ text = None if None == fileName: text = sys.stdin.read() else: inFile = open(fileName) text = inFile.read() inFile.close() grammar = bnf.get_prods(text) grammarFactoryClass = BasilGrammarModel.getModelFactory() grammarFactory = grammarFactoryClass() internalizer = BNFInternalizer(grammarFactory) model = internalizer(grammar) print grammarFactory.externalizeXML(model)
def main (): text = open("test.bnf").read() rVal = bnf.get_prods(text) pprint.pprint(rVal)