So let’s go through a possible answer together. Once again, the real trick is just coming up with a good regular expression, so we can’t have a space, a left angle, or a right angle, but we can have 1 or more copies of anything else, and we’ll just return the token unchanged because that’s…
Tag: string patterns
Greetings – Programming Languages
Let’s see a slightly more lively example. There’s a lot going on in this example, and some of it you may not have seen before. I’m making a procedure called makegreeter that–and this is cute– inside of it defines another procedure. If you haven’t seen this before in Python, don’t worry, but it is possible…
Mis Msf – Programming Languages
So now let’s look at the problem another way, in reverse. Suppose this time that I give you the encoding of the finite-state machine. I give you the accepting states, just 6, and also all of the edges. What I would like you to do is provide me with not 1 but 2 strings that…
Escaping The Escape Solution – Programming Languages
Let’s go through this one in parts. Any regular expression starts with r’ or r”. I’m going to use the single quotes this time so that I won’t have to escape quite as many of these. Then we want to match the blue ” here at the beginning, and somewhere way at the end, we’ll…
Fault Localization – Programming Languages
So here’s the quiz question for you to give you a little more practice with this sort of advanced testing and debugging. We’ve got these 4 boxes here. Each one corresponds to a single line. Which of these lines could I remove, comment out 1 at a time, and still see the exception? I know…
Fill In The Tree – Programming Languages
Here I have a grammar that we’ve seen before, but I’ve abbreviated it still further. Instead of identifier, I’ve just written “id,” and instead of number, I’ve just written num. This sort of abbreviation is all too common in computer science. Programmers can’t help it. Unfortunately, it’s a bit of a vice, because while it’s…
It Could Be Worse – Programming Languages
Alright, so you’ve just finished learning how to specify tokens for languages like HTML and JavaScript. At this point, you might be thinking, boy, so those HTML and JavaScript designers did not make pretty tokens. I just want to mention an experience from my own life. It could be much worse. I once had the…
Token Value Solution – Programming Languages
Well, we just saw the code for processing these tokens, and we know that it went to a bit of trouble to store the beginning position, lexps, and then the ending position, but then–phwoomp–subtract out 9. So this is way too much. We went to a lot of trouble to drop
Anonymous Functions in JavaScript – Programming Languages
Now that we’ve seen this one way, let’s see this from a different perspective. [Brendan Eich, CTO, Mozilla] [Wes Weimer, Professor, University of Virginia] Let me ask you a question that’s actually of personal interest and curiosity to me. I’m teaching in this class a number of elements of functional programming, list comprehensions in Python,…
Wrap Up – Programming Languages
So once again, it’s time to summarize what we’ve learned in this unit. Just as English sentences could be broken up into words, so can HTML and JavaScript be broken up into tokens, typically separated by spaces. Some of the more complicated token types we looked at were number, word, and string. Since these correspond…