This is an old revision of the document!
LANraragi
Programming
Books
software foundation https://softwarefoundations.cis.upenn.edu/
Programming Languages: Application and Interpretation https://cs.brown.edu/courses/cs173/2012/book/book.pdf
Visualization
d3js
Misc
transpilers
To write a transpiler, which is a program that translates code from one language to another, you need to follow a structured approach. Here are the key steps involved in writing a transpiler:
- Define Input and Output Languages: Clearly define the source language (input) and the target language (output) that your transpiler will work with. This step is crucial as it sets the foundation for the translation process.
- Lexical Analysis: Implement a lexer to tokenize the input source code. This involves breaking down the code into meaningful units called tokens. Each token represents a specific element like keywords, identifiers, or operators.
- Parsing: Develop a parser to create an Abstract Syntax Tree (AST) from the tokens generated by the lexer. The AST represents the structure of the code in a hierarchical manner, making it easier to analyze and transform.
- Transformation: Write transformation rules to convert the AST nodes from the source language into equivalent nodes in the target language. This step involves traversing the AST and applying the necessary changes based on the translation requirements.
- Code Generation: Finally, generate the translated code in the target language using the transformed AST. This output code should be syntactically correct and semantically equivalent to the original code but in the desired language.
- Testing and Optimization: Thoroughly test your transpiler with various input scenarios to ensure accurate translation. Additionally, consider optimizing the transpiler for performance and efficiency.
- Iterative Development: Transpiler development often involves an iterative process of refining the translation logic, handling edge cases, and improving the overall quality of the output code.
How to implement a programming language in JavaScript https://lisperator.net/pltut/
js实现最简单的解析器:如何解析一个ip地址 https://github.com/frontend9/fe9-library/issues/3
解析器系列之二:教你手写递归下降 https://github.com/frontend9/fe9-library/issues/10