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

Journey of writing a programming language

Journey of writing a programming language

Keshav Biswa

June 23, 2024
Tweet

More Decks by Keshav Biswa

Other Decks in Technology

Transcript

  1. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 I’m a Senior Software Engineer at Saeloun. •

    Working with Ruby since 2018 • Have worked with multiple frameworks and languages • Open source Enthusiast About Me
  2. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Love with esoteric languages • Learn how

    to make languages? • I got bored • It’s fun! Inspiration https://www.youtube.com/watch?v=hdHjjBS4cs8
  3. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Confuscript? • “Confusing” version of Javascript • Built

    on Ruby • Inverted Conventions • Altered Syntax Elements • Inverse Logic • Esoteric?
  4. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • \\ is comment • void is return

    and print is function • + means -, - means + • input is STDOUT and output is STDIN • loop will run until statement is false • null is used for declaration of variables • Examples
  5. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Parses the code with the grammar •

    Creates an AST • Evaluates AST • Adds to the context • Returns the context Interpreter
  6. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Uses PEG Syntax • Modular Grammar Definition

    • Automatic AST Generation • Error Reporting • Works with Ruby Just a Parser https://cjheath.github.io/treetop/index.html
  7. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Program is on top • action defines

    all actions • Assignment details all assignments • Conditional Logics • Loops • Operators • Initializations • I/O • Functions Grammar for Confuscript
  8. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Structural representation of constructs defined in the

    grammar • Hierarchical nature of the grammar • Terminal and Non-terminal • Each node has its own evaluation logic Nodes
  9. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Variable Declaration • Default Value Setting •

    Modifies the `context` hash by adding the variable with its value Initialization Node
  10. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Write a program to check if a number

    is palindrome? If user input is 12345 Print false If user input is 12321 Print true EXERCISE
  11. https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 RESOURCES To understand more about parsers, compilers, ASTs:

    • https://cjheath.github.io/treetop/index.html • https://www.youtube.com/watch?v=CFQBHy8RCpg&list=PLNBcOjqLS2ceRwHy7S4KZmiTa3h9Cr-K1 • https://amzn.in/d/9R2zsn4 (Compilers: Principles, Techniques and Tools) by Alfred Aho .et.al) • https://amzn.in/d/1HHy9ni (Principles of Compiler Design) by Alfred Aho & Jeffrey Ullman • https://www3.nd.edu/~dthain/compilerbook/compilerbook.pdf