Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building a Programming Language 101

Building a Programming Language 101

This is a presentation about building a programming language for GeekCampID 2017

Giovanni Sakti

July 15, 2017
Tweet

More Decks by Giovanni Sakti

Other Decks in Programming

Transcript

  1. How many of you know & understand 5 or more

    of these terms - Turing Completeness - Lexer - Parser - AST - IR - DSL - LLVM - Covfefe - Compiled vs Interpreted Raise your hands!
  2. So many things to discuss, So little time.. Intro Compiled

    vs Interpreted Lexer Lex, Yacc Parser AST IR LLVM GPL vs DSL 25 mins …
  3. I’ll give pointers on where & what to begin instead

    We can discuss later or you can come to the id-ruby meetup :D
  4. Most popular programming languages are very old and/or has considerable

    backing 34 Years 21 Years 22 Years 3 Years, but Backed by Apple
  5. Now you’re the one that try more to understand computer

    def start puts “ABC” end “ABC”
  6. There’s actually still a considerable gap even if you talk

    to computer using structured language
  7. At the very low level (which is the CPU) Actual

    computer hardware only understand very basic instruction
  8. mov eax, ebx — copy  the  value   in  ebx

    into  eax mov byte ptr [var], 5 — store  the  value  5  into  the  byte  at   location  var push eax — push  eax on  the  stack push [var] — push  the  4  bytes  at   address  var onto  the  stack
  9. Structured Language Instruction Sets As a good engineer, now we

    will try to breakdown this complex problems
  10. Compiling You yourself somehow use dictionary to convert a manuscript

    into other language that you understand better (for example from English to Bahasa)
  11. def start puts “ABC” end [:trace, 1], [:putnil], [:putstring, "hello

    world"], [:send, :puts, 1, nil, 8, 0], [:leave]]] “ABC”
  12. Interpreting You hire a translator to read and understand the

    manuscript, then you ask him/her to explain it to you
  13. Parsing without tools https://gist.github.com/ascv/5022712 """ exp ::=  term    |

     exp +  term  |  exp -­‐ term term  ::=  factor  |  factor  *  term  |  factor  /  term factor  ::=  number  |  (  exp ) """
  14. https://gist.github.com/ascv/5022712 exp ::=  term    |  exp +  term  |

     exp -­‐ term term  ::=  factor  |  factor  *  term  |  factor  /  term factor  ::=  number  |  (  exp ) 7 number + operator 3 number * operator 5 number -­‐ operator 2 number
  15. https://gist.github.com/ascv/5022712 exp ::=  term    |  exp +  term  |

     exp -­‐ term term  ::=  factor  |  factor  *  term  |  factor  /  term factor  ::=  number  |  (  exp ) 7 number + operator 3 number * operator 5 number -­‐ operator 2 number
  16. https://gist.github.com/ascv/5022712 exp ::=  term    |  exp +  term  |

     exp -­‐ term term  ::=  factor  |  factor  *  term  |  factor  /  term factor  ::=  number  |  (  exp ) 7 number + operator 3 number * operator 5 number -­‐ operator 2 number
  17. https://gist.github.com/ascv/5022712 exp ::=  term    |  exp +  term  |

     exp -­‐ term term  ::=  factor  |  factor  *  term  |  factor  /  term factor  ::=  number  |  (  exp ) 7 number + operator 3 number * operator 5 number -­‐ operator 2 number 7
  18. https://gist.github.com/ascv/5022712 exp ::=  term    |  exp +  term  |

     exp -­‐ term term  ::=  factor  |  factor  *  term  |  factor  /  term factor  ::=  number  |  (  exp ) 7 number + operator 3 number * operator 5 number -­‐ operator 2 number 7
  19. https://gist.github.com/ascv/5022712 exp ::=  term    |  exp +  term  |

     exp -­‐ term term  ::=  factor  |  factor  *  term  |  factor  /  term factor  ::=  number  |  (  exp ) 7 number + operator 3 number * operator 5 number -­‐ operator 2 number 7 3 +
  20. … if_stmt: 'if' test ':' suite ('elif' test ':' suite)*

    ['else' ':' suite] while_stmt: 'while' test ':' suite ['else' ':' suite] for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] …
  21. public  JavapTest(); Code: 0:  aload_0 1:  invokespecial #1    

                                   //  Method  java/lang/Object."<init>":()V 4:  return public  static  void  main(java.lang.String[]); Code: 0:  getstatic #2                                    //  Field  java/lang/System.out:Ljava/io/PrintStream; 3:  bipush 20 5:  invokevirtual #3                                    //  Method  java/io/PrintStream.println:(I)V 8:  return
  22. DSL

  23. The  ability  to  read  and  write  "variables" (or  arbitrary  data)

      The  ability  to  simulate  moving the   read/write  head The  ability  to  simulate  a  finite  state   machine A  "halt"  state
  24. If you want to understand clearly the concept first.. Build

    from scratch http://kanaka.github.io/lambdaconf/#/ https://github.com/kanaka/mal
  25. If you can create an interpreter for LISP using x

    language, then you will understand (almost) all of x language functionalities
  26. If you want to have a taste in creating programming

    language using modern tools Learn lex + yacc/bison or ANTLR
  27. If you somehow think that DSL suits your use case

    Learn to create DSL Learn Xtext