Пример #1
0
def ezhil_file_parse_eval( file_input,redirectop,debug):
    """ runs as a separate process with own memory space, pid etc, with @file_input, @debug values,
        the output is written out into a file named, "ezhil_$PID.out". Calling process is responsible to
        cleanup the cruft. Note file_input can be a string version of a program to be evaluated if it is
        enclosed properly in a list format
    """
    if ( redirectop ):
        sys.stdout = codecs.open(EzhilRedirectOutput.pidFileName(current_process().pid),"w","utf-8")
        sys.stderr = sys.stdout;
    lexer = EzhilLex(file_input,debug)
    if ( debug ): lexer.dump_tokens()
    parse_eval = EzhilInterpreter( lexer, debug )
    web_ast = parse_eval.parse()
    if( debug ):
        print(unicode(web_ast))
    if ( debug ):  print(u"*"*60);  print(unicode(parse_eval))
    exit_code = 0
    try:
        env = parse_eval.evaluate()
    except Exception as e:
        exit_code = -1
        print(unicode(e))
        if ( debug ):
            traceback.print_tb(sys.exc_info()[2])
            raise e
    finally:
        if ( redirectop ):
            # cerrar - முடி
            sys.stdout.flush()
            sys.stderr.flush()
            #sys.stdout.close()
    return exit_code
Пример #2
0
def ezhil_file_parse_eval(file_input, redirectop, debug):
    """ runs as a separate process with own memory space, pid etc, with @file_input, @debug values,
        the output is written out into a file named, "ezhil_$PID.out". Calling process is responsible to
        cleanup the cruft. Note file_input can be a string version of a program to be evaluated if it is
        enclosed properly in a list format
    """
    if (redirectop):
        sys.stdout = open(
            EzhilRedirectOutput.pidFileName(current_process().pid), "w")
        sys.stderr = sys.stdout
    lexer = EzhilLex(file_input, debug)
    if (debug): lexer.dump_tokens()
    parse_eval = EzhilInterpreter(lexer, debug)
    web_ast = parse_eval.parse()
    if (debug):
        print(web_ast)
    if (debug):
        print("*" * 60)
        print(str(parse_eval))
    exit_code = 0
    try:
        env = parse_eval.evaluate()
    except Exception as e:
        exit_code = -1
        print str(e)
    finally:
        if (redirectop):
            # cerrar - முடி
            sys.stdout.flush()
            sys.stderr.flush()
            sys.stdout.close()
    return exit_code
Пример #3
0
def ezhil_eval(*args):
    global global_interpreter
    env = global_interpreter.env
    debug = global_interpreter.debug
    
    lexer = EzhilLex(fname=[args[0]])
    if ( debug ): lexer.dump_tokens()
    parse_eval = Interpreter( lexer, debug, global_interpreter.SAFE_MODE,False,env=global_interpreter.env)
    try:
        web_ast = parse_eval.parse()
        parse_eval.call_stack.append("__tmptop__")
        return parse_eval.evaluate()
    except Exception as e:
        raise e
    return
Пример #4
0
 def __init__(self,file_input,debug=False,redirectop=False):        
     EzhilRedirectOutput.__init__(self,redirectop)
     
     try:
         lexer = EzhilLex(file_input,debug)
         if ( debug ): lexer.dump_tokens()
         parse_eval = EzhilInterpreter( lexer, debug )
         parse_eval.parse()
         if ( debug ):  print("*"*60);  print(str(parse_eval))
         env = parse_eval.evaluate()
     except Exception as e:            
         print("exception ",str(e))
         raise e
     finally:
         if ( redirectop ):
             self.tmpf.close()
             sys.stdout = self.old_stdout
             sys.stderr = self.old_stderr
Пример #5
0
def ezhil_file_parse_eval( file_input,redirectop,debug,encoding="utf-8",doprofile=False,safe_mode=False):
    """ runs as a separate process with own memory space, pid etc, with @file_input, @debug values,
        the output is written out into a file named, "ezhil_$PID.out". Calling process is responsible to
        cleanup the cruft. Note file_input can be a string version of a program to be evaluated if it is
        enclosed properly in a list format.
        @doprofile : automatically attach profile("begin") to entry of a file and calls profile("results") to end of file.
    """
    if ( redirectop ):
        print(u"redirect mode @ ezhil file parse eval")
        tmpfilename = EzhilRedirectOutput.pidFileName(current_process().pid)
        sys.stdout = codecs.open(tmpfilename,"w","utf-8")
        sys.stderr = sys.stdout;
    lexer = EzhilLex(file_input,debug,encoding=encoding)
    if ( debug ): 
        print(u"####### dump tokens ########")
        lexer.dump_tokens()
        print(u"##########################")
    parse_eval = EzhilInterpreter( lexer=lexer, debug=debug, safe_mode=safe_mode )
    web_ast = parse_eval.parse()
    if doprofile:
        # add profile at entry and exit
        TransformEntryExitProfile(interpreter=parse_eval,debug=debug)
    
    if( debug ):
        print(unicode(web_ast))
    if ( debug ):  print(u"*"*60);  print(unicode(parse_eval))
    exit_code = 0
    try:
        env = parse_eval.evaluate()
    except Exception as e:
        #print(u"xxception raised... %s"%str(redirectop))
        exit_code = 255
        print(unicode(e))
        if ( debug ):
            traceback.print_tb(sys.exc_info()[2])
        raise e
    finally:
        if ( redirectop ):
            # cerrar - முடி
            sys.stdout.flush()
            sys.stderr.flush()
            #sys.stdout.close()
    #print(u"returning back...")
    return exit_code
Пример #6
0
def ezhil_execute(*args):
    global global_interpreter
    global_interpreter.reset()
    env = global_interpreter.env
    debug = global_interpreter.debug
    
    if len(args) < 1:
        raise RuntimeException(u"ezhil_execute: missing filename argument")
    if (debug): print(args[0])
    lexer = EzhilLex(fname=args[0])
    if ( debug ): lexer.dump_tokens()
    try:
        parse_eval = Interpreter( lexer, debug, global_interpreter.SAFE_MODE,False,env=global_interpreter.env)    
        web_ast = parse_eval.parse()
        parse_eval.call_stack.append("__evaluate__")
        return parse_eval.evaluate()
    except Exception as e:
        traceback.print_stack()
        raise e
    return
Пример #7
0
 def __init__(self, src_file):
     """ @styler uses a Wiki/HTML/LaTeX output formatter, with a color theme 
     specificied by @theme to render the text into the appropriate format"""
     Visitor.__init__(self)
     self.styler = WikiStyle.wrap_msg
     self.theme = XsyTheme()
     self.lexer = EzhilLex(src_file)
     #print self.lexer.comments.keys()
     self.output = []
     self.line = 1  #current line
     self.NEWLINE = "<BR />\n"
Пример #8
0
    def __init__(self, file_input, debug=False, redirectop=False):
        EzhilRedirectOutput.__init__(self, redirectop)

        try:
            lexer = EzhilLex(file_input, debug)
            if (debug): lexer.dump_tokens()
            parse_eval = EzhilInterpreter(lexer, debug)
            parse_eval.parse()
            if (debug):
                print("*" * 60)
                print(str(parse_eval))
            env = parse_eval.evaluate()
        except Exception as e:
            print("exception ", str(e))
            raise e
        finally:
            if (redirectop):
                self.tmpf.close()
                sys.stdout = self.old_stdout
                sys.stderr = self.old_stderr
Пример #9
0
    def __init__(self, file_input, debug=False, redirectop=False):
        EzhilRedirectInputOutput.__init__(self, file_input, redirectop)

        try:
            lang = "எழில்"
            lexer = EzhilLex(debug)
            if (debug): print(str(lexer))
            parse_eval = EzhilInterpreter(lexer, debug)
            ezhil_file_REPL(file_input, lang, lexer, parse_eval, debug)
        except Exception as e:
            print("exception ", str(e))
            raise e
        finally:
            if (redirectop):
                self.tmpf.close()
                sys.stdout = self.old_stdout
                sys.stderr = self.old_stderr
                sys.stdin = self.old_stdin
Пример #10
0
    def __init__(self, file_input, debug=False, redirectop=False):
        EzhilRedirectInputOutput.__init__(self, file_input, redirectop)

        try:
            lang = u"எழில்"
            lexer = EzhilLex(debug)
            if (debug): print(unicode(lexer))
            parse_eval = EzhilInterpreter(lexer, debug)
            ezhil_file_REPL(file_input, lang, lexer, parse_eval, debug)
        except Exception as e:
            print(u"exception ", unicode(e))
            traceback.print_tb(sys.exc_info()[2])
            raise e
        finally:
            if (redirectop):
                #self.tmpf.close()
                sys.stdout = self.old_stdout
                sys.stderr = self.old_stderr
                sys.stdin = self.old_stdin
Пример #11
0
def ezhil_interactive_interpreter(lang=u"எழில்", debug=False):
    ## interactive interpreter
    lexer = EzhilLex(debug)
    parse_eval = EzhilInterpreter(lexer, debug)
    REPL(lang, lexer, parse_eval, debug)