1 00:00:01,240 --> 00:00:03,629 welcome back everybody to are 2 00:00:03,629 --> 00:00:06,859 I'm lecture on parsing and lead 3 00:00:06,859 --> 00:00:10,620 make it does on our first more net I am 4 00:00:10,620 --> 00:00:14,910 grade and now we can move on 5 00:00:14,910 --> 00:00:18,440 and lead look add 6 00:00:18,440 --> 00:00:21,949 a an another operator 7 00:00:21,949 --> 00:00:25,859 on partners that really 8 00:00:25,859 --> 00:00:29,300 an make it into a moan at 9 00:00:29,300 --> 00:00:33,110 and that is namely sequencing of bars 10 00:00:33,110 --> 00:00:36,670 so what we want to do as we wanted a good barger 11 00:00:36,670 --> 00:00:41,570 and not gonna you know try the other one that the first one failed 12 00:00:41,570 --> 00:00:45,620 but we want to go to sequentially composed and so we don't do gonna run 13 00:00:45,620 --> 00:00:46,649 one barger 14 00:00:46,649 --> 00:00:52,910 and then run its terminated we want to run the next bars & Poor Dad we're going 15 00:00:52,910 --> 00:00:56,469 to use this so called to duty and action to do 10 Dec 16 00:00:56,469 --> 00:01:00,770 that's one of the advantages of having a moan at because now you can ride 17 00:01:00,770 --> 00:01:04,610 code that looks I'm and out that makes this 18 00:01:04,610 --> 00:01:09,460 sequential composition clear so here's what we all do it 19 00:01:09,460 --> 00:01:12,700 ride so we want to ride the following are the day 20 00:01:12,700 --> 00:01:16,310 drive to bars a nighttime 21 00:01:16,310 --> 00:01:20,570 Golden Axe bars another item 22 00:01:20,570 --> 00:01:24,409 I don't care and about that also I don't give a name 23 00:01:24,409 --> 00:01:28,110 that bars a third IBM goal that why 24 00:01:28,110 --> 00:01:31,860 and then return the pair of X common why 25 00:01:31,860 --> 00:01:35,060 okay sorry to hear that were sequencing 26 00:01:35,060 --> 00:01:38,210 these three barges I P M 27 00:01:38,210 --> 00:01:42,049 a ever just returning the first and the Los 28 00:01:42,049 --> 00:01:45,820 and now 29 00:01:45,820 --> 00:01:49,280 if you look at a this code here 30 00:01:49,280 --> 00:01:52,560 remember that we talked about to lay out a row so 31 00:01:52,560 --> 00:01:57,049 all day right banks here must be lined up 32 00:01:57,049 --> 00:02:00,770 really nice you can also good curly braces 33 00:02:00,770 --> 00:02:04,710 and Jamie goes in there that actually well I usually do 34 00:02:04,710 --> 00:02:08,560 and when I used to do notation because then it looks even more like Embarq it 35 00:02:08,560 --> 00:02:09,060 got 36 00:02:09,060 --> 00:02:11,730 I 37 00:02:11,730 --> 00:02:15,140 and as we already showed 38 00:02:15,140 --> 00:02:18,940 if you don't food is gone left arrow a and their 39 00:02:18,940 --> 00:02:22,090 then the partners gold but they have resulted 40 00:02:22,090 --> 00:02:26,100 discarded alright 41 00:02:26,100 --> 00:02:29,320 so I'm the other thing is dead 42 00:02:29,320 --> 00:02:33,250 when we're composing partner mokhiber barges in a row 43 00:02:33,250 --> 00:02:36,510 what we want your help is dead you know when 44 00:02:36,510 --> 00:02:41,040 any attempt failed the whole thing will fail and then we get always gonna 45 00:02:41,040 --> 00:02:44,370 dry read the the triple plus do 46 00:02:44,370 --> 00:02:47,890 you know you have another partial so I V Bar a.m. 47 00:02:47,890 --> 00:02:51,540 every am bar here P 48 00:02:51,540 --> 00:02:54,560 and that what are our example here 49 00:02:54,560 --> 00:02:57,590 and would get it would take this guy and murdered 50 00:02:57,590 --> 00:03:01,240 bars three characters and readers the first 51 00:03:01,240 --> 00:03:05,640 and that their readers yet but if we tried to 52 00:03:05,640 --> 00:03:10,470 applied at through a drink that only has two characters 53 00:03:10,470 --> 00:03:13,910 then they won't work so it will fail 54 00:03:13,910 --> 00:03:17,110 it will fail you see it here 55 00:03:17,110 --> 00:03:20,490 failing eat their I'm failing 56 00:03:20,490 --> 00:03:23,640 like departure okay so 57 00:03:23,640 --> 00:03:28,760 when a barter any bars images aggression combos fails you want the whole 58 00:03:28,760 --> 00:03:32,310 think bit okay and the other than 59 00:03:32,310 --> 00:03:35,630 is dead the the real 60 00:03:35,630 --> 00:03:39,860 advantage of having a Mon add as know that it makes you look smart 61 00:03:39,860 --> 00:03:44,160 it is not that you're a cool kid it's not that you can ride 62 00:03:44,160 --> 00:03:47,420 to millions blow up almost on explaining Mon at 63 00:03:47,420 --> 00:03:51,180 their real advantage Mon at is that you can do 64 00:03:51,180 --> 00:03:54,410 used to do notation a ride and 65 00:03:54,410 --> 00:03:58,360 so that all there is to it 66 00:03:58,360 --> 00:04:03,560 not a big deal a ride to allege 67 00:04:03,560 --> 00:04:06,680 I'm grabbing your 68 00:04:06,680 --> 00:04:09,940 riding show more partition here in this cage 69 00:04:09,940 --> 00:04:13,170 assuming that we have this barger 70 00:04:13,170 --> 00:04:16,820 that can do a.m. sequential composition 71 00:04:16,820 --> 00:04:20,260 we're going to and ride 72 00:04:20,260 --> 00:04:23,600 the following function that pink granite get 73 00:04:23,600 --> 00:04:24,740 from care 74 00:04:24,740 --> 00:04:28,210 after tubal and breeders a bar here 75 00:04:28,210 --> 00:04:33,539 for character you hear that that don't be 76 00:04:33,539 --> 00:04:37,240 or looking for a character that satisfies be 77 00:04:37,240 --> 00:04:40,860 weep arsenide done it will trigger next 78 00:04:40,860 --> 00:04:47,860 FBI hold every immediately returned act every dog chased the input 79 00:04:48,050 --> 00:04:51,539 it be aback 80 00:04:51,539 --> 00:04:55,449 does not halt then we have to 81 00:04:55,449 --> 00:04:58,800 fail alright so this is 82 00:04:58,800 --> 00:05:02,340 quite a bit we tried to bar any I don't 83 00:05:02,340 --> 00:05:06,370 Demi Jack whether to grant a good haul if it holds 84 00:05:06,370 --> 00:05:10,020 we use the bars are not always 6eh and 85 00:05:10,020 --> 00:05:14,740 ever the Brotherhood does not hold for years the bar here that always felt 86 00:05:14,740 --> 00:05:18,069 good notion does came in quite handy I'm 87 00:05:18,069 --> 00:05:21,870 alright ledge years this 88 00:05:21,870 --> 00:05:25,509 at bars are now to ride some interesting 89 00:05:25,509 --> 00:05:29,650 at think so say that we want to parse it did 90 00:05:29,650 --> 00:05:33,460 well what they can do it again today used it 91 00:05:33,460 --> 00:05:39,409 Sat red is dead so not this thing will try to parse a character 92 00:05:39,409 --> 00:05:43,370 check weather today did in that case it will imagery 16 93 00:05:43,370 --> 00:05:47,349 that they did image know that they did it will fail 94 00:05:47,349 --> 00:05:51,830 immediately I'm if you want to parse 95 00:05:51,830 --> 00:05:55,590 specific character I'm here 96 00:05:55,590 --> 00:05:58,880 got back and we can use sectioning 97 00:05:58,880 --> 00:06:02,009 to grid the predicate 98 00:06:02,009 --> 00:06:05,919 X it grows a quote so this is a function 99 00:06:05,919 --> 00:06:09,610 expected character and checks rendered equal to act 100 00:06:09,610 --> 00:06:13,969 and then we applied at set alright 101 00:06:13,969 --> 00:06:17,460 sure you see a quite nice use of sectioning 102 00:06:17,460 --> 00:06:22,310 in case you wondered why honored it is weird sectioning and have to go 103 00:06:22,310 --> 00:06:25,479 up here you have an example up this 104 00:06:25,479 --> 00:06:28,490 now some people won't say 105 00:06:28,490 --> 00:06:32,050 %uh but you know they're X here and their action there 106 00:06:32,050 --> 00:06:35,400 I can ride this point for each stock so maybe you should ride 107 00:06:35,400 --> 00:06:37,410 you can ride this thing here 108 00:06:37,410 --> 00:06:41,010 and point freestyle and again as I warned you 109 00:06:41,010 --> 00:06:44,370 when used Ford Freestyle read from serb opposition and so on 110 00:06:44,370 --> 00:06:48,360 you got your code might become quite unreadable 111 00:06:48,360 --> 00:06:52,530 very quickly but in this case I think it's a nice challenge 112 00:06:52,530 --> 00:06:55,840 to right this wrong. 13 and will nuke 113 00:06:55,840 --> 00:07:01,350 quite nice okay but you get the next one here 114 00:07:01,350 --> 00:07:04,660 it into a bar that drives to parse me 115 00:07:04,660 --> 00:07:09,310 year or more times and you see the adopted like a regular expression or 116 00:07:09,310 --> 00:07:11,670 repetition and I want to find you know 117 00:07:11,670 --> 00:07:15,500 here are more digit maury by Buddha Bar 118 00:07:15,500 --> 00:07:18,970 identify rwanda barcy and a letter 119 00:07:18,970 --> 00:07:22,790 followed by a year or more identifiers or digits 120 00:07:22,790 --> 00:07:25,820 so yeah digit often happens 121 00:07:25,820 --> 00:07:29,370 when you're trying to parse think so here we see many 122 00:07:29,370 --> 00:07:32,850 thank you barbara Bay and readers a bar sure 123 00:07:32,850 --> 00:07:36,090 messed up and guess wat 124 00:07:36,090 --> 00:07:40,440 this is defined recursively so many of me 125 00:07:40,440 --> 00:07:45,020 first drive-through barcy at least won't be 126 00:07:45,020 --> 00:07:49,060 and if that fails and returns and 127 00:07:49,060 --> 00:07:53,810 the MPS are and you know will be slightly nicer to use the 128 00:07:53,810 --> 00:07:59,370 parser dead always fail there now how do we write many want well 129 00:07:59,370 --> 00:08:03,350 and really find that in terms of many sure we have here 130 00:08:03,350 --> 00:08:07,020 mutual recursion definition so if I want to parse 131 00:08:07,020 --> 00:08:11,680 be one or more times I tried to barge be wrong 132 00:08:11,680 --> 00:08:16,150 I get the value P then I tried to 133 00:08:16,150 --> 00:08:19,270 bar here or more times be 134 00:08:19,270 --> 00:08:22,590 I got the value that can be dnt elective II 135 00:08:22,590 --> 00:08:26,480 it by return them to let dad and 136 00:08:26,480 --> 00:08:33,480 I have to apologize it is really regarding the empty let that up failing 137 00:08:36,650 --> 00:08:37,190 because 138 00:08:37,190 --> 00:08:41,570 if I'm bars be here are more time second bars and longtime 139 00:08:41,570 --> 00:08:44,930 or hear adults and this year a dime I have to return the 140 00:08:44,930 --> 00:08:48,630 let so I'm Atlas 141 00:08:48,630 --> 00:08:52,910 something there so I we parted there 142 00:08:52,910 --> 00:08:57,330 so we get here are more gone and never return 143 00:08:57,330 --> 00:09:00,330 be concatenated with me 144 00:09:00,330 --> 00:09:04,580 so this is the wrong time and Disney many good 145 00:09:04,580 --> 00:09:08,430 is a so this is like this SUT gol mutual recursion 146 00:09:08,430 --> 00:09:12,089 and very subtle I can even Eric made a mistake there 147 00:09:12,089 --> 00:09:16,470 so you better pay attention okay 148 00:09:16,470 --> 00:09:21,720 a las 10 here and her going to use a function 149 00:09:21,720 --> 00:09:25,520 define a function that tries to parse a string 150 00:09:25,520 --> 00:09:28,860 so far we have seen many examples very trying to parse 151 00:09:28,860 --> 00:09:32,740 a character but I want a bar a strain 152 00:09:32,740 --> 00:09:36,480 so if I want to am it might 153 00:09:36,480 --> 00:09:39,800 and remember strings are just list of characters 154 00:09:39,800 --> 00:09:42,800 so if i start red the MP lead 155 00:09:42,800 --> 00:09:47,160 well I just returned the ampule at the empty string 156 00:09:47,160 --> 00:09:52,380 and I'd try to parse is a character actor contacted 157 00:09:52,380 --> 00:09:57,360 well I tried to barge a character actor I Rieger you need ride to bars 158 00:09:57,360 --> 00:10:01,410 string that represents the rest of this thing and then 159 00:10:01,410 --> 00:10:05,500 II return 160 00:10:05,500 --> 00:10:09,080 the result well I found the neck 161 00:10:09,080 --> 00:10:12,959 I returned that and I return that so I just 162 00:10:12,959 --> 00:10:16,490 return district addicted checks rather dish during 163 00:10:16,490 --> 00:10:21,670 is the prefix of my input good 164 00:10:21,670 --> 00:10:25,850 so now we can define a parser that consumes alleged 165 00:10:25,850 --> 00:10:30,070 a wall or mortgages from a string so this is starting to become more like a 166 00:10:30,070 --> 00:10:30,990 no parking 167 00:10:30,990 --> 00:10:34,390 an actual language so what we do we do is we want to bar the list 168 00:10:34,390 --> 00:10:38,459 so we have to parse it and open brace and a close bread 169 00:10:38,459 --> 00:10:42,190 right not interested in those values are you don't see 170 00:10:42,190 --> 00:10:45,740 left arrow there memory trying to bargain digit 171 00:10:45,740 --> 00:10:49,020 and then we're trying to parse many 172 00:10:49,020 --> 00:10:52,360 character 173 00:10:52,360 --> 00:10:56,260 coma digit okay because we will devilish 174 00:10:56,260 --> 00:11:00,640 of wall or more digits so there's Wong digit 175 00:11:00,640 --> 00:11:03,780 and and them or digit here 176 00:11:03,780 --> 00:11:08,460 and then we just don't got in a dead they did but the other digits are you 177 00:11:08,460 --> 00:11:08,950 see 178 00:11:08,950 --> 00:11:12,150 how we got you know take old niece 179 00:11:12,150 --> 00:11:15,630 elementary barger and combine them together 180 00:11:15,630 --> 00:11:18,660 to ride a.m. already 181 00:11:18,660 --> 00:11:22,870 pretty complicated bars like this every 182 00:11:22,870 --> 00:11:25,950 a apply departure here on the list 183 00:11:25,950 --> 00:11:29,020 on the lead God strain 184 00:11:29,020 --> 00:11:32,520 but we want to barge that ring as a letter and 185 00:11:32,520 --> 00:11:35,690 we'll see let me get the and 186 00:11:35,690 --> 00:11:39,610 then just wanted 34 and and if we're trying to 187 00:11:39,610 --> 00:11:43,830 parted on something that hasn't you know at mother brother last 188 00:11:43,830 --> 00:11:47,280 we will get an error okay 189 00:11:47,280 --> 00:11:50,900 now courted head as you read that bitch is heard 190 00:11:50,900 --> 00:11:54,150 super simple barger and if you want a ride 191 00:11:54,150 --> 00:11:57,330 a real cars are if you want to you know our 192 00:11:57,330 --> 00:12:01,570 use a bar here in real God you definitely want to do something smart to 193 00:12:01,570 --> 00:12:04,660 render errors and Justin are returning the MTS 194 00:12:04,660 --> 00:12:08,500 agree you want to go to No if the position 195 00:12:08,500 --> 00:12:12,450 in the AM blessed right things go wrong are you a good ride to 196 00:12:12,450 --> 00:12:16,420 correct errors or whatever but again we're trying to 197 00:12:16,420 --> 00:12:21,070 go over here very very basics of parsing 198 00:12:21,070 --> 00:12:25,040 and there's plenty of parking libraries perhaps call 199 00:12:25,040 --> 00:12:28,960 and for other languages that are based on this day my dear 200 00:12:28,960 --> 00:12:31,960 that at all these more sophisticated features 201 00:12:31,960 --> 00:12:35,670 thank you very much and CEO 202 00:12:35,670 --> 00:12:36,320 an ex parte