Example #1
0
 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)
Example #2
0
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)
Example #3
0
def main ():
    text = open("test.bnf").read()
    rVal = bnf.get_prods(text)
    pprint.pprint(rVal)