Building a programming language in an hour

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello it's me jt [Laughter] i'm nervous i uh i did that video on the five easy ways to get started with programming languages and in that video i thought you know it'd be cool i should do a video where i give myself a timer and i try to see what i can get done so here's the video i have it this is just gonna be raw you're going to see what this is right below i have one hour to get done as much as i can and i think that i mean it's it's a bit a bit of a silly you know deadline to see what you can get done in a single hour but i think too it shows hopefully it shows or will show that there's actually quite a lot that you can do in an hour if you keep to keeping things as simple as possible okay i'm not gonna try to hype we're just gonna see what happens so i'm gonna hit start and then we're gonna go you see i haven't even created the project yet so that's gonna eat into my time already um i'm gonna use rust that's the one i'm most comfortable with right now then we'll see what can happen from there oh my goodness one hour ready i'm not ready set oh my god go it's ticking down okay so my idea to get started first let's give ourselves a project cargo new one hour all right so that's going to be our project we'll open that file there's already too many things one hour cool all right so that's our project so the first thing that i'm going to do now that i have it up and running is i don't want to overthink it like that is going to be the thing that i my repeated refrain through this don't overthink so the first thing i'm going to want to do is sculpt out a very simple language to work with in rust i can just do this through enumeration so i'll make our language something like this where the first thing is say set variable we'll take in a name again don't overthink it and some kind of value all right so we need some kind of value in our system sure all right what kind of values uh uh okay let's give ourselves 64-bit integers let's not worry about floating point strings maybe maybe we might even delete that but let's at least give ourselves let's start with ants first again don't go too far so we have our language we're going to set a variable and then we're going to get the value back out and then uh so we need a get var huh okay there we go that's going to be our first program so in order to prove that this part works already so far i need something that is going to be our test so i'm going to make a little test here that's a function and it's going to be i don't know test one don't overthink it okay so what is our our command going to be that we run uh it'll be like maybe a vector of these of these commands let me call these commands so our commands will be a vac of set var command set yeah there we go and then the string will be i don't know a and then our value is going to be ant a hundred and then the next thing we want to do is command get var hey okay if we can get that working that's not a bad start let's close this you can see all right here we go so we've got set var a so we'll set whatever this is the value of this into our variable and then we'll get a variable so i want to run this against some kind of evaluator so like result equals evaluate so what i'm saying in the top five things you should try one of them let's just jump in and do the evaluator let's do the evaluator i'm going to pass in the commands and then the result of this will be the actual the actual value itself all right i need an evaluator so let's get an evaluator function evaluate we'll take in and rust this as a slice of commands so cool we're going to output a result of value or some kind of error i don't even know some error who knows yeah yep box dyne of yeah we'll figure that out later don't worry about it yet cool so we're trying to evaluate we're going to say 4 command in commands i need some state what's my state uh okay we'll make an evaluator it's got some state maybe right now all we're going to have is a hash table so use collection standard collections hash map cool yeah we probably want some kind of scope but before we make a scope let's give ourselves some variables hash map all right string to what value yep that sounds good and then this will be this will be some kind of thing to evaluate on top of that all right evaluate yep self cool so we have the self it comes in for each of the commands we'll run the command against ourselves yeah i buy that so match command take my watch off we're getting serious now okay set var so we've got the name that we're setting into and the value name value cool again we probably want some kind of scope making mental note moving on so set the variable we want itself.fars we need a mutable thing here all right sounds good set vars dot insert name into yep value.clone okay we'll want to clone that value sounds good let's give ourselves clone all right so that's step one we can set variables and set variables see my southern coming out set variables values and we want to be able to get variables so a particular name and then here we want to oh we need some kind of like nothing cool so if we set the variable we get nothing out or maybe just repeat the value that we had maybe that's good sure so we'll set it we'll clone it and then the um the result i'm just kind of looking to see whether the result is going to be so while we're going through this we'll say output equals and going back and forth on this nothing let's start with nothing we're going to say okay of value nothing yeah don't worry about all these squiggles like oh in one second how about now yeah now it's good all right so yeah we'll for set fires we won't return any value we could return the value that we're setting into the variable totally okay for git vars we definitely want to set the var the value so we'll say output we'll just put in output for now okay um match self dot vars dot get for name all right so we have some value and then we can set output sure output dot no i'll put equals okay value.clone all right so we're going to look up the value that we just that might be there if there isn't one there then we'll probably want to return some kind of error all right let's give ourselves an error enum eval error missing variable string then we'll give that debug also oh we haven't given anything to bug we will soon okay so if we get none in the nun case we know that we're in trouble we probably want to just go ahead and return error right because if we continue evaluating from this point we're kind of in like it doesn't make sense so we'll say this returns an eval error eval error there we go eval error missing variable we'll give this one that boom evaluate ship it so we need to make a constructor and then we're almost done just kidding uh do evaluator call vars equal hash map new all right we have a constructor for our evaluator that mute evaluator so this is the thing that's going to do all the evaluation for our particular our current language and then we pass in the commands we want to run and they are a method on evaluator and then we get the result nice we'll also say this test can fail eval error all right then the last step is we need a quality so we'll give ourselves partial eek and debug while we're at it why not so we can see the value there cool all right we have results let us assert equal the result is well first let's fail it and 30. all right okay and then if we succeed nothing all right cargo test so we should fail our test we're already 10 minutes in oh lord okay so yeah left hand side was 100 right hand side was 30. got it yep so that's going to be a test that would be easy to fix just set that to 100 and then this should pass done there we go so we haven't really made our stack yet but we have made vars no worries you want to turn this into a stack we could we'll leave it that way for now we can always turn it to a stack later in our copious amount of time that we have left okay so that is the evaluate part so i'm almost kind of going backwards from what you would expect we have an evaluator it has a very simple language of expressions and our next step is going to be to actually write a little bit of a parser it's not going to be fancy again in that five steps i said just make something that's as easy as possible to parse and i think that's exactly what we should do so we'll take in a string that's like our input and then we'll return a result of something ast it's not even going to be an ast it's like commands vec of commands yeah that's what it's going to be and then like maybe parse error or something oops so we'll do parser and this parser will be uh i don't know we'll come up with some parsers here in a minute but that will be the other thing that might come out of this parse error okay so we get in some input we parse it and we go back out i'm going to say that we're going to say 4 line in input.line so we're splitting on the lines next thing we're going to do is split on say the whitespace let um command equal line dot split ascii white space splits a string by ascii white space cool sounds great uh then like collect can i collect that into a vec is that allowed all right cool and then we're going to save this just to get that error to go away so we can make sure that no other errors looking good so we can see that this is a back of string slices that's great we can work with that so our maybe a kind of example what the language might look like so we have set variable and get variable maybe we have set then the name no no comma the comma is too hard just kidding but again let's just not overthink it we'll just have spaces between each part set maybe lowercase set set a 100 get a all right that's going to be that's going to be what we're doing so for us to check this we need to know that when we split it we have at least one yeah match command dot get zero sum x if x is equal to all right these are going to be our our match statement our kind of match cases for the different commands that we have so set we can parse set and in fact we could probably do something like this parse set input which is a bunch of string slices i think we're going to give that a try a result command or parse error okay so we'll pass into parse set power what command command command just command is that right if we do that okay right so we're going to check the head of this command make sure that it's the set the set command of the set that we support or the get x equals get great then we'll parse get for the current command uh yeah we'll use their output here in a second i'm just kind of kind of filling out the different parts we're going to need to fill in a second parse get also a slice not sure if we're allowed to slice like this but we'll find out command parse error all right so our first one is going to be that all right so we've already checked that the head is the word set then we need to say if input.length does not equal three that's problem return error of parse error yeah what kind of parser do we want we want one that's like mismatch number parameters params mismatch params num params yeah sure good enough so that is going to be the error that we return so we'll say you are a mismatch of number of parameters okay so if we get past this point we know we have the three elements the command name the variable name and the value so we're going to parse the variable name so let's say let var name equals parse of the var name make sure that that worked okay pars var name and we'll say let value equals parse value and we'll give so var name is input 1 this is input 2 and that should be good okay so you can kind of see we are dissecting or bisecting however you want to call it the different pieces that we'll need to parse this one was actually handling each command separately but there's reusable parts of the parse as well that we need to handle in this particular one i've got one that is going to be the var name which is a string size and its result will be we'll give it just the name like that or parse error and honestly this is just going to always be just for now yep i'm just going to take the string in and that is going to be fine and then the other one is going to be our value that's going to come in as a string slice we're going to return a result of value or parse error now right now all i really care about is if i can parse it into an i-64 which i think is string parse oh come on brain you got this bars i 64 like this into another type yeah that does sound pretty good so we'll say result equals so if we can't parse that into an i-64 right the only value type that we currently support is i-64 if we can't get an i-64 out of it that's a problem then we'll say this is a mismatch type these are not going to be the best errors in the world but that's okay so we'll match the result we're going to say you are okay so we've got an i-64 and once we have the i-64 we can take that same thing and return the value that is int of that if we get an error then we know that we need to return an error that is parse error mismatch type looks good cool now we have the variable name and the value we have sufficient stuff now to be able to say command of set variable with our var name and the value cool that was easy now we can just reuse the things that we had before all right oops in this one we're going to get the variable name we're going to say get var make sure this is two elements and there you go so now we have it's either get or set if it's anything else we don't support it so we want to return an error here and we're going to say return error parse error unknown command and then we're gonna get a name say like name.tostring or something okay sorry give ourselves unknown command string cool and then the last thing is that we really got nothing we are coming in and we don't we tried to split we don't even have a command and then we'll just i think in this case what i might just say is just ignore it it might just be a blank line like that's pretty harmless so if it's none we'll just continue or just ignore that's fine great so we have a well we're building up these commands we kind of parsed each of these commands but we haven't put them anywhere to save them out yet so i'm going to make an output called vec and for each of these i'm going to say output.push make sure that that succeeded output.push make sure that succeeded and if it doesn't it'll bubble up the error and now we've got the output that should go back out so instead of returning the empty vector we just return output all right now we can parse things so let's let's try a let's try an example test make a function sure parse test one that will also return result and yeah parse error it could be either eval error i kind of regret having two separate ones now um let's merge these so there's eval error where's error okay cool we're going to call this uh engine error okay so we'll look through and find all of the parse errors we had before and we'll turn that into engine error done and then eval error will do the same cool now that we don't have multiple kinds of errors that should keep a little bit easier to write yeah just a tiny bit of over engineering but easy to fix engine error done okay so now we have the engine error as our main type of error we can say uh input equal shall we shall we do it let's do it set x 30 carriage return oops wrong button carriage return get x that's going to be our input so we want the parse result parsed to equal parse of our input now we have a vector of commands we should just be able to run these commands just like we did earlier and we want to make sure that this fails yeah we'll call this commands like we did before and something like that right we take in our string we're going to parse it we're going to evaluate we're going to get some output all right cool it failed as it should so this should be 30 and then we test again done great now we're parsing so we have set x get x in our language again not a lot going with the language we got 34 minutes to add some more stuff if we want to um what do we want to add do we want to add strings do we want to add strings sure why not okay we're going to add some strings so the first thing that we're going to do is we need to extend value with a string all right so our goal is going to be something like this we're going to take in hello and we want to be able to parse hello we got to escape that okay so that'll be our job so parse we'll take in hello great so the part that we need to change then is that if we parse and we try to get a number what we're going to do here is we're going to check the first piece of the string now there's a bunch of ways that we could do this but i'm going to say if val starts with the pattern double quote and val ends with double quote and vowel length is greater than one all right so it's not the same double quote we know we've got a double quoted thing parse the string else parse the number right so as if you've already been watching you probably know what i'm about to do which is to give myself a few more parse functions again these are handy because i can reuse them and by reusing them that means i can really build up my parser one piece at a time which is really nice okay so we're gonna make a parse string and a parse number or parse integer parse and we'll call it right and this will also be value engine error and then that will be this whole thing that we had before so we'll take in something we'll try to parse it we fail we fail if we don't we don't great so we'll try to parse it as a number if it is not if it's not a string it doesn't have the quotes around it if it is then we'll parse it as a string all right looks good so the last thing that we need to do is to say that we are a string so probably what we want to do is to ensure that this is true so if this is true else we'll return the error of engine error mismatch type sure yeah whatever that's fine um we want the the inner part of the string which is say val from one to vowel length minus one be careful when you do this at home because you want that to be unicode safe but because we we already checked ahead of time and these are one byte long delimiters that we're using this is fine so now we've got this inner thing we're going to turn this into a string now we have this inner component that's a string and we'll return ok value string of inner okay yeah that's going to tell me we can make this better sure clippy's being i should ignore clippy don't don't pay attention to clippy you have an hour to get it done move on okay got it so that's par string parse value parse set pars get right okay test come on it says we have a string called hello and we're expecting an ant that looks beautiful that's exactly what we wanted string hello great and we'll test that we're good 29 minutes now what should we add um um that's a good question i feel like adding a bit more to the evaluator so right now we have variable again should we try to squeeze in a scope i feel like we might should okay let's squeeze into scope well no we're not resisting resisting but if we want to squeeze in a scope we would make a scope a vector of these hash table hash maps that that would be an easy way to make um a scope right now we're just making everything global and that's fine the other thing that we could do is to give ourselves some kind of evaluation stack and so this would be say a stack of values and this stack think of like a stack machine so that we can write values into it kind of push values into it and then pull values back out of it so okay that gives us some possibility for some new commands we could have done like a register machine i think stack is fine okay get var set var right that's going to work with the variables in scope i think push push what should we push variable push value uh pop and like maybe add something like that interesting i have to think for 10 seconds we have some opportunities here to make value also refer to variables so for example we could say this is a reference to a variable and then go find the variable hmm i'm not going to do it that way i'm not going to do it that way so get far might become push far okay cool we need to move let's go so let's start using our stack the first thing we're going to do is to create some evaluator right command looks good push cool v yep and so to the evaluator what it cares about is the stack so we're going to push v dot clone command pop right we need to check that the stack is not empty that's going to be one of the errors empty stack or something so let's say let result equal self.stack.pop if our match result so sum some v that's still good and then we'll return that making sure i remember how to do this get far output equals okay okay got it output equals okay of v none what do we do for errors just return emulate okay that's fine return error engineer empty stack okay so we tried to pop a value yep that's a problem command add right and so what add is going to do is say let hand side equals self.pop self.stack dot pop you know what i kinda want i kinda want a helper that says pop mute self and this is going to give me either the value or an engineer and that's going to be this we'll reuse this as as quickly as we can here 24 minutes all right keep an eye on that all right so it's going to be one of those and now this is output equals self.pop okay right and then like a semicolon or something expected okay yeah that's fine or just this maybe cool and then this lets us do this which is the other thing i wanted to do to be able to say left hand side let right hand side equal self.pop all right we can get our two left hand right hand if we ever break anywhere in between yeah great now self dot add left hand side right hand side right that's gonna be some value so this is the first time we're trying to add two things so we'll add an add thing and then in fact we'll just say output equals that cool now let's describe what adding is add so it doesn't have to be anything special it doesn't even have to be a method but just for brevity let's just do it this way um are they values yeah they'll be values and we can ignore yeah we can take ownership and return a value or an engineer okay so forever in a case where these panic or they mismatch then okay got it so we'll match left hand side right hand side and then on this side we'll say value int i1 value int i2 great that's that's fine and then we'll say i1 plus i2 okay for the other case we're not going to do it i mean you could add string concatenation as one possibility oh we'll just use mismatch type but for now let's not do that we'll see if we have time we'll go back okay so there's our ad all right and i think what we're going to do for get var is that what are we going to do here hmm hmm do we need like a push for command a little bit stuck on that part okay let's add the parsing first and then we'll come back and see what we want to do with our variables if x is push great and then we'll make a parse for that so we need push pop i keep hitting the wrong button push pop and then add push pop add cool i think actually if it is push or pop or add we already know what it is which is output.push command dot or pop so that one's pop this one's add it's nice and simple great so if we came in said push 3 push 10 add then pop to the value off we should see the result okay let's write that test so this will be our test i said parse test this is uh these aren't parse tests this is like real deal okay this will be eval set get and then eval set get string and then we'll make one here for what are we going to call this eval stack yeah why not why not then we're going to steal from ourselves for saving some time and this will be what push 100 push 30 and then yeah pop no no add we'll add first and then we'll pop something like that so add will push the value back on the stack did i make it push it back on the stack i don't think i did let's go fix that real quick so in the evaluator i have these two i've got the output we actually don't want that we want the result to be this and now we have a value and then we're going to push self dot stack dot push result and again we can just kind of play with this you know if we have enough time we can always keep tweaking and tweaking to do what we want it to do so that is push pop add right let's go back to the test we're writing so we've got push pop we'll leave it with hello yeah why not cargo test what do we have so that failed hmm non-zero code push 30. oops couldn't parse that that's bad how about that all right missing variable 100. oh we copied and pasted something i bet people watching the video are like hey hey you uh what the parser you didn't parse it correctly um right because this should be push instead of get right yep good call so we'll make this push parse push and this should be parse value call that val val push all right that's a little bit better nice look at that nice so we have 130 this should be int of 130. cool um yeah i am going to [Music] uh i still want to fix the pushing of the variables so you can push a variable in okay okay we're going to give ourselves just a new command to do it we can always twiddle with this again one of the things as you're working on a language you can optimize is to say you know how do we want to optimize it how do we want these features to interact with each other all right so we're going to create a new word push far yeah sure push far say that five times fast okay oops yeah there we go one called push far push far okay and then this is going to be it's going to be like like get but is going to be specific for pushing the current the variable that you want so we'll grab the variable we'll call this push far something like that does that look good maybe we need to still update the evaluator right yup push var push var and then its output is not going to be anything interesting instead when we get a value out we're going to take that value and say self stack push v you're u clone yeah sure okay now we have a new command that we can use let's make a new function or a new test function all right co-op and we'll say push we'll say push set x to 33 and then say push far x then push i don't know 100 and then add and then pop the result off that something like this right now this example should not be 133 and we'll call this eval push far sure but we'll see how close we get all right perfect nice so we have 13 minutes left what are we gonna do uh yeah good question what are we gonna do we can add type checkers we could add more functionality i think what i'll do though because we've just been adding test it doesn't feel like a language yet because i need to be able to load in by calling a function you know calling my main and running my script so we're going to make this do that okay for arg in standard environment args we're going to skip over the executable and get everything else all right for each of these we want to we're going to create ourselves an engine just the evaluator new make that mutable then we're going to parse let result equal parts of our arc sounds good if we ever fail we want this to fail all the way up it'll panic but that's fine for now so if if you hit a a problem while you're running you're gonna see it and then let answer equals uh evaluator or engine dot and then we're going to evaluate the commands so we'll call this commands and we'll pass in our commands boom boom boom great then our last step is we're going to show you what the answer is for that file yeah and then last step is okay cool so we're going to make ourselves i almost did vim in the terminal nice uh let's give ourselves some test files so how about samples and this first one will be [Music] i don't know hello dot one hour that'll be the name of our language one hour so then this will be set x says hello get x all right so if we say cargo run and then we pass it samples dot hello one hour unknown command samples hello one hour now see the thing is i thought i skipped over hm it's still seeing the first oh yep yep okay oops so we'll say standard file or fs read to string all right each one of these are each of the arguments are files then just for giggles i'm going to unwrap because we have like less than 10 minutes left so that's the contents we'll use the contents instead okay so each of these are file names not actual sources there we go so that is us running our first example let's make some more i'll make one called add one hour push 10 push 20 push 30. let's get fancy and then pop the answer off the top of the stack and then if we do that at one hour nice there we go and 60. um is there anything else we want to do do do do nine minutes to go i'm sorely tempted to work on a type system but it's a little bit tricky because we need to remember what pos what the stacks the values on the stack what their types are um oh my gosh oh my goodness okay this feels this feels like a bad idea to add the type system what other things can we add let's add we can do subtraction we can do other operators oh yeah let's add like string and cat we were talking about that earlier as well so we have add so we can just extend this this functionality i keep hitting page down when i do not intend to uh where were we here we go so we've got value string s1 value string s2 and that also is fine say okay value string s1 plus and concatenate that through s2 now we can do a concat example can cat one hour push hello push world oh we gotta go backwards thinking stacks here uh so we have to push world first and then hello and then add and then pop we shall see cargo run concat mismatch number of parameters we pushed add oh that should work alright so let's see where that happens mismatch num parameters par set did i say set somewhere num params set get push far push oh there's a space gotta be careful for that stuff we're not we have i mean one of the limitations of our compiler is that or of our interpreter is that we're we split on those white spaces so if we even put a white space in the middle of our string we're gonna feel it we have six minutes do we think we can fix that issue let's go for it let's see if we can do it which means oh my goodness so we can't use this oh wow hmm we basically want to split one time i'm trying to imagine switching this into a different kind of parser in like five minutes oh that sounds ambitious oh my gosh maybe if we had like 10 minutes we could do it all right i'm getting quiet now getting serious trying to see if i can actually do it okay split in with the number and the pattern what's the error suspicious split in what oh it's from like oh goodness so this will fail um and then command oh we want to yeah i might need more time to actually fix that let's actually do uh let's pop back up splitting on white space we'll kind of say this is a nice to do if people want to take this project i'll throw this up somewhere and if they actually want to extend it to be able to do that quotation thing that would be awesome but we've got loading in files we've got our quotations very basic quotation parsing but we could we could add a more sophisticated one give it enough time um push far get far push pop add great yeah looks good looks good we could begin adding a type system so for example if we wanted to the type system would need something like this enum type one would be like int string and then we could start building up from there doing a check of the results of those commands so say let's say it's totally going to ding while i'm doing this but just to kind of flesh out a tiny bit of what i'm talking about so we can say type check we'll take in those commands like this and then the result of this would be some type or in this case it's probably yeah some type result or some engine error which would be the type error and then we could run this so we'll say right now we'll give it like a nothing type too just to have something to put in there all right so we'll say yep for now you're this nothing right but what we want is okay what we want is to be able to say for command in commands then like type check command command and so on and just build from there but yeah we're definitely going to run out of time okay type nothing all right so yeah that's another thing that we could add was type checking and we would need to carry along with us in the type checker the current stack so as we did commands we would be changing the stack but the stack would hold the types of the different positions i kind of wish we'd gone that direction but uh yeah that's something that we could do so something like type checker and then this would have its own stack which is a vec of types and so like each of these would be an implementation of that and i'm like scrambling to do my last bit of typing here but yeah we could fit these into something like that just like we did with the engine and each of these would be able to see into that type checker all right and then this would be self dot great so something like this where if we flush this out we would be able to check the types of the values on the stack and then if anything broke we could return an error and this could be another pass that we add to our interpreter in between like parsing and evaluating we could add another okay okay that's our ding cool so how far did we get we have in our possession an interpreter for this one hour language the one hour language has a few different commands that we can run so we have a where's our list of commands here here we go so we can set variables in with values so the string here is the name of the variable and we can set values into them we can get a variable so the variable again the string there is the variable name we would be getting it from this global this global namespace a nice possible improvement if people want to take this and hack on it is to then take our global namespace and turn it into a real stack where it actually has levels um and of course extend the command set so we can call into something move to different part of the stack and then come back off or integrate a little bit better with the stack we already have right there's lots of areas that we can we can improve and that's part of the fun we have all these connections out to other parts in the world other types of functionality and whatnot that we can add so set for our gitvar and i added this push fire which is going to take the variable and then push that value onto the stack and then we also have the ability to work with the stack additionally so being able to take a a value that we know a constant push that on the stack pop it off if we want the top of the stack and to add meaning to take two parts of the stack pop them both off add and then push the result and of course you can add subtract and multiply and whatnot as other commands that similarly work with that stack we support integers so is64 specifically and a 64-bit sign integers and strings i started adding a little type system at the end but of course i didn't get very far i got distracted um it's it's tricky to push as much as you can into an hour i have to say but that was fun uh then we have different types of errors that the engine can have so like mismatched number of parameters and the type unknown commands etc we have our evaluator that can handle both looking up variables and a stack of values that we can push and pop from which is really cool another future implementation again if you want to merge those together would be maybe variables represent named parts of the stack as one possibility a it's a fun improvement so we can evaluate we can add we can pop and so on with the evaluator and then we have a section that is just the parsing side of it so being able to parse variable names so that doesn't that doesn't do much but it is a start parsing strings parsing integers being able to parse values and then our separate commands like parsing set get push bar push and then our top level purse and again this is very very simple all it does is take in the input split on the lines and then split using the white space what our different arguments are i was highly i was like really tempted to make this a little bit better i think that is another place where if someone wants to take this and evolve it to make it better this is a perfect place to start too you could write the parts parser yourself by hand if you want but there's also plenty of parsing libraries and if you take this example and then rewrite it in your and your language of choice like python or c or ruby no doubt you'll also have tons of parser libraries that you could be using that gives you a much better parse than just splitting up white space but again it was enough to get started we got plenty far in an hour so here's our our language and then i started on the type checker and then ran out of time so that's another fun place to add functionality if you want i kind of got you started by you know setting up the types if i had more time i would have then had the type checker work with the the stack of types just like the evaluator works with the stack of values so it gives us the same way of of whereas evaluation gives you a value a type checker would give you kind of a success of failure and then the resulting types i made some unit tests so we created some tests for working with you know get and set and strings and the stack and push bar and then of course we made some samples so we could run actual samples with our parser and evaluators and see the results and it works it wasn't so bad you know it wasn't so bad i got that done in an hour and i think with a little practice you could probably go much do much more than i was doing if you already kind of had a mental model for what you want the language to be like or how to parse particular things that you wanted to be able to parse or if you said well i'm going to spend x amount of time on this but i want to give myself 10 minutes to work on the type checker then you might have done a couple different design decisions as you went to give yourself space and time to do the all the passes to the compiler or the interpreter that you want anyhow i um this is a lot of fun i hope you enjoyed watching this video and i will see you on the next one bye everyone
Info
Channel: Systems with JT
Views: 3,834
Rating: undefined out of 5
Keywords:
Id: Zkd3mZYOOvw
Channel Id: undefined
Length: 67min 22sec (4042 seconds)
Published: Sat Aug 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.