Lmnl.SimpleParse.py
From LMNLWiki
(back to LMNL Experiment page LMNL Parser Experiment)
# Simple Python script to parse an LMNL text, in a file called 'example-lmnl-text.txt'
# using a SimpleParse parser and an LMNL EBNF grammar in the file 'lmnl.def'
# SimpleParse must be installed to run this script.
# It can be obtained from http://simpleparse.sourceforge.net/
# Once downloaded, run "python setup.py install" in its folder,
# and it will install itself into your python environment.
# Run this script from the command line using "python lmnl.SimpleParse.py"
from sys import stdin, stdout, stderr
from simpleparse.parser import Parser
import os, sys
from pprint import pprint
def simpleParseLMNLDocument():
lmnlDocument = open('example-lmnl-text.txt').read()
parser = Parser(open('lmnl.def').read(), 'LMNLDocument' )
taglist = parser.parse(lmnlDocument)
pprint(taglist,stderr)
# If we're running from the command line, parse the document:
if __name__ == '__main__':
simpleParseLMNLDocument()
