Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 698
monk Avatar asked Apr 24 '12 14:04

monk


People also ask

How do you write a CoffeeScript?

CoffeeScript Variables (No var Keyword) In JavaScript, we declare a variable using the var keyword before creating it, as shown below. While creating variables in CoffeeScript, there is no need to declare them using the var keyword. We can directly create a variable just by assigning a value to it as shown below.

Is coffee a programming language?

CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability.


1 Answers

  • 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.

like image 160
Jon Purdy Avatar answered Sep 19 '22 18:09

Jon Purdy