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

Parsers in JavaScript

Parsers in JavaScript

This is an introduction to parsers in JavaScript with examples of PEG.js

Leif Gensert

April 22, 2020
Tweet

More Decks by Leif Gensert

Other Decks in Technology

Transcript

  1. Hello World
    Parsers with
    JavaScript

    View Slide

  2. View Slide

  3. Programming === Hiking

    View Slide

  4. Compilers
    Reverse
    Engineering Building Developer
    Tools

    View Slide

  5. You don't Say

    View Slide

  6. Every single program can be reduced to
    Input
    Transformation
    Output
    * Former Boss

    View Slide

  7. View Slide

  8. Human Readable
    Parsing
    Machine Readable
    Grammar

    View Slide

  9. View Slide

  10. "in 11 seconds" 11
    "11 seconds ago" -11
    "in 5 minutes" 300
    "in 1 minute and
    30 seconds ago"
    90
    "now" 0

    View Slide

  11. Leif Demo

    View Slide

  12. // 1 + 2
    add(1,2)
    // 1 + (5 - 3)
    add(1, subtract(5,3))
    // 1 + 5 * 3
    add(1, multiply(5,3))
    // (1 + 5) * 3
    multiply(add(1,5), 3)

    View Slide

  13. Leif Demo

    View Slide

  14. What else? Domain Specific
    NLP
    Config
    Files
    (Re)Implement
    Programming Languages

    View Slide

  15. Abstract Syntax Tree
    add(1, multiply(5,3))
    {
    type: "callExpression",
    name: "add",
    arguments: [1 {
    type: "callExpression",
    name: "add",
    arguments: [5, 3]
    }]
    }

    View Slide

  16. Why?

    View Slide

  17. Focus!

    View Slide

  18. View Slide

  19. Leif Demo

    View Slide

  20. - Parsers seem intimidating
    - Helps you understand Recursion
    - Try out formulon.io

    View Slide

  21. Shopping List

    View Slide

  22. Back

    View Slide

  23. Back

    View Slide