def GrammarBuild(): import kjParseBuild idl = kjParseBuild.NullCGrammar() idl.LexD = myLexDictionary() #idl.SetCaseSensitivity(0) # grammar is not case sensitive for keywords DeclareTerminals(idl) idl.Keywords(keywords) idl.punct(punctuations) idl.Nonterms(nonterms) #idl.comments([LISPCOMMENTREGEX]) idl.Declarerules(idlgramstring) print "now compiling" idl.Compile() return idl
def BuildSQLG(): import kjParseBuild SQLG = kjParseBuild.NullCGrammar() SQLG.SetCaseSensitivity(0) SQLG.Keywords(SELECTKEYWORDS) SQLG.Nonterms(SELECTNONTERMS) # no comments yet SQLG.Declarerules(SELECTRULES) print "building" SQLG.Compile() print "marshaling" outfile = open(MARSHALFILE, "w") SQLG.MarshalDump(outfile) outfile.close() return SQLG
def Buildrelalg(filename=MARSHALFILE): import kjParseBuild SQLG = kjParseBuild.NullCGrammar() #SQLG.SetCaseSensitivity(0) DeclareTerminals(SQLG) SQLG.Keywords(keywords) SQLG.punct(puncts) SQLG.Nonterms(nonterms) # should add comments SQLG.comments([RACOMMENTREGEX]) SQLG.Declarerules(relalg_rules) print "working..." SQLG.Compile() filename = INSTALLDIR + "/" + filename print "dumping to", filename outfile = open(filename, "wb") SQLG.MarshalDump(outfile) outfile.close() return SQLG
def GrammarBuild(): import kjParseBuild # initialize a Null compilable grammar to define LispG = kjParseBuild.NullCGrammar() # declare terminals for the grammar DeclareTerminals(LispG) # declare the keywords for the grammar # defun is not used, included here for demo purposes only LispG.Keywords("setq defun") # Declare punctuations # dot is not used here LispG.punct("().") # Declare Nonterms LispG.Nonterms("Value ListTail") # Declare comment forms LispG.comments([LISPCOMMENTREGEX]) # Declare rules LispG.Declarerules(GRAMMARSTRING) # Compile the grammar LispG.Compile() # Write the grammar to a file except for # the function bindings (which must be rebound) outfile = open(COMPILEDFILENAME, "w") LispG.Reconstruct("LispG", outfile, "GRAMMAR") outfile.close() # for debugging purposes only, bind the rules # in the generated grammar BindRules(LispG) # return the generated Grammar return LispG
def GrammarBuild(): global pyg import kjParseBuild pyg = kjParseBuild.NullCGrammar() pyg.DoParse = hackDoParse # override lexical dict here pyg.LexD = pylexdict() DeclareTerminals(pyg) pyg.Keywords(keywords) pyg.punct("~!#%^&*()-+=|{}'`<>,.;:/[]{}") pyg.Nonterms(nonterms) pyg.Declarerules(pyrules) print buildinfo print "compiling... this may take a while..." pyg.Compile() print "dumping" outfile = open(marshalfilename, "wb") pyg.MarshalDump(outfile) outfile.close() print "self testing the grammar" test(pyg) print "\n\ndone with regeneration" return pyg
def BuildSQL(filename=MARSHALFILE): import kjParseBuild from sqlgram import sqlrules, nonterms, keywords, puncts SQLG = kjParseBuild.NullCGrammar() SQLG.SetCaseSensitivity(0) DeclareTerminals(SQLG) SQLG.Keywords(keywords) SQLG.punct(puncts) SQLG.Nonterms(nonterms) SQLG.comments([commentre]) # should add comments SQLG.Declarerules(sqlrules) print "working..." SQLG.Compile() print "testing" from sqlgtest import test for x in test: print SQLG.DoParse1(x) print "dumping to", filename outfile = open(filename, "wb") SQLG.MarshalDump(outfile) outfile.close() return SQLG
def GrammarBuild(): import kjParseBuild LispG = kjParseBuild.NullCGrammar() LispG.SetCaseSensitivity(0) # grammar is not case sensitive for keywords DeclareTerminals(LispG) LispG.Keywords("setq print") LispG.punct("().") LispG.Nonterms("Value ListTail") LispG.comments([LISPCOMMENTREGEX]) LispG.Declarerules(GRAMMARSTRING) LispG.Compile() print "dumping as python to " + COMPILEDFILENAME outfile = open(COMPILEDFILENAME, "w") LispG.Reconstruct("LispG", outfile, "GRAMMAR") outfile.close() print "dumping as binary to " + MARSHALLEDFILENAME outfile = open(MARSHALLEDFILENAME, "w") LispG.MarshalDump(outfile) outfile.close() BindRules(LispG) return LispG
def GrammarBuild(self, load=1): if load and os.path.exists(MARSHALLEDFILENAME): import kjParser infile = open(MARSHALLEDFILENAME, 'r') self._grammar = kjParser.UnMarshalGram(infile) infile.close() self.DeclareTerminals() else: import kjParseBuild self._grammar = kjParseBuild.NullCGrammar() self._grammar.SetCaseSensitivity(0) self._grammar.punct('=<>+*') self._grammar.Nonterms("Equation Expression Operator ") self._grammar.Nonterms("Term Variable Plus Times Constant ") self.DeclareTerminals() self._grammar.Declarerules(GRAMMARSTRING) self._grammar.Compile() outfile = open(MARSHALLEDFILENAME, "w") self._grammar.MarshalDump(outfile) outfile.close() self.BindRules()