Some time ago, to practice TDD and C # and explore ideas Erlang, I started an Erlang-like interpreter in C#:
The solution structure:
It has the core class library, draft tests, project and I am putting together a REPL (Read Eval Print Loop) as console program. The interesting thing is that Erlang internally has lightweight processes, implemented in the virtual machine itself, which can communicate with each other by sending and receiving immutable messages. I do not intend to implement a virtual machine of this type, but have processes in threads. They will never be as fast as Erlang, but it’s a first “baby step” to explore, before trying to improve implementation.
Messages can be sent to a queue per process (thread here), and I have implemented the acceptance of messages, and turn his rejection process, as in native Erlang.
But today I wanted to briefly discuss how to implement transforms input text into Erlang expressions and forms:
The Lexer returns tokens, and these tokens have a value and a type. It can already recognize an atom (a name that begins in lower case), a variable, delimiters, operators, integers and real numbers, strings. The Lexer is consumed by a Parser, which has two public methods: one that parses expressions, used from the REPL, and another that parses what Erlang is called a form, would like a function definition in a module of Erlang. There are also ways to declare the name of the module, or other forms exported with name and number of arguments. In these modules will not accept expressions, only statements such form.
If you look at the history of commits, you will see that not everything went ahead, but grew slowly, as small raised me to implement use cases.
Upcoming topics: discuss the implementation of expressions, forms, processes and threads with mailbox for messages, and the REPL. And keep working on the implementation of messages and distributed processes.