# get to ply lib_path = os.path.join('../lib/ply-3.4') sys.path.append(lib_path) # import lexer class from svelLex import SvelLexer # import parser import svelYacc # get and build lexer svel = SvelLexer() svel.build() # get parser parser = svelYacc.getParser() # provide some data data = ''' //tests Hello.java boolean helloWorldTest() { file helloFile = "../Hello.java"; funct helloMain = {__main__, (j_String[]), helloFile}; input in = (); output out = "Hello World!"; return helloMain.assert(in, out); } ''' #main() { # if(helloWorldTest()) {
def setUp(self): self.lex = SvelLexer() self.lex.build() self.lexer = self.lex.get_lexer() self.parser = svelYacc.getParser()
if(os.path.isfile(output_filename)): sys.exit("Error: Refusing to overwrite " + output_filename + "\nPlease either delete it or rename your source file") # try to open source code try: source_code = open(input_file).read() except IOERROR, e: sys.exit(e) # get and build lexer; errorlog=lex.NullLogger() removes PLY warnings svel = SvelLexer() svel.build(errorlog=lex.NullLogger()) # get parser; errorlog=yacc.NullLogger() removes PLY warnings parser = svelYacc.getParser(errorlog=yacc.NullLogger()) # parse the data into an abstract syntax tree ast = parser.parse(source_code, lexer=svel.get_lexer()) # walk the tree and get the compiled code if verbose == None: compiled_code, errors = SvelTraverse(ast).get_code_and_errors() else: print ast compiled_code, errors = SvelTraverse(ast, verbose=True).get_code_and_errors() # if arg3 = -d # compiled_code = SvelTraverse(ast, debug=true).get_code() # if no errors thrown during compilation, go ahead and write compiled code to file if errors == False: