3

I am intrigued by lower level concepts such as operating systems, algorithms, mathematically proving software correctness, etc.

What intrigued me most are compilers. I started learning about them and wish to implement a toy compiler for the sake of learning and maybe it turns out to be something big (you never know, right?).

My goal is to implement lua-like statically typed, thread-aware programming language (first goal is interpreter with basic stack operations of course). My problem though is that I have little to no interest in lower level languages such as c,c++ or pascal and I was wondering whether it would be possible to implement a compiler for statically typed language in a dynamically typed environment?

I am interested to implement such a language in lua or python (lua suits me better though).

4

3 回答 3

6

Easy question: yes, absolutely, it's done all the time. Most compiled languages are ultimately "bootstrapped" such that their own compilers are written in the language itself: for example, javac, the standard Java compiler, is written in Java.

于 2012-07-29T23:56:44.650 回答
2

Yes it is. In fact, the compiler for the latest version of C# will be implemented... in C#: http://blogs.msdn.com/b/csharpfaq/archive/2011/10/19/introducing-the-microsoft-roslyn-ctp.aspx

(I'm talking about the Roslyn C# library:)

The foundation of this work is a new C# compiler, written in C# (and a new VB compiler written in VB too, see the VB Team blog for details).

Edit

Check this out: https://bitbucket.org/pypy/pypy

It's an implementation of Python written in Python.

于 2012-07-30T00:01:07.910 回答
-1

正如其他人指出的那样,是的,这是可能的,但是......

1-使用编译器,通常正在实现的编程语言与用于实现的编程语言之间的耦合非常薄。另一方面,不同的语言有不同的社区和不同的“专业领域”。对于编写编译器,最前沿的函数式编程语言(Haskell、Ocaml 等)有更丰富的用例和示例库,您可能想探索一下。他们的社区也充满了编程语言极客非常乐意分享他们的经验。

2-如果您对编写口译员(或笔译员)感兴趣,那么故事就不同了。宿主语言的某些特征强烈影响您的解释语言中的某些功能的易用性。例如,应用程序顺序,动态作用域和闭包在宿主和解释语言中更容易实现,遵循相同的规则。

于 2012-08-01T19:20:22.637 回答