未加星标

Intro to programming language development series in JS

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二05 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

Take this article as a sort-of short introductory post. So, recently I've come up with an idea to create a programming language . Seams easy, isn't it? :sweat_smile: Is it possible? - Yes. Is it worth it? - Kind-of. You see, by creating a language you can learn certain concepts that you wouldn't otherwise. It just makes you a better programmer . Also, it's fun. :wink: So, without further ado, let's create a programming language !


Intro to programming language development series in JS
Photo by Glenn Carstens-Peters / Unsplash Let's get prepared!

Well, I think it's gonna be an interesting (and quite long) series. Keep in mind, that even this will be some new experience even for me. Like many others, I'm just an ordinary guy without deeper knowledge of language creation. I just plan on creating something from nothing (or rather from other sources on the web). Now, some basic information. The language I'm going to make will be named AIM (because I'm aiming at my goal of creating a language and it's a nice shortcut). It's meant to be multi-paradigm, statically typed, compiled language. For this, I'll be using LLVM (more on that later) and Node.js . As you might know, programming languages and similar lower-level stuff are done using C/C++, so I take Node.js - the unusual project is being made using unusual tools. Also, I'm a bit more experienced with Node.js that C/C++. :+1:

So, if you're ready, let's first create a TODO list:

Find a cool name ( done! ) :grinning: Create / imagine language's syntax. Create lexer. Create parser. Create compiler.

These are the most basic and definitely required steps. Next, going forward in the future without much order:

Standard library implementation Runtime library implementation Self-hosting/compiler bootstrapping Specification/documentation Examples/other libraries/first app

Now, let's get back to the ordered list and discuss each point for a second or two. Also, I'll be discussing each of these points in the following post, so I'll be brief.


Intro to programming language development series in JS
Photo by Fabian Grohs / Unsplash Create language syntax

Syntax and the general idea of it is one of, if not the most important when designing a language. Many programming languages have similar syntaxes. They base on what has already been proven to work and that's fine. That's what you should consider when creating a programming language of your own. But, as I'm not really planning on creating this particular language for general purpose (but who knows :joy:) I most likely won't follow this advice in order to create something new and fresh. Of course, it won't be as radical as this , so don't panic, just a little bit different. Still, I don't know exactly how will it look like but I'm sure it won't be so standard.

Create lexer

Nothing fancy here. A lexer is just a software that takes your code and creates a series of tokens with additional metadata for it. At least that's what I know for now. Of course there's a plan for posts about each step of language development, so be patient.

Create parser

A parser is much more important that lexer. Parser, from a list of tokens created by the lexer, creates what's called AST (Abstract Syntax Tree). It's basically a representation of parsed code in a form of the data tree, which allows interacting with it programmatically. So, it's important for it to be fast and well-design since it'll be used in things like linters, pretty-printers and so on. Generally by software that's meant to interact with the syntax of your language directly. Also, AST is what will be used in the stage of compiling the language to its machine code representation. Which brings us to the last, most important step...

Create compiler

This is what all the programming languages are about (the compiled ones, of course) - to just being able to execute. The compiler just takes your code and outputs (usually) the machine code. I've decided to implement the compiler with the help from LLVM (Low-Level Virtual Machine), so-called compiler infrastructure library. This piece of software has been used to create languages like (most notably) Rust and Swift together with one of the most popular C/C++ compiler front-ends - Clang , so it must be good enough for this project. :wink: It's much easier to use the C API of the LLVM to generate machine code than to use Assembly, obviously. Still, it's very big and complicated, so I'm going to spend a fair bit of time with its documentation, which is a very well-written one. Here the Node.js C binding may be necessary.


Intro to programming language development series in JS
Photo by Vlad Bagacian / Unsplash Journey begins...

So here you go with what's coming next. I'm not covering the other points as only time will tell what will come in the future. After this little intro, I hope you and me myself will enjoy this journey. Again, keep in mind that I'm not an expert, I'll just share my own experience, so if you got any tips for me, I'll be grateful. Now, the next post is coming about the syntax of this creation, so if you want to follow me on Twitter for any updates. Once more, thank you for reading this intro and let the journey begin...:+1:

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

分页:12
转载请注明
本文标题:Intro to programming language development series in JS
本站链接:https://www.codesec.net/view/620890.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(13)