[英]How to can I develop a programming language like Coffee Script?
What are the initial requirement that i need to know to develop a programming language like coffee script that basically has its own syntax but after compilation changes into another language. 开发像咖啡脚本这样的编程语言时我需要知道的初始要求是什么,它基本上有自己的语法,但在编译后会变成另一种语言。 I did Google on that but couldn't find the right answer.
我做了谷歌,但找不到正确的答案。
Specify your language with a basic formal grammar in something like EBNF . 使用EBNF之类的基本形式语法指定语言。
statement = if-statement | return-statement | expression | ... if-statement = "if" "(" expression ")" "{" statements "}" return-statement = "return" expression ";" ...
Learn about simple parsing by recursive descent and operator precedence . 通过递归下降和运算符优先级了解简单解析 。
Write a parser that creates an abstract syntax tree from a source file. 编写一个解析器,从源文件创建一个抽象语法树 。
Write a code generator that converts this AST into your target language; 编写一个代码生成器 ,将此AST转换为目标语言; or
要么
Write an interpreter that merely evaluates the AST. 写一个仅仅评估AST的解释器 。
A good first step is to read Programming Languages: Application and Interpretation . 好的第一步是阅读编程语言:应用和解释 。 It'll teach you how to design and implement languages with interpreters.
它将教你如何使用解释器设计和实现语言。
The initial requirements are: 最初的要求是:
You'll still have plenty of work ahead, but basically, you're translating your new language into a target language. 你还有很多工作要做,但基本上,你正在将新语言翻译成目标语言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.