How to can I develop a programming language like Coffee Script?

前端 未结 3 608
耶瑟儿~
耶瑟儿~ 2021-02-09 10:17

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 an

3条回答
  •  面向向阳花
    2021-02-09 11:10

    • Specify your language with a basic formal grammar in something like 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; or

    • Write an interpreter that merely evaluates the AST.

提交回复
热议问题