简体   繁体   中英

What does it mean for a language to be ‘interpreted’?

Do languages like eg Ruby (if running MRI, I mean not compiled to byte-code) run actually parsed everytime when an execution of, eg, method or loop body is needed? I mean, to execute a loop, you need to parse its body N times?

I just always thought that all these programs are being parsed one time at the bootstrap, transformed in a 'strongly-typed' statements tree, etc. Is that not true?

Interpreted is a word with a very loose definition. Even machine code instructions are interpreted by the processor.

In general a distinction is made between languages which are compiled before they are run and languages which do not have a compilation process and are run inside another program, called the interpreter. The latter types of languages are often referred to as interpreted languages .

The line is not that clear in some cases:

  • Some languages can be either compiled or interpreted, eg PHP.
  • Some interpreted code might be compiled at runtime into native machine instructions ( JIT compilation ).
  • Some compiled languages may have an exec functionality which allows code to be generated and executed at run-time, bypassing the normal compilation process.

I'll just be mean now and say that just about EVERY programming language is interpreted, whether it's a software (Ruby, Python, Java) or a hardware (C, C++) interpreter :)

For a real answer, while I don't know about the internal Ruby implementation, I'm sure as hell they don't parse the statement over and over and over again. While not using bytecode in the original implementation (or did they migrate already?), they use some intermediate representation (you can see it nicely when you want to write C-extensions for it), thus just executing those over and over again.

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