|
所在平台: Udemy |
课程主页: https://www.udemy.com/course/transpiler-from-scratch/
课程评论:没有评论
课程名称:从零开始构建转译器 课程概述: 在近年的编译器实现中,逐渐流行将一种高级语言翻译成另一种高级语言。这类高级编译器被称为转译器(transpiler),本课程就是围绕这一主题展开。通过利用现有的运行时环境,如 JavaScript 引擎,我们可以避免处理低级构造,例如内存和字节码指令,使得转译的过程更加实用。如果你想要探索编译器的世界并实现自己的编程语言,从高级编译开始是一个良好的实践方法,这也是本课程的重点。 许多关于编译器的相关书籍往往偏向理论方面,集中于解析、正则文法等内容,而不深入讲解如何构建一个实用的转译器。通过本课程的学习,我们可以在 2-4 小时内从头到尾构建一个完整的转译器,内容直接明了,课程中包含实时编码的配对编程和易于理解的描述。 在《从零开始构建转译器》课程中,我们专注于将一种高级并发编程语言(具有消息传递过程)转译为 JavaScript。除了深入探讨转译过程外,你将更好地理解并发函数式语言(如 Erlang)或操作系统的进程和线程如何运作。实现转译器的过程也将提升你的工程水平,因为它涉及多个数据结构和算法的方面。 课程先决条件: 本课程的可选先决条件是《从零开始构建解释器(Essentials of Interpretation)》课程,在该课程中我们构建了一种编程语言的 AST 解释器。如果你对编程语言的工作机制(如 eval、闭包、作用域链、环境等)没有深入理解,建议先参加解释器课程。 适合人群: 本课程适合任何渴望提高构建复杂系统技能的工程师,构建编程语言转译器是一项高级工程任务。如果你对编译器、编程语言及类型理论感兴趣,并希望为自己的编程语言构建一个转译器,本课程也非常适合你。 实现工具: 我们使用 JavaScript 来构建转译器,并将其编译为 JavaScript。JavaScript 是最受欢迎的编程语言,许多工程师都可以接触到。同时,我们的目标是提供一个简单明了的实现,而不是专注于宿主语言的细节。因此,代码应可移植到任意你选择的语言,如 TypeScript、Rust、OCaml、C++、Python 等。请注意,我们希望学生能够亲自理解并实现转译器的每个细节,而不是单纯复制最终的解决方案。尽管视频讲座中会展示转译器的完整源代码,项目的代码库中包含的 /* Implement here */ 作业需要学生亲自解决。 课程特色: 本课程的主要特点: - 内容简洁明了:每节课独立且简短,直接描述与主题相关的信息,不分散注意力。 - 动画展示与现场编辑笔记相结合:这样使得主题的理解更容易,展示各个对象结构之间的关联。 - 现场编码程序和任务:提供从零开始到最终完成的完整源代码,所有内容通过视频讲座呈现。 课程内容: 课程分为四个部分,共18节课,每节课有许多子主题: - 第一部分:转译器管道 讨论转译器管道、解析、代码生成及 AST 节点的探讨。 - 第二部分:函数与进程 实现运行时组件,如进程和调度器类,并讨论协作式多任务处理。 - 第三部分:模式匹配 实现有序数据结构,如列表和记录,并建立模式匹配的支持。 - 第四部分:消息传递 实现消息传递机制,进行案例研究,使用从网页编译的代码,构建最终的可执行文件。
Course overviewIn recent compilers implementation, it became popular to translate from one high-level language to another high-level language. Examples might be desugaring new version of JavaScript to an older version of JavaScript, or languages like TypeScript, etc. Such high-level compilers are known today as transpilers, and what is the topic of our course.It proved to be very practical, since we can fully rely on an existing runtime such as a JavaScript engine, avoid dealing with lower-level constructs like memory, bytecode instructions, etc.If you would like to explore the world of compilers and implement your own programming language, starting from the high-level compilation is a good hands-on practical approach, and which we apply in this class.Often related books on compilers go to theoretical aspects, stucking in parsing, regular grammars, etc - not explaining how actually to build a practical transpiler. I believe we should be able to build a transpiler for a full programming language, end-to-end, in 2-4 hours - with a content going straight to the point, showed in live coding sessions as pair-programming and described in a comprehensible way.In the Building a Transpiler from scratch class we focus on compiling a high-level concurrent programming language with message-passing processes, down to JavaScript. That is, in addition to the deep dive on the transpiling, you will get a better understanding of how concurrent functional languages, such as Erlang, or even an operating system itself with its processes and threads, work today.Implementing a transpiler will also increase your engineering level, as it touches several aspects of data structures and algorithms.PrerequisitesAn optional prerequisite for this class is the Building an Interpreter from scratch (aka Essentials of Interpretation) course, where we build an AST-interpreter for a full programming language. Unless you already have understanding of how programming languages work at this level, i.e. what eval, a closure, a scope chain, environments, and other constructs are - it is recommended to take the interpreters class as a prerequisite.Who this class is for?This class is for any curious engineer, who would like to gain skills of building complex systems (and building a transpiler for a programming language is an advanced engineering task!), and obtain a transferable knowledge for building such systems.If you are interested specifically in compilers, PL and Type theory, and want to build a transpiler for your programming language, this class is also for you.What is used for implementation?We build the transpiler in JavaScript, compiling to JavaScript.JavaScript, being the most popular programming language, should be accessible for many engineers, and also our goal is to provide a simple and concise implementation, not focusing on specifics of a host language. So the code should be portable to any language of your taste and choice: TypeScript, Rust, OCaml, C++, Python, etc.Note: we want our students to actually follow, understand and implement every detail of the Transpiler themselves, instead of just copy-pasting from final solution. Even though the full source code for the transpiler is presented in the video lectures, the code repository for the project contains /* Implement here */ assignments, which students have to solve.What's specific in this class?The main features of these lectures are:Concise and straight to the point. Each lecture is self-sufficient, concise, and describes information directly related to the topic, not distracting on unrelated materials or talks.Animated presentation combined with live-editing notes. This makes understanding of the topics easier, and shows how the object structures are connected. Static slides simply don't work for a complex content.Live coding session end-to-end with assignments. The full source code, starting from scratch, and up to the very end is presented in the video lecturesWhat is in the course?The course is divided into four parts, in total of 18 lectures, and many sub-topics in each lecture. Below is the table of contents and curriculum.Part 1: Transpiler pipelineIn this part we start talking about transpiler pipeline, parsing, code generation, and exploring AST nodes.Part 2: Functions and ProcessesIn this part we focus implementing our runtime components, such as Process and Scheduler classes, and discuss cooperative multitasking.Part 3: Pattern matchingIn this part we implement packed data structures, such as Lists and Records, and also build support for pattern matching.Part 4: Message passingIn the final part we implement the message passing mechanism, do a case study analysis, using the compiled code from Web, and build the final executable.