开发者

Compiled interpreted language

Is there a programming language, having usable interactive interpreter, even as 开发者_JS百科it can be compiled to machine code?


Compilation vs. "interpretation" is essentially a matter of implementation, not the language itself. For example, MRI Ruby 1.8 is interpreted, while MacRuby is compiled to native machine code. Both include an interactive REPL. All the languages I know that have at least one machine-code compiler and at least one REPL:

  • Ruby
  • Python
  • Almost all Lisps (Lisp was the language that pioneered this technique, AFAIK)
  • OCaml
  • Haskell
  • Forth

If we're counting compilation to bytecode as well as machine code, it's true of the vast majority of popular bytecode-compiled languages:

  • Java
  • Scala
  • Groovy
  • Erlang
  • C#
  • F#
  • Smalltalk


Haskell, using the Glasgow Haskell Compiler which has an interactive "shell" called GHCi.


Many flavors of Lisp offer both options, including Clojure.


Two come to my mind : ocaml and scala (~= java), but I'm sure there must be a lot more out there.


And here's another one to burn your house down:

x86 Assembly

Yup, there are interpreters for this as well.

  • Javascript x86 Assembly Interpreter
  • Jasmin

At this point you're really in emulator land, but it does meet the requirements you state.

I'm wondering if it's easier to name compiled languages that someone hasn't cobbled up a working interpreter for. :-)


Lua has an interactive mode for one-liners and experimentation. It normally compiles to bytecode for its VM for execution. LuaJIT is an independent implementation of a Lua VM that also does just-in-time compilation to 32-bit x86. Support for 64-bit is underway, and support for ARM is frequently requested.

Compilation to a bytecode is often a reasonable compromise between a pure interpreter and a pure compiler. The VM can be tuned to the needs of the language, and JIT techniques can analyze the VM code as it executes and concentrate on frequently executed code paths and inner loops.


As others have mentioned, OCaml.

If managed code (.NET CLI) is close enough to machine code, F# would be a candidate as well. There are probably other .NET/Mono languages which meet the requirement as well.


You may regret you asked:

C and C++.

Why?

  • Ch
  • CINT
  • EIC
  • picocc

and there are probably others out there as well.


Plenty of languages offer an implementation that both interacts and compiles to machine code, but it's rare to do both at once. Standard ML of New Jersey is one that has an interactive loop but no bytecode: it simply compiles to machine code in memory and then branches to it.


Not exactly machine code, but Java can be compiled and also used via BeanShell.


I've used Ruby with an interpreter, and there seems to be a compiler here.


Icon used to have a compiler, but it falls in and out of maintenence. It may still work.


Python can be compiled to windows executables.


C# can be compiled by using SnippetCompiler, maybe this would act as an interactive interpreter for you?


Your question is a bit vague. Even Java would fit it:

by interactive interpreter, i mean shell-like environment, where you can work in the runtime interactively.

Java has this, e.g. in the Eclipse "scrapbook pages", where you can enter Java expressions and have them evaluated right away. Java is of course also a compiled language (and while it's usually compiled to bytecode, there are various compilers that output machine code).

So what are you looking for? Maybe you could explain your problem or interest.


I tried using mono/.net for a bit and found random GC pauses to be disagreeable (at least on my crusty old laptop). I looked at using gambit-c an implementation of scheme that can compile to C but it seemed difficult to work with because the docs were somewhat limited and the packages where not very easy to install and use.

I usually just stick to having an interpreted language such as python bound to C/C++ which is more painful but at least I know what I am in for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜