Summarized using AI

Slaying the Dragon

Jason Yeo • June 23, 2016 • Singapore • Talk

In the talk titled "Slaying the Dragon," presented by Jason Yeo at the Red Dot Ruby Conference 2016, the speaker explores the rewarding experience of writing a programming language, asserting that this task, often seen as daunting, can actually be enjoyable and accessible. The session focuses on implementing a simple Lisp interpreter in Ruby, specifically targeting attendees without prior knowledge of parsing, lexing, or programming language theory.

Key Points Discussed:
- Introduction and Speaker Background: Jason introduces himself, expressing his nervousness and briefly mentioning his work at SourceClear, an open-source security company.
- Talk Title Explanation: The title refers to the "Dragon Book," a well-known textbook on compiler design, challenging the notion that one must read it to implement a language.
- Reasons to Implement a Language: Jason emphasizes that writing a programming language is fun and instructive, helping programmers understand the intricacies of coding, language design, and error handling.
- Lisp Language Implementation: The session specifically chooses Lisp due to its simplicity, stating that it can be implemented in just a page of code. Jason provides resources for further learning, including guides for implementing interpreters in various languages.
- Interpreters and Virtual Machines: He differentiates an interpreter from a compiler, explaining how code is interpreted and compiled for execution on a virtual machine.
- Using Rubinius: Jason discusses Rubinius, highlighting its role as not just a Ruby implementation but a platform that allows the easy customization of language features like parsing and syntax trees.
- Implementation Process Overview: The talk breaks down the implementation into three main steps: tokenization (using regular expressions), reading tokens to transform them into s-expressions, and creating an abstract syntax tree (AST) to represent code structures.
- Bytecode Generation: A practical demonstration shows how to generate and interpret bytecode on a stack-based virtual machine, with interaction encouraged among attendees to experiment with examples in real-time.
- Conclusion and Resources: Jason wraps up by providing additional resources for attendees interested in language implementation, including links to repositories and guides for further exploration.

Slaying the Dragon
Jason Yeo • June 23, 2016 • Singapore • Talk

Speaker: Jason Yeo, Software Engineer, SourceClear

Learning to write a programming language is considered a rite of passage for some programmers. And, it is also the most rewarding exercise as you will learn a whole lot about programming languages in general. Many might think it's a daunting task but I will show you otherwise by showing how to implement a simple language in Ruby and compile it to Rubinius bytecode. Be warned, only the brave and true will survive. Don't you worry though, no prior knowledge of parsing, lexing and programming language theory required. And of course, don't forget to have fun.

Speaker's Bio
Jason Yeo flips bits and smashes stacks at SourceClear. Some of his interests include participating in pointless discussions about type systems, writing interpreters for languages that has no real world application, bashing languages that has real world applications and embedding Easter Eggs in talk descriptions.😝

Event Page: http://www.reddotrubyconf.com/

Produced by Engineers.SG

Help us caption & translate this video!

http://amara.org/v/ONq5/

Red Dot Ruby Conference 2016

00:00:20.960 thank
00:00:23.320 you I'm really nervous this is my first
00:00:26.080 time speaking to a huge crowd like this
00:00:29.320 so uh yeah so just thank
00:00:35.879 you um just a quick quick word about uh
00:00:39.840 Matt's talk just now it was really cool
00:00:41.600 I really like the ideal of types uh I
00:00:44.160 also love dark typing and uh it allows
00:00:47.160 me to do things like
00:00:48.840 this it's awesome Yep and um oh yeah and
00:00:53.960 by the way um yeah like I said I'm
00:00:55.600 actually very nervous so um because if I
00:00:58.280 screw up I'm going to screw up in front
00:00:59.440 of 300 people I don't know whether I
00:01:01.239 should come back to the Ruby conference
00:01:02.680 again but uh by the way uh there's
00:01:04.799 coffee outside and they actually powered
00:01:06.600 by
00:01:08.720 Scala yeah so I was thinking maybe
00:01:10.759 that's a hint that maybe I should go to
00:01:12.360 a Scala Community next time so
00:01:15.840 yeah okay so oops hi uh by the way my
00:01:19.200 name is uh Jason uh uh this is my
00:01:23.360 twwiter handle and this is my GitHub
00:01:25.960 handle I actually work at work at source
00:01:29.320 clear
00:01:30.439 uh it's a startup based in San Francisco
00:01:32.799 we are actually an open source security
00:01:35.159 company so we actually look at your open
00:01:37.720 source libraries and let you know
00:01:39.399 whether of them any anyone of them is
00:01:40.920 vulnerable and lets you know how to fix
00:01:42.920 it oh something happened to the screen
00:01:46.640 okay anyway so um yeah I'm going to talk
00:01:50.439 about how to slay a dragon so you might
00:01:53.560 think what what's up with the talk title
00:01:55.399 is it has anything to do with Daenerys
00:01:57.280 and his tender dragons Game of Thrones
00:01:59.920 nope uh it's actually referen to uh this
00:02:03.159 book right here it's actually a a very
00:02:05.399 famous uh University textbook used for
00:02:07.719 uh their compal course so it's also
00:02:09.640 known as the Dragon book so and but the
00:02:12.239 thing is that people think that when
00:02:13.280 they want to implement a programming
00:02:14.800 language or write a comper they have to
00:02:16.280 read this textbook so um but today I'm
00:02:19.280 going to show you that you don't and I'm
00:02:20.840 going to actually show you how easily
00:02:22.160 that you can um Implement your own
00:02:24.080 programming language and in our favorite
00:02:26.760 language Ruby yeah so but you might
00:02:29.560 think
00:02:30.760 why why why do we have to implement a
00:02:33.040 program language first of all it's fun
00:02:36.080 uh at least to me I think it's fun and
00:02:38.680 um you get to understand how programming
00:02:40.519 languages work and you get to understand
00:02:42.840 how your quote works so uh you might get
00:02:45.959 this kind of error sometimes in your
00:02:47.200 code and you once you actually Implement
00:02:50.000 a programming language you you actually
00:02:51.959 understand why you're getting this error
00:02:53.959 and you get to put yourself in the shoes
00:02:55.480 of a language designer like Matt's
00:02:58.760 here
00:03:03.200 um yeah don't ask me why he's wearing
00:03:04.720 that python QuickBook shirt he has yeah
00:03:07.760 but his shirts are really cool yeah like
00:03:10.159 I said so you get to put yourself in the
00:03:11.319 shoes of a language designer and you get
00:03:13.000 to appreciate things like oops U garbage
00:03:16.159 collection and scoping rules so today
00:03:19.599 I'm actually going to show you how to
00:03:21.239 implement a language and the language
00:03:23.000 we're going to implement is lisp yeah so
00:03:27.319 we're going to make a lisp so why lisp
00:03:29.840 because it's super easy to implement uh
00:03:32.760 you can actually implement this in a
00:03:34.400 single page of code right here yeah
00:03:37.200 believe me it's just a single page page
00:03:38.879 of code so you probably can't see and
00:03:41.280 there are tons of Guides Online so over
00:03:43.720 here we have pet noic he wrote a guide
00:03:46.720 on how to implement a lips interpreter
00:03:48.920 in
00:03:50.040 Python there's a guide uh that's called
00:03:53.079 build your own lisp but it's in C so if
00:03:55.680 you're thinking of contributing to C
00:03:57.879 Ruby and you want to learn C check out
00:04:00.159 this guide and um lastly last but not
00:04:03.519 least uh is this repository that I found
00:04:06.280 uh is it actually contains uh this
00:04:09.560 actually basically it has a lisp
00:04:12.799 implemented in 56 languages including
00:04:15.360 Ruby and he has a very nice step-by-step
00:04:17.440 guide and it's really easy to understand
00:04:20.040 because there's diagrams we all love
00:04:22.720 diagrams right because it's a lot easier
00:04:24.199 to understand so uh and also when you
00:04:28.400 implement uh when we implement this you
00:04:30.479 actually understand how we actually
00:04:31.960 influence Ruby so Mets back in uh 2006
00:04:36.479 he actually wrote this in an email to
00:04:38.000 the Ruby talk uh mailing list uh he said
00:04:41.919 this and I zoom in for you just in case
00:04:44.080 you can't see he says Ruby is a language
00:04:46.600 designed in the following steps take a
00:04:48.720 simple list language remove macros as
00:04:51.479 Expressions add simple object system
00:04:54.960 much simpler than Closs at blocks at
00:04:57.880 methods found in Small Talk At
00:04:59.560 functionality found in pear and this is
00:05:01.560 how he concludes so Ruby was a lisp
00:05:04.360 originally in theory let's call it mat's
00:05:07.080 lisp from now on yes so I propose since
00:05:11.479 mats was saying he wants to move Ruby
00:05:13.360 forward so to help move Ruby forward I
00:05:15.720 propos we change the name to Met's list
00:05:17.960 from now
00:05:19.720 on and I even designed a logo for
00:05:25.199 it and I I realized that the domain name
00:05:28.479 wasn't bought by anyone so I decided to
00:05:30.960 design a website and bought a
00:05:36.680 domain by the way it's real you can
00:05:38.600 actually go to the website and check it
00:05:39.720 out yeah try out mat lips it's a cool
00:05:42.919 language right so anyway uh get to the
00:05:46.280 serious stuff uh on to the serious stuff
00:05:48.000 let's get started building our lisp so
00:05:50.880 like I said just now I'm going to follow
00:05:52.400 this guide uh you can actually check it
00:05:54.520 out and and do check it out I really
00:05:56.240 encourage you to check it out I've been
00:05:57.199 seeing this so many times all right so
00:05:59.199 um and this implementation of lisp is
00:06:01.880 called male why do I say it's
00:06:03.639 implementation of lisp because there are
00:06:05.319 tons of implementation of lisp so um his
00:06:09.000 implementation of this is called male is
00:06:10.919 short form for make a
00:06:12.720 lisp yeah and um before we start to
00:06:16.280 implement it I'm pretty sure none of you
00:06:18.039 know not not none of you I'm pretty sure
00:06:20.160 Matts know lisp but uh I don't think a
00:06:22.720 lot of you know how to write lisp and
00:06:24.800 how to read lisp so I'm going to teach
00:06:26.919 you uh lisp in less than 5 minutes
00:06:30.360 yeah so uh right over here uh we have a
00:06:33.880 rapper an interpreter so I'm going to
00:06:36.520 type Cote in just pretend I know this is
00:06:39.160 Powerpoint but play along for me okay so
00:06:41.319 just pretend I'm going to type code in
00:06:43.199 and the result is going to be evaluated
00:06:45.199 and and UPC comes the result results so
00:06:48.520 um here is a piece of code uh can
00:06:50.639 someone just shout out what do you think
00:06:52.360 this will be evaluated
00:06:58.400 to any other smarter guesses I no I'm
00:07:01.440 just kidding any other
00:07:05.400 guesses eight yes I I heard eight right
00:07:09.160 so uh what you have here is actually a
00:07:11.039 list form on an Expression is usually
00:07:13.520 enclosed in parenthesis or brackets
00:07:16.120 depending on which part of world you
00:07:17.319 come from and um we have uh this right
00:07:21.240 here what do you think this will be
00:07:22.759 evaluated
00:07:24.960 to minus four that's right you guys are
00:07:28.199 really smart all right what about
00:07:31.919 this six nice and this right here true
00:07:38.319 thank you okay the difficult one what's
00:07:44.120 this 42 yes that's a right
00:07:48.479 answer and right here this is how we um
00:07:52.520 Define a function in male so we'll use
00:07:55.479 FN star uh in our expression so followed
00:07:59.000 by the parth the parameters and Clos in
00:08:02.080 square brackets and followed by the
00:08:04.120 function body so this function actually
00:08:07.080 helps us to um it's actually a function
00:08:09.759 that multiplies a parameter by
00:08:12.840 itself yeah this is similar to how we do
00:08:15.680 this in uh Ruby by using Lambda and um
00:08:19.919 to actually call it uh we put uh we
00:08:23.280 enclose uh the function and the
00:08:24.840 parameters in a pair of parentheses
00:08:26.360 again in the first position position we
00:08:28.240 put the function you want to call
00:08:29.879 and followed by the
00:08:32.000 arguments and you will give us 64 and
00:08:35.000 this is similar to how we do this it
00:08:36.399 will be we just call do call and pass in
00:08:39.680 arguments so if you want to give it a
00:08:41.760 name just use def followed by the name
00:08:44.120 you want to name it I I'm naming it SQ
00:08:47.120 uh short for square and uh I will call
00:08:49.839 it the same way just put the name of the
00:08:51.560 function and the parameters and give us
00:08:53.600 64 just as expected so now you know
00:08:56.480 basic
00:08:58.200 list W all right simple right so um and
00:09:04.200 I'm going to give a very very quick
00:09:05.920 introduction to interpreters so because
00:09:07.720 we're going to write an programming
00:09:09.120 language we're going to have to write
00:09:10.480 The Interpreter for it so an interpreter
00:09:13.160 basically takes
00:09:14.480 code um yeah it goes into The
00:09:17.360 Interpreter and it actually evaluates
00:09:19.800 directly on a machine but unfortunately
00:09:22.680 that is so Ruby 1.8 we are no longer
00:09:25.000 doing that so what we're going to do is
00:09:26.800 that we're going to take the code
00:09:28.760 compound to BU
00:09:30.560 code and run it on a virtual machine so
00:09:33.959 that it's evaluated directly on a
00:09:35.800 machine the real machine but you might
00:09:38.480 think what the heck is a virtual machine
00:09:40.399 so a virtual machine basically
00:09:42.120 interprets B code so B code is uh
00:09:45.000 basically a a bit higher level than
00:09:47.440 native code and um a virsion machine is
00:09:50.240 also an abstraction layer between the B
00:09:52.760 code uh and the native machine so we can
00:09:55.000 actually write the Same by code for
00:09:56.240 different kind of machines be it arm or
00:09:59.440 uh
00:10:00.959 x86 so you might think H uh actually no
00:10:04.120 I'm not actually going to do this in MRI
00:10:06.760 I'm actually going to use rubinus so you
00:10:09.320 might think why why rubinus rubinus is
00:10:11.120 just another implementation of Ruby so
00:10:13.519 actually rubinus is not just a
00:10:15.320 implementation of Ruby is also a a
00:10:17.480 language platform so it lets you easily
00:10:20.800 Implement a language in it so uh and it
00:10:24.279 lets you customize the parser and the
00:10:26.560 abstract syntax tree and I'll show you
00:10:28.519 how later on
00:10:29.560 so let's dive in so in short what we're
00:10:32.040 going to do is that we're going to
00:10:33.240 customize rubinus compilation pipeline
00:10:36.040 there's two things we're going to
00:10:36.880 customize first is the parer and second
00:10:40.200 is the abstract syntax tree for the
00:10:42.800 parer U there are three steps to it
00:10:45.639 first is the tokenizer second is the
00:10:48.279 reader and third uh is the passing logic
00:10:51.600 so for the tokenizer uh by its name
00:10:55.600 suggest is just tokenizers code so it
00:10:59.160 would take code and uh produce tokens so
00:11:02.440 my tokens are basically parenthesis um
00:11:05.120 symbols and
00:11:07.120 literals uh and it will return array of
00:11:09.839 tokens like this how am I going to do it
00:11:12.240 it's very simple I'm just going to use
00:11:13.399 this regular expression and apply on a
00:11:14.760 string yeah it's kind of like cheating
00:11:17.480 right okay so uh that's why I say it's
00:11:20.120 actually easy to implement a language uh
00:11:22.279 a list uh and um it's really simple my
00:11:25.920 lexer is just um my my tokenizer just a
00:11:29.360 piece of regular expression yeah so but
00:11:33.040 yeah so actually you can also take a
00:11:34.800 look at uh Lexing in in Ruby sorry uh I
00:11:37.560 mean lexin and mat liis so um if you
00:11:41.360 have a a ruby I mean a mat lips
00:11:43.519 interpreter with you um and you just
00:11:46.160 require Ripper Call do Lex on Ripper
00:11:49.839 passing the code and out comes the
00:11:52.079 tokens that represents the code so you
00:11:54.040 have f equals and one two three in the
00:11:57.079 last position of that array yeah you can
00:11:59.760 try it right now so just to recap we
00:12:02.079 have actually taken um the code and
00:12:04.480 actually spit it up into tokens so the
00:12:06.959 next phase will be the reader so uh what
00:12:09.839 a reader do is is that it basically
00:12:11.920 reads code so and um but of course it's
00:12:14.959 not that simple so it's going to take
00:12:16.760 out tokens and change to transform them
00:12:20.040 into s Expressions so what are s
00:12:22.079 Expressions so it's something from lisp
00:12:24.639 uh and uh basically in simple what it is
00:12:27.839 is basically just nest arrays that uh
00:12:30.240 adds meaning to my tokens so but before
00:12:33.160 we do that I have to explain the the
00:12:35.040 grammar of the language because our
00:12:37.760 implementation will be based on the
00:12:39.160 grammar so I'm going to show this scary
00:12:42.320 looking thing but don't really it's not
00:12:44.480 very difficult to understand so right
00:12:46.800 here we have three lines and each line
00:12:48.800 represent a rule the first rule is
00:12:51.160 basically uh um the in in the r you'll
00:12:54.600 see this colon colon equal operator it
00:12:57.000 means is a or can be expanded too so
00:13:00.199 left hand side is uh the right hand side
00:13:02.480 so and for that pipe operator is uh can
00:13:06.040 be read as all the plus operator can be
00:13:09.000 read as all one or more and the star
00:13:12.240 operator means zero or more so just to
00:13:15.079 give an example I'll use English a
00:13:17.279 subset that English obviously so uh to
00:13:20.240 to give an example so I have five rules
00:13:22.000 here so I have sentence a sentence can
00:13:24.839 be expanded to a subject followed by a
00:13:27.199 verb followed by an object
00:13:29.360 and uh a subject uh is a noun same for
00:13:33.399 an object object also nouns and a verb
00:13:36.320 can be eat or quote or love and Nows can
00:13:39.880 be I he she Ruby or python so sentences
00:13:45.040 that this grammar accepts can be I love
00:13:47.720 Ruby or he eats
00:13:51.120 python by the way the python conference
00:13:53.440 also happening at the same time I have
00:13:54.639 no idea why but yeah so they want to
00:13:57.560 like Ste program from us so anyway yeah
00:14:01.120 I'm not a very big fan of python by the
00:14:02.519 way
00:14:04.880 yeah all right so okay back to our
00:14:07.560 grammar so let me explain what this
00:14:09.279 grammar is so for the first rule our
00:14:11.480 form or um um listes is like expression
00:14:16.320 in lisp so um a form is uh can be
00:14:19.720 expanded to either a a list or an atom
00:14:22.880 and a list is basically a bunch of forms
00:14:25.639 uh enclosed in a pair of parenthesis
00:14:27.839 orare Square
00:14:29.519 and an atom uh is basically a bunch of
00:14:33.000 characters or a bunch of numbers or our
00:14:35.199 true and false literals so uh like I
00:14:37.880 said just now the L the reader
00:14:39.680 implementation is based on the grammar
00:14:42.680 so for our first rule we're going to
00:14:44.600 have a function that corresponds to it
00:14:47.000 so uh in this function I'm going to call
00:14:48.880 it read form I'm just going to take the
00:14:51.000 first token and check whether is an open
00:14:52.800 parenthesis if it is I'm just going to
00:14:54.800 call read list on it if it's not I'm
00:14:56.680 going to call read atom simple as that
00:14:58.720 that just like five lines yeah so as for
00:15:01.680 the second rule um since it's it's a
00:15:04.639 bunch of tokens and closing parenthesis
00:15:06.720 I'm going to put it in the loop and call
00:15:08.240 re form on it yeah and as for our last
00:15:11.240 rule atom so since it's uh a few cases
00:15:15.399 of the strings I'm going to put it into
00:15:16.800 a case when statement and uh with
00:15:19.279 comparing with against regular
00:15:20.680 expressions and strings so if it's an
00:15:23.040 integer I'll return the integer symbol
00:15:25.199 along with the token
00:15:27.079 itself right so just to recap I have
00:15:29.880 converted my code into tokens and my
00:15:32.120 tokens are transformed into s
00:15:33.920 Expressions so now to the last stage so
00:15:37.639 what we're going to do with s
00:15:38.519 Expressions we're going to actually
00:15:39.920 transform this into abstract syntax tree
00:15:42.800 so what are abstract syntax tree is
00:15:44.639 basically syntax trees that are
00:15:48.680 extract so it well it represents the
00:15:52.319 synthetic structure of the code and U
00:15:55.120 just to give an ex example so this
00:15:57.800 expression here
00:15:59.519 uh will be represented by this tree uh
00:16:02.199 with uh the Ed note and two children uh
00:16:05.480 the Ed note will be the root so uh the
00:16:08.360 children on the the child on the left uh
00:16:10.240 is called the left operant which
00:16:11.720 corresponds to our symbol myar and the
00:16:15.199 right child corresponds to the right
00:16:17.000 operant which is our integer 42 so how
00:16:20.240 is this implemented in code just like
00:16:22.360 this so my integer note is basically a
00:16:24.959 class that holds a value the integer
00:16:27.720 value and for my ad note is basically a
00:16:30.279 class that holds references to the note
00:16:32.560 objects and the note objects are uh to
00:16:35.199 the to the left and right op and they
00:16:37.000 themselves are node objects so and now
00:16:41.000 move moving on the most exciting part
00:16:43.079 which is B code generation so um and um
00:16:47.040 one thing that's special about Ruby I
00:16:48.920 mean Mass lips and uh rubinus is that it
00:16:52.680 actually uses a stack based version
00:16:54.639 machine so what's a stack based version
00:16:57.199 machine so basically it's a version
00:16:58.759 machine that operates where it
00:17:00.440 instructions operates uh it operant are
00:17:03.319 actually on a stack right so let me give
00:17:05.720 you an example okay so let's say I want
00:17:07.520 to compute 1 plus two on my stack based
00:17:09.799 virtual machine so on the left are my
00:17:11.520 instructions and on the right is my
00:17:13.199 stack where my instructions are going to
00:17:14.919 operate on so um I have to first what
00:17:18.600 I'm going to do is I'm going to push uh
00:17:20.559 the integer value one to the St next I'm
00:17:23.120 going to push the integer value two to
00:17:24.839 the set and next I'm going to uh execute
00:17:27.760 the ADD and instuction so what this
00:17:31.080 instruction do is that it will pop uh
00:17:33.480 the operant so um one and two will be
00:17:36.919 popped and it will push the result onto
00:17:38.760 the stack what do you think will be on
00:17:41.080 top of the stack after this
00:17:44.799 instruction yep I hear a tree yes that's
00:17:48.039 right so what if I want to multiply uh
00:17:51.559 the result of 1 plus2 by three so I'm
00:17:53.919 going to push three and execute the
00:17:56.440 multiply instruction so what do you
00:17:58.280 think will be at the top of St right now
00:18:01.159 nine that's right you guys are really
00:18:03.280 smart right so um yeah you can actually
00:18:06.760 see this actually happening right now if
00:18:08.440 you have an interpreter with you you
00:18:10.000 don't need to connect to the internet if
00:18:11.559 you have a ruby interpreter you guys are
00:18:13.360 Ruby right so you have an interpreter
00:18:15.320 right now so go to your interpreter uh
00:18:18.080 and uh we're going to use this class
00:18:20.360 from the ruie BM module the class is
00:18:22.640 called instruction sequence so um assign
00:18:25.679 your code uh in form of string to a
00:18:27.720 variable so over here I have a piece of
00:18:29.919 code which is 15 + 6 *
00:18:32.440 2 then I'll pass it to this uh um this
00:18:37.039 method from that class I'll call do comp
00:18:39.919 power on the code and I go going to call
00:18:41.960 this Assam or dis assemble for short
00:18:44.960 yeah so um it will it will actually
00:18:47.760 return us this and you'll see that 15
00:18:50.440 and six are being pushed onto the set or
00:18:52.919 rather over here it uses the word put
00:18:54.559 object and it calls op plus which uh
00:18:57.720 corresponds to the the plus um
00:19:00.120 instruction then you'll push um the the
00:19:03.440 integer value two to the set and cuse
00:19:06.159 and executes uh
00:19:07.880 multiply yep so you can try it right now
00:19:11.600 so um so as for rubinus how does it work
00:19:14.280 how are you going to generate bite code
00:19:15.559 so uh the first thing we're going to do
00:19:17.039 is that we're going to uh create a class
00:19:19.360 an empty class or rather uh some form of
00:19:21.520 interface where we Define the B code
00:19:23.840 method Y and um what's cool about Rubin
00:19:28.440 is that it actually provides a pure MTH
00:19:30.960 lips by code generation DSL yes so um so
00:19:35.760 this is how the DSL look like so in my
00:19:38.480 integer node class what do we do in the
00:19:40.520 integers we just push them to the St
00:19:42.159 right so in my B code method I just have
00:19:44.840 to um call or or rather I just have to
00:19:48.360 execute the push integer uh instruction
00:19:51.880 so this is the DSL and this is how it
00:19:53.440 looks like it reads just like the B
00:19:55.679 code and for our add no mod this is what
00:19:59.120 we do so we just have to push uh the
00:20:01.960 left oper by code and the right op by
00:20:04.559 code we just call sorry the the left
00:20:06.600 oper and the right oper by code method
00:20:08.520 and we execute the plus instruction so
00:20:12.039 once you have actually implemented the B
00:20:13.679 code instructions uh for all your notes
00:20:16.280 you have a working programming language
00:20:18.480 all right yes obviously um I don't have
00:20:23.080 a lot of time so I'm actually
00:20:25.960 um that is not a complete programming
00:20:28.520 language so um so where to get help if
00:20:31.320 you need help uh so I really recommend
00:20:33.440 you to check out this repository uh it
00:20:36.280 has a very nice guide a step-by-step
00:20:38.840 guide to teach you how to implement a
00:20:40.760 language be in Java C or Ruby and most
00:20:44.559 importantly has diagrams very nice
00:20:45.960 diagrams and um also check out this
00:20:48.520 repository this is um uh it's actually a
00:20:50.840 language implemented in rubinus um and
00:20:53.520 is uh done out by a bunch of beginners
00:20:55.360 from the real girls
00:20:57.120 community and of course you can check
00:20:58.919 out my repository and give a star if you
00:21:01.080 like it right and if you're interested
00:21:03.919 in the internal of Ruby uh uh yeah go
00:21:07.480 check out this book it's called Ruby
00:21:09.400 under microscope yeah that's all any
00:21:27.039 questions uh we welcome some questions
00:21:29.520 for
00:21:33.880 Jason W if you have
00:21:37.640 questions can you show
00:21:40.400 us can you show us that repository those
00:21:43.480 repositories that you you know oh sorry
00:21:45.480 I went too fast right okay so this is
00:21:48.600 the rubinus one Queen Frankie SL Lenny
00:21:53.720 and this is
00:21:55.200 the male one kanaka SL
00:21:59.400 mail and of course last but not least my
00:22:02.440 own repository JSO yeah I call it Melody
00:22:06.960 it's a sick quote it's really sick yeah
00:22:11.120 nobody got that reference it's
00:22:14.320 okay any any other
00:22:19.080 questions hey G hey um I don't know if
00:22:23.600 you if you said this and you're talking
00:22:24.880 if you didn't I just forgot it that I'm
00:22:26.200 sorry uh what got you you interested in
00:22:29.240 learning how to build your own
00:22:31.240 programming language like a
00:22:33.120 lisp you're saying why am I interested
00:22:35.880 yeah yeah yeah oh why yeah what what's
00:22:37.919 the origin story behind this talk I
00:22:39.480 guess origin story uh I was beaten by a
00:22:44.279 spider uh so
00:22:48.720 uh I always um Tau that because the I I
00:22:55.039 so basically I I spent a lot of time on
00:22:57.559 hacken
00:22:59.240 um so on hecken news uh you have Paul
00:23:02.720 gra gram talking about lisp so and he he
00:23:06.400 has all these blogs and all these
00:23:08.080 articles so it kind of inspired me so
00:23:09.880 and he he said that Lis is really easy
00:23:11.679 to implement and then I one day I just
00:23:13.679 tried it out and follow one of the
00:23:15.799 guides right here yeah cool thank you no
00:23:22.320 problem any more questions for
00:23:26.880 Jason
00:23:28.679 okay
00:23:29.720 um right it seems like oh wait
00:23:33.279 cool uh so you showed an example where
00:23:35.679 you generated bite code from um the the
00:23:39.520 the language so is it possible to
00:23:42.039 generate some uh Lang code in some other
00:23:46.360 language from that particular
00:23:48.840 language so you're saying is it possible
00:23:51.120 to um like let's say I have a Java that
00:23:54.520 compiles to this by c yeah so using
00:23:57.120 these tools
00:23:58.520 the tools that you talked about right
00:24:00.520 now yes is it possible to generate say c
00:24:04.080 a c function from uh not sorry not not
00:24:08.080 maybe not a c function but maybe a ruby
00:24:10.679 function from uh uh the syntax that you
00:24:14.120 just showed right now yes um the DSL
00:24:16.200 actually compiles to um the rubinus
00:24:19.840 version machine so it actually has um
00:24:22.640 some instructions for you to uh generate
00:24:26.039 functions I'm not sure what that answer
00:24:29.080 a
00:24:31.399 question yeah so there was a link right
00:24:37.360 here I think
00:24:40.559 yes y there's a link right here it's
00:24:42.760 kind of small and I went kind of fast so
00:24:44.840 we can check out like he has a it's an
00:24:47.399 article about the DSL uh in
00:24:50.399 rubinus yeah so it's it will show you
00:24:52.720 like what some of the constructs you can
00:24:54.120 generate in your programming
00:24:56.760 language
00:24:58.360 okay it seems like we have a last quick
00:25:00.520 question all right yeah hello I got a
00:25:02.919 question hi uh why don't you use uh
00:25:05.880 Regal for example for Lexing analysis
00:25:08.200 and
00:25:11.360 yat ACC for example for parel oh because
00:25:16.399 uh regular seems to be uh much better
00:25:19.039 than usual regular expression since it's
00:25:21.720 for example allows to um bars uh
00:25:25.159 recursive structures Etc yes um very
00:25:28.559 simply because uh the regular expression
00:25:30.799 Works once again it works just for my
00:25:33.600 use case oh okay yeah so uh yeah it's
00:25:37.960 pretty uh it's yeah it just works I
00:25:41.679 don't need another dependency because
00:25:43.000 it's not that high level like uh Ruby or
00:25:46.399 or like some other programming language
00:25:48.640 like C or JavaScript so I don't need
00:25:50.720 like such a uh I find it over CU to use
00:25:54.039 Reco for just for passing like
00:25:58.080 parenthesis and scriber kets yeah thanks
00:26:02.039 no
00:26:02.799 problem um thank you Jason uh for any
00:26:06.760 other questions for Jason you can reach
00:26:08.440 him on his Twitter handle which is Jason
00:26:11.799 yo JS Jason yo JS uh thank you very
00:26:19.080 much
Explore all talks recorded at Red Dot Ruby Conference 2016
+17