Skip to content
Browse files

now using __import__ to make a portable main function, just name a le…

…xer and we can import it yourclass.scanner is preferable
  • Loading branch information...
1 parent 28df4e9 commit 75782c27e566a80c9ccf83943e03d15496f52c09 @dacresni committed May 30, 2010
Showing with 11 additions and 8 deletions.
  1. +1 −1 bnflexar.py
  2. +1 −1 cyk.py
  3. +2 −2 grammar.py
  4. +6 −3 main.py
  5. +1 −1 viz.py
View
2 bnflexar.py
@@ -1,7 +1,7 @@
from lexar import Token, Scanner
# we can impliment the grammar parser inside the scanner lexer
# 3 out of 4 methods are going to be overloaded by the child does the nested class inheret?
-class BnfLexar(Scanner): #should I subclass this or not
+class Lexer(Scanner): #should I subclass this or not
def rule(self,match):
result=match.string.strip('\n',)
self.tokenStream.append(Token("nonterminal",result) )
View
2 cyk.py
@@ -2,7 +2,7 @@
import sys
from lexar import Token
from grammar import Grammar
-from bnflexar import BnfLexar
+from bnflexar import Lexer
class CYKChart(object):
def __init__(self):
View
4 grammar.py
@@ -1,5 +1,5 @@
from lexar import Token
-from bnflexar import BnfLexar
+from bnflexar import Lexer
class Grammar(object):
"""grammar is simply a list of rules with at least one start symbole"""
@@ -21,7 +21,7 @@ def __findbreaks( stack ,i, left):# we need to text this function
newrule.rightHand=stack[i:]
self.rules.append(newrule)
- lex=BnfLexar()
+ lex=Lexer()
if verbose:
lex.setVerbose()
lex.scanFile(source)
View
9 main.py
@@ -2,15 +2,17 @@
from cyk import CYKChart
from viz import genDot
from os import system
-def main(lexarname, gramarspec, inputfile, outputfile=None):
+def main(args**):
+ lexarname, gramarspec, inputfile, outputfile=None
if outputfile == None:
outputfile = inputfile
G = Grammar()
source = open(gramarspec,'r')
G.generate(source)
G.bnf2cnf()
print "grammer==",G
- lexer=__import__(lexarname)
+ lexerclass=__import__(lexarname)
+ lexer=lexerclass.Lexer()
lexer.scan(inputfile)
S=lexer.getStream()
print "stream ===",S
@@ -19,9 +21,10 @@ def main(lexarname, gramarspec, inputfile, outputfile=None):
print C
print C.graph
genDot(C,outputfile)
- system("dot -Tjpg %s -o %s "%(outputfile, outputfile))
+ system("dot -Tjpg %s -o %s "%(outputfile, outputfile))
print "%s ted"%(outputfile)
if __name__ == '__main__':
import sys
main(sys.argv)
+
View
2 viz.py
@@ -1,4 +1,4 @@
-from treecyk import CYKChart
+from cyk import CYKChart
class genDot(object):
def genTree(self,G,here,visited):

0 comments on commit 75782c2

Please sign in to comment.
Something went wrong with that request. Please try again.