简体   繁体   中英

Can a Interpreted language have a entry point

I want to know, do only compiler based languages use a entry point, or if a interpreter based language can also use entry points, if yes then please give 1 example.

I shell scripts starts at the beginning of the script file. A python program starts at the beginning of the python file. In both cases you can call that the "entry" point.

The decision, if a program starts at the beginning of the file (like in both the examples above) or starts at a specific function (like main ) has nothing to do with the decision to make a language compiled or interpreted. It is a mere language design consideration.

Addition
It is actually a quite common for example in python to do something like

# include statements and
# class definitions and
# function definitions go here

def main():
    pass    
    #do main stuff here

if __name__ == "__main__":
    main()

This defines a main function and the first non-definition statement calls it, if the module is the main program file.

A typical way a program is started in Linux is by a shell calling fork+execve. The new process is loaded and begins execution at the entry point specified by the format of the executable; for example ELF. In the case of an interpreted language, the executable is the interpreter specified on the first line after #. such as /usr/bin/python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM