As a practice of learning compilation theory, I tried to implement a language interpreter with what I’ve learned. I get Lua and Ruby source codes for reference, as Lua code is relatively small and Ruby is the one I am familiar with.
Firstly I coded a hand-written lexer and parser ,along with its simple vm using cpp. It is based on a stack(like Ruby),and has blocks and scopes.
It can eval codes like this:
c=1;
for(b=1;b<9;b+=4){
c*=3;
}
d=c;
However, the incomplete vm doesn’t have GC , function definition and function call. Then the whole program grew out of control when it had 9 source files,14 headers. I gradually get unfamiliar with my own code (although I wrote comments), and finally dropped this project.
Those complete languages have more functions and more complicated architectures. Lua has 34 source files and Ruby has 107, and they depend on each other ,one by one. Also the function and macro definitions are so many that I can’t trace them to the first declaration, Therefore I can’t get a point to dig into.
This problem also appears when reading other projects, even if many softwares are open-source, I can’t understand the how they work, let alone making contributions. How can I get over this difficulty and complete my own projects?
Thanks to everyone for helping.
从 Windows 版邮件<Microsoft Outlook on the App Store>发送