Share
Embed
Transcript
21 slides
-
https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Writing your own Programming Language in Ruby Keshav
Biswa Senior Software Engineer at Saeloun -
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 -
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 -
https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Lexer • Compiler • Assembler • Linker
Overview of a Programming Language -
https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 Confuscript? • “Confusing” version of Javascript • Built
on Ruby • Inverted Conventions • Altered Syntax Elements • Inverse Logic • Esoteric? -
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 -
https://github.com/keshavbiswa https://twitter.com/keshavbiswa21 • Conditionally loads the grammar • Compiles grammar
on the fly if not available • Initializes the Parser Parser -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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