Slide 1

Slide 1 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Writing your own Programming Language in Ruby Keshav Biswa Senior Software Engineer at Saeloun

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Confuscript: The Art of Confusing Code

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 ● Lexer ● Compiler ● Assembler ● Linker Overview of a Programming Language

Slide 6

Slide 6 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Journey to Confuscript

Slide 7

Slide 7 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Confuscript? ● “Confusing” version of Javascript ● Built on Ruby ● Inverted Conventions ● Altered Syntax Elements ● Inverse Logic ● Esoteric?

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 How it works? Parser and Interpreter

Slide 10

Slide 10 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 ● Conditionally loads the grammar ● Compiles grammar on the fly if not available ● Initializes the Parser Parser

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Treetop

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 ● TDD ● Using Minitest Writing tests

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Checkout Confuscript ● https://rubygems.org/gems/confuscript ● Github Repo: https://github.com/keshavbiswa/confuscript ● Documentation and Guides: https://confuscript-lang.org/ ● Treetop Library: https://github.com/cjheath/treetop

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Any questions? THANKS!