Jump to content

hisoka

Recommended Posts

in this link :

 

http://en.wikipedia.org/wiki/Interpreter_%28computing%29

 

it is mentioned the following:

 

"In computer science, an interpreter is a computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, without previously compiling them into a machine language program".

 

does this mean that the interpreter does the job of the computer CPU? and if yes

 

does it mean that an interpreted language , like PHP and contrary to a compiled language like C++ , does not need to be transformed into machine code as it is directly executed by the interpreter???

Link to comment
Share on other sites

The difference between compiled languages and interpreted languages is that compiled languages are translated to machine language as soon as you compile it, interpreted languages are translated to machine language as the program is running. This means interpreted languages are slower.

Link to comment
Share on other sites

The interpreter is software that is being executed by the CPU. It translates instructions to machine language and passes them to the CPU.

 

The CPU is the chip. It is the actual computer. The CPU does absolutely everything except whatever tasks are delegated to the graphics chip.

Link to comment
Share on other sites

"The interpreter is software that is being executed by the CPU"

 

who changes the interpreter code instructions into machine code so that the CPU can execute it ???

 

this is the first question

 

"and passes them to the CPU"

 

I read another thing : see

Fetch the Instruction in

 

http://en.wikipedia.org/wiki/Instruction_cycle

 

it is not stated that the interpreter is the one who passes the instruction to the CPU

Link to comment
Share on other sites

who changes the interpreter code instructions into machine code so that the CPU can execute it ???

The PHP software itself is compiled. It reads in a PHP script and then gets to work executing that code with its own instructions.

it is not stated that the interpreter is the one who passes the instruction to the CPU

Interpreted versus compiled languages have nothing to do with a CPU pipeline or instruction cycle. By that point all instructions are native CPU instructions.
Link to comment
Share on other sites

"The PHP software itself is compiled. It reads in a PHP script and then gets to work executing that code with its own instructions."

 

 

"Interpreted versus compiled languages have nothing to do with a CPU pipeline or instruction cycle. By that point all instructions are native CPU instructions."

 

I did not understand what do you mean???

Link to comment
Share on other sites

What part don't you understand? PHP itself is a program, it is a program that executes PHP code. PHP was written in C++. So, PHP is a compiled C++ application. That means that it gives the CPU native instructions, it doesn't try and feed PHP code to the CPU. It interprets the PHP code and tells the CPU what to do. Just like Javascript, which is also interpreted. Your browser (a compiled program) doesn't just feed Javascript code to the CPU, it reads the Javascript code and then executes it itself. None of this has anything to do with how the CPU actually fetches and executes individual instructions (the instruction pipeline).

Link to comment
Share on other sites

after reading your last post I will sum it up and I would appreciate it if you tell if I understand what you wrote or not .

 

The php program interprets the php code ,I write, to CPU ; that is it translates it to binary representation or machine code understandable by the CPU so that the CPU it executes our php code. In the same way the browser interprets the script to the CPU so that the CPU can executes it

 

am I right ? or is this what you mean?

Link to comment
Share on other sites

"That's not specifically how it works, but it's the general idea"

 

Could you please tell me how it works specifically ??

 

You can give me a link or links if you want too

 

Both Ingolme and JSG have. I think you need to read the replies people give to you a little more carefully. Have you considered doing some of research on your own first?

 

What part don't you understand? PHP itself is a program, it is a program that executes PHP code. PHP was written in C++. So, PHP is a compiled C++ application. That means that it gives the CPU native instructions, it doesn't try and feed PHP code to the CPU. It interprets the PHP code and tells the CPU what to do. Just like Javascript, which is also interpreted. Your browser (a compiled program) doesn't just feed Javascript code to the CPU, it reads the Javascript code and then executes it itself. None of this has anything to do with how the CPU actually fetches and executes individual instructions (the instruction pipeline).

 

The interpreter is software that is being executed by the CPU. It translates instructions to machine language and passes them to the CPU.

 

The CPU is the chip. It is the actual computer. The CPU does absolutely everything except whatever tasks are delegated to the graphics chip.

 

The difference between compiled languages and interpreted languages is that compiled languages are translated to machine language as soon as you compile it, interpreted languages are translated to machine language as the program is running. This means interpreted languages are slower.

Link to comment
Share on other sites

PHP itself doesn't have code for translating PHP statements into machine code. It has C++ code for setting up the PHP environment and then running the code. That C++ is already compiled into a language that the CPU understands. The CPU is executing compiled C++ code, not necessarily interpreted PHP code. The C++ code is running the PHP code.

Link to comment
Share on other sites

I read again all the answers. This is my conclusion. If I am wrong correct me

 

Correct me if I am wrong . PHP software takes the high level language instructions of the source code and interprets them to low level language so that the CPU can understand them . Executing the interpreter by the CPU is nothing more than executing the instructions that was interpreted by the PHP interpreter. In other words the PHP interpreter tells the CPU what to do . The same thing with Mozilla Firefox . Mozilla interprets Javascript code and once the CPU executes Mozilla it is executing the instructions that Mozilla interprets from high level language to low level language . In other words when Mozilla is executed by the CPU it tells it what it should do. Is it wrong or right?

Link to comment
Share on other sites

PHP software takes the high level language instructions of the source code and interprets them to low level language so that the CPU can understand them

It doesn't do that explicitly. Think of it as creating a virtual CPU that understands PHP code. The virtual CPU itself is running on top of an actual one. PHP itself is still written in a high level language (C++). It never goes lower than that.
Link to comment
Share on other sites

What I understood is this:

 

the interpreter directly executes the instructions in the program source code . It read the first instruction and executes it .Then it reads the second instruction and executes it until the end of the program . The instructions in the source code program are executed by ,the interpreter , in high level language because the interpreter knows the high level language and knows the low level language ( the language of the CPU) . Based on this knowledge it can ,independently and without the intervention of the CPU , execute the program and output it in the computer monitor . Am I wrong ? correct me if I am wrong

Edited by hisoka
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...