SEPTEMBER 29,  2015
ORGANIZATION OF PROGRAMMING LANGUAGES

	INSTRUCTOR:  D2L in particular, thank you, the fill in the blank format is very unwieldy, took more than 3 hours to get that question in there and still not like what I wanted.
	People can't see where they missed the points, that's the real problem, the way it's setup.  No way to show where you missed the points without showing the answer key.
	Yeah, let me, that's interesting, I didn't know the answer quiz was available to you all, I thought it was only the other section that had that there.  Let me double check on that one.  Getting setup, working, working.
	I see, okay.  I -- setup time for that, setup special access to the other section and setup access to everybody at the same time.  D2L trying to help me and fill in default values for me.  Oh, well.  No biggie.
	I'm not going to worry too much about that -- it was out there and so on -- but, go ahead and do it and see if you can get the answers, and think about and understand why the things are there.  I think if you're working, again side-by-side with Dr. Racket and typing in expressions which you need to do for homework 4 B anyway, you can check if all those things work.
	Not quite all, but the signatures, you decided on, but, a lot of people missed points in the other section for things -- if they typed it in, they would see that it was generating error and not a legal reply, so -- okay.  Let me try the -- webcam sharing here.  Try that for a bit.  So first, questions on homework for A or B, anything discussion topics?  Questions about why things are done the way they're done -- for the record I think one of toughest things, one of common mistakes I see, people have to work through, I go ahead and make a team structure, like book, define struct book and the fields, what are access, hyphen title.  I'm in a function, given a book I call B, I say call book title, open paren book title B.  People want to say, B hyphen title.
	-- like Java used to say, the variable, the object, object reference and method name people want to do the same in Racket.  No.  Name the function and function is book title like any other function, no different syntax going on here.  I have a lot of people in the beginning tell me one of access or functions for team and get it right.  If you're inside a function how do you grab, pull out the offense from one of the teams an get the wrong answer there.  So, that's what we're, that's one common sort of pitfall.  Again part of reason of doing this on D2L is work through that out, oh, right, that's what's going on there, so you're not running into that when you're actually writing the code.
	Different function that worked in tests.  So, not quite sure what you mean by that, but, I'll be looking for function that takes into 2 teams.
	I think interesting part what should be, so first of all, one very important issue that some people again the other section are having wrong, is that, I said write a function that takes in, one team is better than the other.  Yeah let's have a function that does that.  So what input should it take in.  How many inputs and what type of input.
	What I want the answer to be, you give that function 2 teams, not I give it 2 strings and 4 real numbers.  Some people sort of say that.  The whole idea of making an instruct team that holds a string and 2 real numbers is so we can wrap it up together and say, this is one object.  One thing I can pass around this as an unit and get it back.  Get back team objects.
	Not returning 3 thing from the function, returning one object that has several fields.  So -- sure, go ahead and put the stub up of what you're trying -- yeah, that sounds exactly right, team greater than takes in 2 teams, yeah.  And then the stub would be there, and what's the return type, I guess is the issue.  -- false is to finish the stub -- what you typed in there Steven is what I call the header, but then to make it a run able code so I want to finish off define, I need to put some default answer in, so I put false in as at default answer.  -- so what am I thinking of as I return type for this function.
	I'm guessing Boolean, this answers in question mark, like string equal, or strange greater than ends in question mark.  Symbol, question mark, all these function that's return Boolean, that's another cue.  Okay, I'm given this problem, 2 teams and figure out if one is better than the other, dominates the other, yeah I'll take in 2 team objects, and best way to phrase the answer is true-or-false.  A lot of people say I return a string or string of the team name or something like that.  And I think, in, so now imagine this, running this website, massive online sport's simulation game, one hundred thousand clients they have team objects going on and now one hundred thousand teams and another one hundred thousand teams and I want to make a billion calls to team greater than to see which is flat out better than the others.
	If I have to do billion function calls to figure out which team is best I don't want to have to go through and look at a bunch of string to figure out the answer.  I think, returning a Boolean is the right type, is one team better than.  Think of function string greater than.  Or greater than for 2 numbers.
	Is the first bigger than the second, not return the number which is bigger.
	So -- yeah, less concerns about greater than and less than.  But think about, you know, string greater than, I guess that's the function between max and greater than.  Max returns the bigger of 2 numbers.  So, do don't sweat this too much, but I think that is, wasn't quite spell that had way, it was intentional, to sort of do that.  And if you want to say I want to change it, you can change it and submit again to D2L, I'll take the most recent submission before the dead deadline.
	Okay.
	So, yeah, and then, Steven suggested in private a solution to me, and that looks, reasonable, -- so you should have special access to the quiz, not solution quiz but quiz 4 B.  No.  No.  No -- the 4 A was that part due today?  For us?  -- by class so we can talk about 4 A?  -- I think that had been the deadline all along, right?  Yeah.
	And so you should be able to look at your attempt, but you can no longer start it.  If you're like, I didn't know that was due, send me an e-mail and we can work around that.  And 4 B is due tomorrow at midnight for you all.
	The purpose, iron out things, what's the name of instructor how do you make the examples and all of the things I want in 4 B.
	And, the reason is, I can make extension, the reason I do that, I want to be able to talk about it in class.  If enough people I understand you have lots of things to do, but, so if I don't have it due by class, some people haven't looked at it by class and now they're falling a week further behind and talking about new stuff and never had seen the old.
	I do not have the grades back on the other one.  I'm slowly digging myself out of a hole I hope this week I'll make progress on things.
	Yeah.
	Yeah, and we'll see, have some solutions, put more solutions up too, you can compare and see if it looks close or similar.  So yeah, I'll be getting solution sets out and can I look at some things.  Particularly in if you have particular questions, you can send me an e-mail.
	And I'll take that into account while grading somewhat.  I hope the designer, make it's pretty clear what I'm doing.  And examples we worked through in class, that's what I'm looking for, exactly the things we're doing in class I'm looking for in homework.
	When I say what is the signature, examples in data, these sorts of things.  I try to do exactly in class what I want you to be doing on the homework.
	Okay.  Other questions on -- on the 4 A?  Or the 4 B.
	We can talk briefly about the asteroids ever I can take a few minutes and talk about a different setting and what sort of answer would I be looking for in that setting.
	Wonder if I can setup a pod.  Let's wait and do this.
	I'll double check the auto grader.  It, does pretty well, if you left out spaces on things, if you have, you know, like define struct team and, I write define struct, team, space, open paren, and fields, if you leave off spaces and doesn't look like the notes, for example, then the auto grader doesn't catch that, and, I'm going to, yeah so try to indent and so on, like specified on there.  But, yeah, I'll double check the auto grader, it's pretty close overall I found.  There's times when I added a few points back on some people's.
	Okay.  Looking for -- just a quick exercise on -- design issues.  So look at a different game, what's one you know?  Like pong?  Is that a -- do you all know the game pong?  Or is that too old and classic?  So -- and we can go and go to congregate.com and search for pong.  First video game to hit the arcade.  First video game that made it out there, made it big.  So, in pong, what are some of the objects we might have going on in our program?  
	Let's see if I can -- like a new page here -- 
	So, in pong, what objects or struct, so the left paddle and right paddle but not class paddle right paddle.
	We would have class paddle, and class ball, that's it, pretty basic game.
	For a paddle, what might we need to keep control.  What fields might we have.  Something pong, where you have a field, balls bouncing left and right and moving paddles up and down, so directional?  X and Y, not sure what that means?  What type might I use for the X and Y coordinates.  Yeah, maybe a double and I'm measure ting on a scale of 0-1.  Scale to any screen size, might say it's INT and might be bad dl location in pixels.  That might be reasonable way to do it.  Figure out data type, representation.
	Anything else we need to keep track of?  -- about a paddle too.  So keep track of ball, so paddle size, so, for the paddle -- it will change, we will move the paddle up and down in response to key on keyboard, but not a field inside that is maybe the movement.
	Unless you want to have paddles glide.  If you hit the up arrow and paddle keeps glide to go the top, until it hits the top.  If there's continuous motion, that's something we need to remember.  If you say, hit up arrow it goes up and hit again it goes up a bit and tap, tap, tap, up, up, up, that's not really, information that I have a feel about.  The deflection angle.  Acceleration, deceleration, again there are different games.  My inclination, for accelerate and decelerate, I'll move in response to the keys, unless I'm gliding, that won't really be a field.  It's positioned, I'll change its position based on key presses.  Yeah, the ball probably has.  So I like that.  The ball will have maybe an inter INT X and INT Y.
	So how fast.  We saw different things, trajectory and velocity.  I think the word velocity means both speed and direction, which I think trajectory means.  So.  Okay.  Come back to SEAN's comment.
	The ball does glide we have to keep track how fast it's sliding or speed up and speed down, so it might have a speed.  Any time I have numeric field should probably have units going on.  In, pixels per frame or something like that.  Speed of the ball.  Acceleration of the ball.  Acceleration, speed, if all I keep track of is speed and maybe I have that speed stay the same, do I need to keep track of the acceleration, acceleration is the change in the speed.  Well as the ball moves along I'll probably not be accelerates, I think initial pong kept ongoing, when you hit paddle you change your trajectory, velocity very quickly.  The speed, we also need, direction.
	Which again might be doubles.  And in fact, if you're a physics person, you say I can get the direction and the speed, direction of plus one and 0, direction of X being plus one and Y being 0 might be straight across, ball moving across might be plus 5 and 0.  You can wrap up together, yeah, that's okay -- if you go to program that doesn't need physics you don't need to know physics, pong, very elementary physics going on.  I might in pong, instead of keeping track of the speed as an unit and then its the angle, I guess I can keep track of speed and angle its traveling it at and that tells how fast to move a cot the screen or keep track how fast moving in X and Y direction.  -- use terms to impress people at parties, usually convenient to keep track of, how fast its going in the X direction and how fast it's going in the Y direction. 
And pixels per frame, something like that.  That might be reasonable.
	And, if you can keep, track instead of the angle and direction, you need to keep track of, first of all angles and degrees and units, degrees from what?  North?  East?  Whatever?  What if the ball misses the paddle.  -- so for ball misses paddle.  And what would the type of that field be?  I'm not sure what the -- I know the ball can miss the paddle but what information do you want to keep track of?  
	Somebody else was asking about that earlier, too, right.  INT of XY position of paddle, I don't need to keep, I'm already keeping track of where the paddle is, where the ball is.  If the ball is out of play, if I ball goes out of play, you lost.  The way I think of pong, I'm not going to have maybe, I could have a Boolean is the ball out of play or did somebody lose, no, my game is when the ball misses a paddle we stop of game, increment a score and go back to a regular pong game.  I never have an object where that is a ball out of play that would be true or something like that.  You need to keep track of score.  But that's not part of paddle and ball.  That's a good thing we need to keep track of.
	So score, we need to keep track of that, just finishing up with ball, keeping track of where it is, direction it is, somebody asked about acceleration, and again, this is, you know, I guess it will accelerate when it hits something, angle when it deflects?  Well I'll calculate ball comes in certain angle and deflects at certain angle, might have funny physics, the deflection is determined whether the paddles is moved or just moving or where on the paddle you are, or you can -- that's not just a field, that's something that will happen, but not information we keep track of any given moment.
	Somebody, I'm playing the game and I have to go off and eat dinner, great, I'll hit pause, or quit the game but write down everything, the entire state of the game.  Exactly how everything was, where is left paddle, X and Y, where is right paddle.  How fast was the ball going, etc... -- I'll write down everything and I need to write down just enough information so I can totally resume the game when I come back.  So keeping track of how the ball is going to reflect depending where on the paddle, that might be in the rules of game, I don't need to write down so I can resume this particular game.  It bounces the same every single game, the way it reflects is calculated the movement it collides.
	I don't need to coop track of are things colliding.  I can look at position of paddles and realize -- I can deduce that by looking at information I do have.  The play field boundaries, as it changes, as the game progresses, write that down to be able to resume game after dinner, they'll be information about that, but not part of paddle or ball.  Probably be a named constant.  
	So, okay.  So, probably something like this would probably be enough, just the ball -- one last thing -- if you remember physics, what's Newton's second law?  -- maybe it's his first, I don't remember which it is.  I'm asking and people will answer and I can say yeah that's the one I'm thinking of.
	Inertia?  Yeah, inertia, and object in motion continues in motion at the same speed unless an outside force acts on it.  Then there's quantified version.
	F equals MA, how much does it change the speed.  If equals MA, how much the speed is changing per moment.
	Yeah.  So Newton's Law is saying, you don't keep track of position, keep track of velocity, speed which we can do with X and Y directions, but you don't need to keep track of outside forces.  The ball -- anything else that affects the ball is outside of the ball.  It will continue in motion at that same speed unless an outside force like a paddle acts on it.  So nothing intrinsic to the ball.
	So new stone's, saying, hey programmers keep track of the 0 derivative of the position, first derivative, the velocity, and that's it.  Anything more, second derivative and higher are outside forces not intrinsic to the object and shouldn't be fielded inside the object.
	Okay.
	Pong was played in a vacuum, yes, same speed until outside forced acted on it.  But outside force is air in an atmosphere, so it works in the air as well.
	Anyway.
	-- one more, class game.
	The overall game.  This is where I might keep the score.  In fact if 2 players, I might keep track of 2 scores, something like that, I'll leave it as score.  What else does the overall game need to keep track of?  Sort of stuff we already talked about, right?  The overall game object will have a score, it will have, yeah, if I want to keep track of score, you know, P one score and P 2 score, and also keep track of, what is the game have one of?  It has one ball object inside of it.  And, it has, 2 paddles inside of it maybe.  So I'm thinking of something like this.  A game, is itself a structure, it has a score for each player, it has one ball and 2 paddles.  And if you look at the screen, each one of those takes up visual real estate, so pretty direct correspondence.
	I can have a class that contains other objects as feels no problem.  All of these, I'll let you write the exact same thing a define struct.  We'll take one example.  This is the paddle in Java, in Racket, I'll do the -- I wouldn't say class paddle, I would say define struct.  That's the word in Racket that makes a new object.
	Call it a paddle and give it field names like that.
	And might add, -- the fact that the these X and Y are integers.  I still need to know that in Racket program.  It will be in comment.  and this is the way I put it in when we did the book and DVD, this is the format that I used there.
	The word data definition, again, I'm making a new type, adding new type to the whether in Java or Racket.  When I'm in class game, I have a field of type paddle.  Why?  Paddle is brand new type I created earlier.
	Okay.
	Anything else?  I wanted to mention.
	You have velocity as vector, yeah, this is really a vector, keeping track of X exponent of vector and Y component of vector, one might could correspond to going NW on the screen, X and Y velocity might mean going Northwest, going Northwest 5 times faster.
	Anyway, that's vector arithmetic from your physics one.
	So, those are my thought beside this.  So, looking at asteroids game, I chose that because it was most popular in get to know you quiz.  I think it's feasible, I think it's scaled back, not asteroids, space invaders.
	Pretty scaled back space invaders, I'm not after trying to make it polishes thing, I'm after getting certain programming concepts, including what we're doing here data representation.  Think about what sort of objects will they have and fields will they have.  One thing to note -- anything, I'll put this in comment here -- any, I'll call is in variance data --something never changes -- don't make it a field, repeat myself a guess.
	For example, imagine, one thing that we didn't mention is, we sort of struggled on this, how big is the paddle, should I have how big, INT in height in how tall is paddle, what is this note on the bottom indicate?  Should have I it as a field or not?  
	Well, turns into the question, in the game pong, does the height of the paddle ever change?  If it never changes, make it a named constant and it's not a field.
	If you're playing a version of game where it can grow and shrink based on what's happening, maybe power up and that's a new class, oh, thank you, we should be recording, and you can think about, hey I'm going to have, what if I had 20 different paddles going on.  You think about that and they're all the same height, then yeah, height should not be a field of that.
	Okay, definitely thanks for the reminder.
	So, these notes here, I'll try to see if I can make it all bigger, so people watching the recording that just started, can go ahead and read that.
	So I think I asked for, I forget if I asked specifically for Java or Racket definitions of these things.
	Regardless give me whatever I asked for.  For the, oh, yeah, got practice doing one of each, for the game of space invaders.  And again, if you height doesn't change, if all paddles are always the same height, don't have 2 paddles and have constant sitting in each of them.  That's redundant information.  We don't like redid you know didn't want information, that means they could get a skewed somehow, we don't like that.  Always stays the same, don't make it a field, might be a name constant.  If it might change, then make it a field.  Say I will have paddle that's change size, it won't -- you might want it to be the height, field within a paddle.  If you have 2 paddles and they both are going to change with the phase of the moon or how long the game has been played, you again, you might not have individual field, every paddle is the same.
	I'll put that there, too.  If, some value is, inherently the same for all objects, even if it changes overtime, it should not be a field.
	I guess I should say using object-oriented terms.  It could be a, class field, in Java, static field, but, it, should not be, and, instance field, which is what field basically means.
	The shields, how will you represent the shields, good question in space invaders.
	They don't move but they do change and how do we keep track of that change.  We don't need to keep track of any movement or motion, but if I have 3 different shields do they all have the same location?  No.  They have different locations.  In that case they're not the same for all objects.
	I have 2 different shields, whatever you call them, houses, space invaders, yeah, and, they have different locations.  I know they're not moving but, different objects have different values.  They're suppose to.  So that would definitely be a field you would want.
	So, changes across all objects, I should say.  
	Really of these 2 things here, I guess, that latter, I think I'm trying to say the same thing both times, -- saying for all object, which should not be a field.  That's, what I'm really after -- okay.  And you can always imagine, what if I had 5 different balls going on the game.  Make super pong and then ask yourself, what thing each ball that's that different.  Those would be fields.
	If they're all 5 balls still all be green, then great.  Don't make that a field, the color of a ball would not be a field if that's what it would be like.  And, that always spurs interesting designer things --what if I do have more paddles, what is the same -- and so on.
	It might be too snazzy and fancy and not fun to play, so -- if it's changing and changes overtime, then, yeah, you -- might be an object you make out of it, okay.  That's a little bit on design philosophy and thinking about this all tying back into, this is really step one of designer speed, how do I represent my data.  I'm asking you to do some program, (Inaudible) data representation.
	If compound time, choose compound type, if union, choose union and define what that is, and give examples of data.  First step, how I do represent my data, do I use compound, union type, or built in primitive type.  Sometimes I can say, yeah, that's going toe be represented by in title, need to make a new class for it.  Okay.
	Yeah, that's the thinking there and how it relates into what we're talking about.  Okay, so -- start the next phase, for about 15 minutes before we take a break.
	I want to switch gears and talk about -- syntax.
	And parsing.
	And I'm going to leave and come back to data representation.
	As one last reminder before we leave in rearview mirror error for one week, we ended up, we talked about union types, we talked about compound types, what was the last time of data that we talked about, the last template that we wrote?  Do you remember?  We did, talked about book, and that was a compound type.  And talked about DVD, another compound type and then I think we finished with an union of compound types.
	We said we had a library item.  Or inventory item.
	And that was either a book or DVD, now back to that union definition, one of these or one of those.
	Okay, great, if I write a program that processes library item I have a COND that 2 types, so I start writing template.  COND with 2 types, do I have book or DVD and go further, if I know I have a book in that part of COND I can pull out all the fields that a book has, and that's part of template, something I'll want to do a lot.  Similarly if I have DVD in that branch of COND, once I know I have DVD I can pull those fields from that struct, if I have an union of instructs I can do a fair amount of code in my template.  And that's about as big as you make the template.  If you make it anything bigger you have to break into sub functions.
	We'll come back to it.  We'll come back to things like library item.
	Union, some of variance of union where themselves structs, all I'm doing, is 2 types of label blocks an overlapping them a bit.  Okay.
	I want to move on to, a new page of notes.
	And then talk about syntax.
	For a while.  In particular I want to talk about syntax, versus semantics.  I guess the title is syntax, grammars and parse trees.
	Syntax was grammar rules for language, when characters in file, when is legal Java compile or not.  That's the syntax.
	And semantics is different question, what should the program do.
	What exactly is the meaning of dual statement.  What are the semantics of throw and catch, what's suppose to happen in all of those different situations, that's semantics, we'll focus on syntax.
	And in fact.  In computer science we like separating different phases.
	Looking at program and making sure it has the right syntax and building that data structure and then worry about what are semantics and what to do with this program and we'll separate those in entirely 2 phases.
	-- valid programs or valid strings.  By using a grammar, in particular a context free grammar.  And if you go to the web page and look up the notes, let me pull that link, real quick.  
	Probably all there before I am.
	I don't have all my bookmarks, using different browser --
	Okay, start with this.
	Reading assignment in the book on top of that -- okay.  So -- in the notes, there's a page, I'm going to start with talking about grammar, let me work through an example or 2 and then go back and say what are the exact rules, so I'll push informally until we have a sense of what's going on and then talk about what are the exact formalization.
	Let's see -- if I can pull up window in a way that helpful to me -- so I'm going to make a -- hold this out here, see if I can paste it in.  Okay.
	I'll name this grammar G one and it is a set of 4 different rules.
	And I'm going to go ahead and say, I'm going to make a sentence that follows these rules and here is how I'm going to do it.  
	I'm going to start with S and say, I'm taking S and replace it with -- take S and replace it with, on the left-hand side of one of those 4 rules on the top of grammar, choose one of those and replace it.
	Replace this -- with NV -- now I'll do the same thing, I'm going to continue.
	And I'm going to replace, take one of the, NVN I'll choose one of them, I'll choose the V in the middle.  I'll replace V with one of things on right-hand side of the middle.
	It says, vertical bore, that's OR, and shorthand for V goes to bites or V can go to hit, it's a way to collapse 5 or 6 rules all into a single line.
	I'll take the rule of V goes to jump and I'll replace, the V with the jump.  Can you see that on the screen?  When I hit return it update it's?  Okay.  Let me know, if things are not updating or scrolling, let me know.  Okay.
	So, should be on the notes 17 pad, and I have a line that says N jump N at the bottom.
	That's where I'm working on.  I'll add more things to the bottom of that.  Those next few lines.  I have no idea, fits on my screen, but I'm not sure how that works -- I think if I go ahead and move, if typing at the top it's okay.  I'm going to go and rearrange, paste stuff from the top and put it down to the bottom -- 
	And now hopefully, I have up at top, the stuff we're actually using and I'll be updating near the top then.
	So can people see the N jump N line?  -- okay.  So now, I'm going to continue in this little game here, and what we're doing is making a legal sentence according to this grammar, not really program language, but -- okay.  Of that N jump N, I'm going to copy and paste it, I'm going to choose one of the 2 N's, I'll choose the last one, I'll choose that N.  And I'm going to say, go ahead and replace this, that N with anything on the right-hand side.  And again, there's rules and I can replace N with cat, UFO, whatever I want.
	Hot dog, okay.  And now, here is the thing.
	Every single step I choose one of the non terminals.  One of the capital letters and I'm going to go up to those 4 rules at the top and I'll choose any rule involving N, in this case, and replace the N with the right-hand side of the rule.
	So -- so that would give me a sentence, what does it this all mean?  That the sentence android jump hot dog is a valid sentence according to grammar G one.
	It may not be an interesting grammar, but that's the rough idea.
	Here's the rule for making one step -- a derivation.  Take your string and find a non-terminal in it, a non-terminal, starts with a capital, is the left-hand side of the a rule, okay -- and, also choose a rule for that non -- that non-terminal on the left, and replace non-terminal with the rules right-hand side.  And by -- rule -- meaning, a rule of the grammar.
	Involving the single right arrow.
	Okay.  And so we have 2 things here, we have the general rule and a derivation, we can do another derivation.  Let's derive another string from the grammar, start with S, take my string or string only has S now, it's boring.  Choose one of non-terminals, capital S is non-terminal.  Great I'll choose that one, since only choice.  Find one of rules involving S, there's 2 rules involving S, last time I chose NVN, this time I'll choose the NV rule.
	Okay, replace the S with NV period.  Fair enough.
	And now I'm going to go, say, hey choose one of non terminals, I'll choose non-terminal N this time.  Take that N and replace find a rule involving N, and we have, what?  Rules involving N and N goes to cat, or UFO or apple, choose one of them.  I'll choose N goes to UFO and replace the N with UFO.
	Carry along the V, carry along the period.
	Okay?  That's important.  Don't leave those off.  People leave those off and I have to take off points.
	The game is replace the N with something on the ride-hand-side with a rule involves N and similarly, take this, string UFO period.
	UFO is already a terminal.  Period is a terminal.  Capital V is non-terminal.  Find a rule involving V and do the substitution.  Okay.  I'll take the rule that V go toss spin, and I'll take my string UFO V and substitute spin for V.
	I end up with the UFO spin period.  And that's valid sentence from that grammar -- do those rules make sense?  I know it's lame.  But we get a lot of mileage about this thing here.
	Okay, actually I'm noticing it is one hour into it, -- hopefully this will be all straightforward.
	We'll take a break.
	And come back and say I want to take this grammar and I want to be a little fancy and adverbs, and adjectives.
	Tweak the grammar rules to get a new grammar and see if we get more interesting sentence that's come out of there.  Let's take a break and come back 6:49 p.m.
	And I'll be sitting here, listening and monitoring if people have questions.
	[Break Time] 
	INSTRUCTOR:  If particular if I write blah-blah-blah, and then a double arrow, BLURBGLURBGLURB, blah blah, bunch of stuff I'm not specifying, it means that I can go from the string on the left to get the string on the right, by just replacing an one non-terminal with the right-hand-side of a rule for that non-terminal.  Read that slowly to see if it makes sense.  Spelling it out almost makes it sound more complicated than it is I think.  We had N jump N period, goes to N jump hot dog period.  I can go from one string to the other by choosing one of non-terminal and replaces with right-hand side of the rule for N -- yeah I have hard time managing all the questions, I try to get to them as I can.
	Okay.
	We have the general rule, let's go back to the grammar and now play a slightly different game.  You sometimes which you could have the S at end, letter for a verb.  How can you do that, modify the rules a bit.  I want to modify the rules a bit.
	Like saying, hey this expression is equal to that expression is equal to that expression.  One thing I warn against in doing derivations, people leave off chunks much string, that boring I don't want to rewrite that.  You can be smart and use copy paste to avoid a lot of rewriting.
	And don't put that double arrow between 2 strings unless possible to go from one side to the other by doing a substitution according to the rules.
	In particular don't magically leave off some of the right-hand side and 5 steps later add it back in, because you think it should be there again.  Say exactly what we mean.  This string can derive this string in a single step according to the rules.
	And period can go to N jump hot dog period.  Don't leave off a period several steps and forget to add it back in.
	I have to say, in my example I'm playing fast and loose where spaces go.  So -- I'm not going to worry too much about that in here.  In Java, it's tied in, part of the language grammar.
	I want to go and adverbs to say, verbs can sometimes have an S on them or not.  I can conjugate a verb by adding S or stem of the verb, conjugate it by doing nothing.
	I want to have a new notion of a conjugated verb.
	It can be a V followed by S -- or another rule involving CV, you can just, con gentleman gated verb can be a verb followed by S or a plain old verb.
	And I'll leave it here.
	How do I go back and change my original S formula?  It can be a noun followed by a CV period, or N volume by CV and followed by another N period.
	And you're right, I'm thinking of N standing for noun and V for, really look, the computer doesn't know that, the computer can go ahead and can I give it a string and say hey, is that possible it generate the string starting with S with a bunch of steps.  It will be yes or know, not knowing what V and N stand for.  This is all symbolic.
	So, so maybe Steve, you're saying CV, let's -- get examples.
	Go ahead generate a string involving this new grammar for me.  In your note pad, look how we did the, down below, how we had done the, what was the final string, android jump hot dog, something like that.
	Yeah -- see -- give me any string that is in this grammar.
	Can anybody maybe, intuit, string for this grammar.
	For the old one, G 2, android jump hot dog period was one such string and you showed the example.
	-- so cat run -- so let's see, with period at the end.
	Let's see how we'll get cat run out of that.  See if that's true.  Use that double arrow.  I'm doing notations.  So everybody else, we're trying to either see if Chris is correct, verify if he's correct, if not, then we'll be -- can we get cat run period, starting from S.
	What should the first rule we apply.  S ask only non-terminal.  2 rules involving S, which one should we take if we want to reach cat run period.
	Yeah, I think, N and CV period.  Exactly.  If you we choose the other one I'm guessing we'll have too many words an never get down to cat run period.
	Okay.
	So yeah, and now we can go and can do copy paste here.  Let choose VC and replace with something that is going to -- I'll choose of N, and throw in one more term here.  In a -- left most derivation, when we choose a non-terminal to replace,  out of all the possibilities we can -- of all the possibilities we choose the left most one.
	If cur doing that, it's called a left most derivation.  There's many, many valid, -- there can be many valid derivations of the same result string.  But, there's only one left most one for it.
	And I'll see, the only reason I care about left most derivations, when I'm grading it way easier if everybody answers in the same order.  So that's why I'll sometimes request you to give a left most derivation.  I'm going to leave that, again, up here, we have, NCV period, I can choose the N or CV, I can choose any non-terminal.  Dot is not a non-terminal.  But no rule up on top that let's me turn dot into something else.  So that's a terminal a guess.
	Out of N and CV, we change N and we want to end up with cat run.
	Is there a rule that says I can replace N with cat?  There sure is.
	So, a go ahead, and cat CV period, getting close to cat run period.
	What's the next step of derivation, here is a common mistake, people say let's turn CV into run, is there any rule that says you can replace CV with run in a single step?  No.  There's only 2 rules involving CV, take the CV and choose one of those 2 rules.  Which one do we want to choose?  Yeah, just CV goes to plain old V and then choose, now there's a rule that says V goes to run.  And, we have this system.  Sure enough, Chris's suggestion that cat run is a sentence is correct.  How about, now I'm going to go and retroactively change what we did, how about the sentence cat runs.
	Is that a sentence in here?  Cat runs?  Yeah.  When we replace nd step, I should number these derivations -- test my Roman Numeral counting skills -- I'm putting Roman Numeral so we can talk about lines.
	-- 3 and 4, I'm going to say replace CV with VS.
	-- and then online 5, I do the same thing, replace the V with run, and I get the sentence, cat run S period.
	I won't worry about the spaces.
	Cat run, this grammar can generate cat runs.  And so, what's, interesting to note and I should label rules as well, and I can even go ahead if I label these rules, go ahead and write, by rule, it was A -- by rule -- oops I didn't do anything in step 2, I guess I copy and tasted without doing much -- I got sidetracked by talking about left most derivation.
	What rule lets me take N to cat, that was rule E option one.
	What rule let me replace CV with V space S -- by rule C.
	And last one, V with run, that's by rule F, option 2.  Okay.  So I can go on each line of derivation, can I tell you exactly what rule I'm applying to get there.  Good way to keep yourself honest.  People skip steps and people don't repeat the entire string, they leave parts off and maybe magically add it back later because they know they needed it in the answer.
	What else do people do?  -- yeah, I guess skip steps, go from, you know, 3 to 5, according to my numbering, Roman Numeral 3 to 5, without realizing their skipping a step.  Do it in their heads sometimes and rush forward.
	I want to be leer we're doing just one step at a time.
	So, how do people feel about that?  Do we keep the space between run and S?  Yeah, again I'm not going to worry about space, we should go to grammar rules, the reason I didn't write rule C without a space there, is because I'm like, capital V, small S is that name of non-terminal that's named capital V small S or 2 things with a space between them -- so, I wrote it with spaces and I'm not good to go worry too much about it.
	But now I don't wa to say, take another example, this example is about a caveman language, not interesting.  We'll come back and make it more interesting in a moment, but that goes ahead and does something.  It's -- to keep you all from scrolling down, I'll add blank lines in the top and start a new.
	Let's set aside caveman language for a moment and use a different caveman language, Java.
	Let's see if we can come up with a grammar that captures variable declaration in Java.  Can you give me some examples of the data.  Give me examples of Java code that declares a variable.
	I want at least 3 different examples, so a lot of people can type stuff in.
	Yeah -- INT X, I like that.
	Public INT N, INT, FOO.
	String, any string hello world.
	And then you have Boolean.  I think very subtle thing, actually an a reserved word in Java, -- Boolean keep going.  That's actually as written wouldn't quite compile.  We need that semicolon at the end of it, okay.
	So -- those are examples.
	What is the general pattern, somebody says, I want to get rid of this public N for a second, come back to that.  Here I'll comment it out.
	First 3 examples, can we come up with general pattern what is allowed to be a, think, yeah, a type followed by name.  So -- let's come up with general rules.  Type, followed by name.
	Now we can also have type, rule for type -- type can be one of INT, string or Boolean or float or chart.  Etc...
	Let's leave it at that.
	We're going to be, not capturing full Java and come back at the end, sand say where have we failed.
	Imagine this, INT, string, Boolean, type by name, name I'll go ahead and I'm going to postpone this here, I'm going to say, all name -- for name, all the rules about what is a valid Java identifier.
	It turns out the rule beside what is a valid name in Java, they're not that complicated but a little complicated.  We can come back to that in a moment.  There are rules, 3 or 4 rules for names an we can come back to those.
	Let's pretend we have all the rules for names.
	What about the this rule for variable declaration, are we happy with this as our grammar, is this first one, can we derive the first one from this grammar, yeah, not quite, we need semicolon, type, followed by name, followed by semicolon.
	Okay.  That's great.  That will, from that can I goat that first example in X semicolon?  Yeah, replace type with INT, name with X, that's valid Java name, I can come up with INT, X, semicolon.  Similarly Boolean keep going.  I can come up with that one as well.  What else do I need to be able to handle.  The middle case, have to do a little bit of hand waving but what do we need to add to our language?  To our gamma?  -- that line we have is pretty good.  So, let's, sort of imagine we already have something that can be any expression, which might include a string literal.
	So -- expression, a bunch of rule beside valid expressions.  Still need something, empty string is valid expression, any constant is a valid expression, as well as, expressions can be like 2 plus 3 -- or hello plus world.  Those are both expressions themselves.
	So how about, I like this rule here, variable declaration, -- but it's not enough.
	Followed by 0 or more expressions, no, not quite.  Paren, I don't see any parens in my example.  I'm fishing for, we're going to need another line here, another rule, that starts with a type all by name, but doesn't have semicolon.  What do we have after the name?  Yeah.  An equal sign, assignment operator, and then expression.  And then semicolon.  This I think now, this is sort of in the ballpark of what we want.  And so, again, think of this as, you know, a conjugated verb followed by V or S, typed, name, semicolon or do initiation at the same time.
	Type, followed by name, followed by equal sign, the capital T type, that's -- that other rule we have down here, about -- what is a valid type, what is a valid name and expression.  We haven't filled in those details.
	The equal sign is a terminal.  It's just, the jump in our cave language, equal sign, literally, equal sign character sitting there.  That's what we need.  Again, I'm not worrying about spacing here.
	So, first -- why, so, there is something you can do in Java, right?  You can say there's other things we can do.  We can do, INT, X, Y, Z,  let's ignore that for now, it is there, we'll figure out how to do it, but leave it off for now.
	How do I go ahead and take care of fact that I might have the word -- public or private -- in front of it, but I don't need the word -- public or private -- in front of it.
	Yeah, optional scope.  I want my grammar to say, just sort of say, we can add an S at the end of a verb but we don't have to.  We want something similar here, we make another rule, what should that rule be?  Might need several new rules.
	And then go back later and see if we can simplify it.  No rule beside scope?  Well, -- no rules about scope?  I see what you're saying, yeah, but see if we can, give me an actual honest to God rule, non-terminals in capital letters?  Okay.  So -- so we have a couple of things coming in here, Chris's, and Sean's version, Chris says take this and I'm going to copy that middle rule and add -- call it a scope.
	I'm going to call it a, visibility, it's kind of like scope.
	I'll call it visibility.
	So I can have a type name semicolon or visibility type name semicolon and, (Inaudible) this type name, semicolon, and visibility followed by that.  And what can visibility be?  -- yeah, public or private or protected.
	I like that.  There's a bunch of them, but there's 3 of them.  There's a fourth one that people call package protected and that's what you get if you actually leave it off.  And I'm not going to worry about that.
	Okay, so -- yeah, we have this, visibility, so now we have 4 rules and visibility, private, protected, now we captured whether or not you want to add public or not.  We could do INT, X.
	Or public (Inaudible) by using the, new versions we just added.
	Okay.
	So this is Good.  When you look at these rules, what strikes you slightly regrettable about the 4 rules involving variable declaration, there's a lot of repeated code there, this works, but a lot of redundancy, can we factor out some of these redundancies.  I like what Sean was saying, I'm going to make something called visibility OPT -- change the name a bit.  Maybe I should leave this here --
	Works but -- just so we leave in the notes.
	By the way when I look at that, we, this has, grammar that involves, 1, 2, up -- sorry, 8 different rules, and actually some of them left vague about name and expression and even type.  We didn't completely fill N okay, I like now, what, when it gets minimized some of this -- I'm going to get rid of that first one much.  Typed name, visibility optional, by type name, and similarly with the, make a new non-terminal named visibility OPT.  Here is how I'm going to write it.  Visibility OPT can be the word, public, private, protected or it can be the empty string.
	Well, I had a hard time writing empty string in grammar, there's actually common convention, and if you're taking 420 or have taken it, you've seen this.
	Most people here have not done that.
	People often use the Greek letter epsilon to denote the empty string, lower case epsilon.
	Let me put that in here.
	Now we've got from 4 rule beside variable declaration, 2 rules for variable declaration but we added one more option, turned individuals ability to advise ability OPT, that make it's optional visibility.  That good, we got rid of 2 and added one more case.  That's cool.
	We still have redundancies by the way?  -- yeah, the sort of assignment is optional.  Exactly.  It's, I like that.  So yeah, I like the way -- I like that way better, I'm going to steal Mark's approach.  We always have visibility type name and end in (inaudible) and initialization part.  And then I have rule for INTOPT and that's either, either the empty string like we had before, or equal sign followed by expression.
	Here is a question -- do I need a semicolon in this?  You know.  Initialize optional rule or not?  Yeah.  Okay, some question, some no.
	Another no.  Let's find out.  Go ahead and give me a definition for this, give me a derivation of this string, my string is hello world.
	Using our new improved grammar.
	So even if we can't do it, go ahead, Chris is like, I have to write rules.  Never mind, never mind I didn't say that.  Let's do it anyway, give a derivation for string, my string, hello world.
	Can we go from (Inaudible) through a bunch of rules -- can I be different and say -- INT, N -- 17 plus 2.  I choose this because it doesn't have uppercase letters in it so we don't get confused about terminals and non-terminals.
	Yeah, so the semicolon, take out semicolon, exactly right.  The semicolon is not part of initialization, it's part of variable declaration.  That's one way to phrase it.  So go ahead and give me rules starting with VarDecl and end up with INT, N, 17 plus 2.  That's cool.  I'm more, let's pay attention to it and think about what's coming from where so we're on top of these things.
	And let me name my rules -- rules A, B, C.
	D, E, F, okay.  So -- somebody give me the first VarDecl what is the on the right-hand side of my first step of the derivation?  -- this is where you guys are big disadvantage because I can't, you can't copy and paste, there's no rule saying VarDecl goes to the thing that Chris just typed now.  In fact there's only one rule involving VarDecl and it's that.  And I have to use it.  Remember, by rule A -- so I'll annotate for our fun.  Which rule we're using.
	My first thing will be this whole visibility OPT type name.  Left most derivation, the game says, hey out of this whole string I have, visibility OPT type name INITOPT, I see, that's kind of what you had there, Chris.
	I'll do the capitalization so we can be clear on these things.
	Out of all, there are, one, 2, 3, 4, non-terminals there visibility OTP, type etc...
	Let's choose the left most one, visibility OPT, how can we go ahead and, what do we do with that, what do we replace visibility OPT with?  -- you're all doing what I just did, Wikipedia and finding out how to paste the Greek letter epsilon.  And I'm happier when, you don't need to apologize for answering wrong -- I'm not trying to ride you or anything like that.  What I'm grading I'll look for, but here, we're at the edge of our seats doing good stuff.  I'm happy to have people reply.
	So, I want to take the visibility OPT and replace with epsilon, by rule B, option 2.  Okay.  And again, I realize that epsilon is the empty string, I'll drop at some point.  And that's fine.  In fact I'll drop in next step.
	Then I'll take, again there's 3 different, 3 different non-terminals here.
	I can choose any of them.  I'll choose left most one, let's take, I'll replace type with INT, and what rule is that, that was D one -- and I'm also going to, it's okay to replace epsilon to get rid of it entirely.  So -- in fact, if you had just gone written that second line, without the epsilon at all I would have been happy with that.  I'll do something along these lines.
	INT is a terminal.  Name, replace name with something.  I'm looking for INT, replace N with N.
	You don't know what option, we're getting close, we're getting close.
	Getting close to where we want to reach.
	What do we do with the INITOPT, do we replace with empty string?  No, no, -- I'm going to use rule F, rule F is expression.
	I need to take INIT off and replace it with, yeah, rule B option one.
	Okay.  And I think this is what Chris you were thinking of.  You were doing 2 steps in your head.  Yeah, BE careful and make sure we have each one and followed by an expression.  Sorry, not expression, equal sign expression.  That's the right-hand side of B one is equal sign expression.  Equal sign got a little lost.  Okay.
	Yeah, and now, now go ahead and use rule F and I'm like, yeah, 17 plus 2, that's an expression, there's a whole bunch of rules what are valid arithmetic expressions, I'm not going to worry about it, but that gives me the string I wanted.  And in fact, a couple of these rules, when I use rule one and rule F, I'm going to go ahead and introduce a slight, not concerned about this notation but I'll use it sometimes, the notation, if I go ahead and say, a double arrow with star above it or maybe after it, if I'm typing, means, with 0 or more -- let's see, let me change that, via 0 or more derivation steps.  So, the double arrow means a single step.  Double arrow star means a whole bunch of steps.
	Usually I wouldn't mean to 0 steps or one step.
	What I'm saying, rules E and F are really a whole bunch of complicated rules, so separately, I didn't specify those, I don't want to get -- so, I like the, double arrow star, just to make it clear that yeah, there's probably actually a bunch of small steps being taken here and I'm not listing them all.  I didn't list all the rules for name and expression.
	Okay.  How does that feel?  Yeah, just go slowly, if you're doing on homework and copying and pasting.
	You copy one line and it will be easier, and choose one non-terminal and replace it.  And especially if you use the rules on the right hand side, that keeps you honest.  Hey that non-terminal I just replaced is that the left hand rule that I'm citing?  We'll write interpreter 4, language that we makeup.
	So -- rule I for Mark's.  Not sure what you mean by Mark's, in real Java there are a lot more rules -- I see, okay.  Yeah, so, da-da-da, actually let me go and -- I want to pull up an example here.
	Let me pull up a link here -- check out link.  There, that is a web page, I made up for my intro Java class a while back -- and so if you look at it, under major definitions and expressions.
	I actually have a grammar for expressions, at least the expressions covered by about week 7 or week 8 of the intro class.  I don't use the right arrow, I use colon, colon equals.
	I didn't say capital E expression for non-terminal.  Put them in gray font instead.  You see, there's a bunch of rules there.  And if you replace the colon, colon equals with the right arrow, that's the grammar for simplified version of Java.  Yeah, what is a class declaration, function declaration, and signature you put up in the header of your function, what is parameter declaration and so on.
	This is really simplified one, if you look at it, count the bullets, -- counting -- that's 14 different rules.  Most with several options.
	Just for the Java that you come across in the first few, first few weeks of Java, if you, really want to get technical, you go view another link here -- there's a link to the --
	There's a link to Java language specification.
	And if you look at that web page -- there's, start scrolling down, each of those brown boxes are more rules.  And you can see that, they use colon rather than right arrow or colon, colon equal sign, slightly different syntax and use multiple lines instead of the or symbol.  A method declaration, (Reading), method header is method modifier OPT, and result, and blah-blah-blah -- and, man Java is a complicated language.
	You start scrolling through there and see those gray boxes and goes on for pages and pages.
	Even the discussion in between, cut that out, there's a lot of them.
	Just telling, so just telling if something about Java program, there's a lot of rules to consult, a lot of corner cases.
	So there's ideas where these are used, how they're used in reality.
	And should notice this page about Java language specification on Oracle website is really mixing, gives syntax rule in the gray box and then have a section about, the both examples and about semantics.  Hey here is what this is suppose to mean.  You know.  And, hey, you know, different, just sort of mixing both semantics an syntax on the page, the dark gray boxes are the syntax.  And that's what we're working with right now.
	So -- okay.  Where is my -- web page -- where is the chat box, there we are.
	Way done below things.
	Okay.  Let's do one more example, and then take a break.
	So first of all questions about that, so, we sort of, and this is common thing, we had idea in mind what we wanted to capture, this Java variable declaration with modifiers and, optional initialization part.  And we can, sort of came up with rules, until we got what we wanted and refactored.  These rules are a little bit like writing code aren't they.  
	And they are a formal language with exact meaning attached to it.  In fact you can take, the, there are programs that will take the grammar rules and turn it into a program that I recognizes, hey, this string, something that reads this grammar, so -- a hybrid type of language?  I'm not sure.  We'll be making up our own language with our own syntax.  I'll ask for certain features and have some flexibility if you want to suggest different ways of writing it.
	Yeah, so, here we're talking -- not talking about semantics, whatever keywords you want, you can make whatever you like.
	Yeah.  And there are many, like I was saying, many, many different languages out there.  Java borrows some from C++ and then adds some other things and leaves some parts out.  So Java is a hybrid language already, if you look at language that came before.  And took stuff from C++ and took stuff from other languages and decided to use those.
	Okay.  So, I want to jump back from this -- example of, variable declarations in Java and grammar that does that -- and I want to go back to caveman example.  Let me scroll down, find that, paste it, so web page gets up-to-date.
	Sorry, you're probably making your screens crazy here by -- deleting stuff, -- okay.
	We already, sort of back in that calf man we updated our grammar to allow S for the end of verb.
	I want to go a heed and add adjectives.
	Take the rule that's have A through F and add adjectives to this language --
	Adjectives to this language, add -- add -- adjectives, what are different adjectives that can I use.
	Green or -- hot, or, happy.  We is that adjective?  The we car?  Not quite adjective.  Things that we can stick in front of nouns.
	Where are we on the note pad, sorry, on the top of note pad on note 17.
	You can call this G 3 or -- or continuing to modify, sure, the grammar G 3 like G 2 but we add adjectives.
	May have taken a while to update there, hopefully we're all good.
	Okay, the top of note 17, I shoved everything else down.  I added a rule G, adjective is green, hot, happy.
	Okay.
	DIANA: Sound went out.
	>>>  Where can adjectives occur.
	DIANA: It's back.
	PROFESSOR:  Adjectives come before a noun, so I could go backup.  They're optional, we don't need to have adjective but we can if we want.  So we could go and say, we take rules A and B, and everywhere there's a noun we can stick in adjective, make it optional, we can have optional adjective, I'm going to go ahead and, up in rules A and B, I'm going to replace N with NP, I'm thinking of changing, upgrading noun to noun phrase, noun phrase means a noun preceded optionally by adjectives.
	Okay.  So now I need a rule that explains what's rule for NP.  NP can be a regular noun, or -- it can be an adjective followed by a noun -- okay, that's pretty good.
	I think, we, go ahead and take a noun freeze and noun phrase, either noun or adjective followed by a noun, I should call that rule B and a half.
	I'll call it H I guess.
	-- okay.  Let me make rules H and I, make it clear.
	Okay.  Do people see rules H and I?  -- okay.
	Now we can come up with, if we have examples, I can have something like, you know, happy cat jump hot hot dog or something like that.
	That's good, of course, what's the cool thing about adjectives?  Might not have adjective or you can have adjective, or you can have?  What other favorite number in computer science?  0, 1, many?  -- oh,  I can have an adjective or I can have 2 adjectives, or 3 or 4 adjectives, so I can go ahead and close that up, right?  
	Adjective, or 2 adjectives and noun, or 3 adjectives and noun, or 4 adjectives and noun, wait a minute.  This will take a long time to finish.  You can have, as many adjectives as you like, you happy, happy, green, green, happy, happy, hot, hot, green, happy, happy, cat -- is that a meaningful sentence?  Maybe not.  Is it grammatical sentence?  Yes,  it has the syntax that fits.  So, exactly.
	-- so, yeah, gosh, so I, can we think of a better way, rather than writing infinite number of rules here, is there a better way we can come up with, saying hey I can have any number of adjectives?  Well, say ADJ star, that's shorthand for infinite number of rules.
	I want to use the rules we have, without making up things that are shorthand -- I don't like to expand infinitely large.
	I like Mark's solution.  I can say NP, noun phrase can be a single noun, but rule I, a noun phrase is an adjective followed by a noun phrase.
	Okay.  And now think of this as, rule H is our base case, and rule I, we can keep applying rule I as many times as we get more and more.
	Go ahead and try this.  Give me an example of -- we'll do -- cat runs again -- happy, green, happy hot happy hot dog.  Now you don't want to do this if you're not type anything text editor or something like that -- so we have -- and I took this because we already have an example of cat runs.
	And so that will help us.  With our problem.
	I takeaway Roman Numeral numbers, I don't care about those.
	I'm going to start.  If I want to generate, cat runs happy green happy hot happy hot dog, it should be rule B.
	Not rule A.
	Right?  -- and I'm going to change -- I'll use rule B, and now, how do I get from NPCVNP, first line, how do I get, I want to get to cat CV space, did can I do that directly, no rule that says NP can be replaced with cat.
	So -- so what do we do?  I can't, there's no rule saying NP, I can get from NP to cat, I need intermediate step.
	What do I want to use?  Again, and P was a noun phrase, so let me add all of the adjectives I want.  I didn't add any adjectives for this case, I used the rule base set, when is rule H.
	So, NPCVNP goes to, NCVNP, --okay, I get cat CVNP then I use the words we did before, to get cat Vs NP and cat runs NP, by excusing rules --
	Okay, now I'm down to cat runs and P, so go ahead and --what rule do we want to play after cat runs NP.
	-- I need happy, how do I get the happy in there.  There's a rule, NP goes to happy?  No.  Not quite.
	-- I changed NP into adjective NP by rule I.
	And then change the adjective into happy.
	That's rule G,  option 2.
	Okay, now we're going to repeat those last couple of steps.
	Turn NP into adjective NP, by rule I.
	And then replace, so, go ahead and replace adjective right now -- I could go ahead and change into adjective, adjective, adjective, NP and then start with middle adjective, whichever one the NP to an N to hot dog right away, whatever I wanted.
	Okay, does that make sense?  -- if nothing else, do it yourself and add a few more lines that I did.
	Repeating rules I and G.
	how do I get rid of that NP in the end, once I don't want adjectives, NP can be replaced by simple noun, and that's rule H.
	And then, setup last one and N can go and replace N with hot dog.
	ABCDEF -- 1, 2, 3, 4.
	Rule E 4 -- no, E 6, something like that.  Yeah.
	Okay.  So this is kind of cool, we go ahead and, add rules H and I together, let me do 0 or more occurrences of adjective.  After doing this trick once or twice more, we can stop writing these 0 out -- whenever you need that 0 or more trick, we don't have to do that now, shorthand for 2 rules an let you use the star notation.
	I'll be clear, when I'm allowing the star shorthand or not.  For, the first homework we'll do involving grammar rules, I'm going to say no.  Don't use, don't just say adjective star, -- tell me exactly what you mean, exactly what rules you mean I need.
	In this case, rules H and I together.
	Again, think of it as base case and recursive step.
	Even though it's worth noting here -- I can go ahead -- the self reference, rule I, pointing out self reference, how many strings are there in G 3?  There's infinite number of strings in G 3, G 2 only had a finite number of possibilities.
	G one there's only like whatever, 400 possible sentences.
	Now there's infinite number of possible sentences, that repeat a lot of adjectives.  So, okay, let's take a break.
	Come back to finish up -- and talk about trees and how they relate to derivations that we're doing.
	On quiz or exam, I'll give you grammar and say generate a string, I might say give me rule that's capture a concept.  Declaring a variable in Java, something like that.  Being able to come up with rules.
	Knowing what you want to include and come up with the rules that's like coding.
	You applying the rules to come up with a specific sentence, that's a little like tracing through a program, both good skills to have.  Sounds good.
	[Break Time] 
	PROFESSOR:  Okay, can everybody see my drawing there?  Am I sharing that properly?  Okay.  I'll try to look down at camera occasionally, so you don't have to see my chin the whole time.
	And let me see if I can figure out the eraser.
	The eraser is not select able -- oh, record, thank you.
	I forgot to read Sean's notes.
	I told myself to do that.
	PROFESSOR:  Okay, so, -- let me kill this pod and make a new sharing pod, how about that?  Is there, no?  Okay, using whiteboard 131.  Okay.
	-- and can you, -- let's see if we can do this -- I'm going to try scrolling -- I'll stay where I am on the notes.
	Can people see both the notes an sentence about cat runs, happy, green, happy hot, hot dog and the whiteboard?  -- so -- okay, so -- looks like that, let me know if things are covered up and screens not big enough.  Is the text big enough on the notes?  Hopefully that is.  Okay.
	So, we go ahead and use this grammar to derive a string.  This string we de reef also has a tree that goes with it, here is how the tree looks.  It's pretty straightforward.  Like it bigger -- it has an S at the root.  And then it has from there 4 children.  And, the first child is, NP, the second child CV, and next child NP, that's the next step we use, rule B, replace that S with NP, CV, NP to the, and we took different things, we had rule that says the NP, if I can -- do this correctly -- NP, first NP got replaced with an N.
	And that N in turn eventually became, the word cat.
	-- similarly, I guess CV became -- we had a rule there, CV became a, VC turned into how many things?  2 -- the VS, that V turned into run -- okay.
	So -- hopefully this makes sense.
	How does it look for this other NP, happy, green, all of this NP again rated the happy green happy hot happy hot dog, how did that happen?  We went from NP, replaced with, what was what rule?  I, adjective and NP.
	So -- and that NP got replaced with adjective NP and so, the point is, every time we do a derivation we can think of tree that goes with it, we want to think of the tree that goes with it.  There's a direct correspondence.
	Notice that, there's exactly one tree, I can fill it out in various orders but end of the day, there's only one tree that corresponds to that tree we generated in this case.
	And, even though there are many possible derivations, depending on the order.  The left most derivation I was always choosing the left most non-terminal, when I went from one line to the next, and that's cool, but I could have chosen any of them.  But the tree, they all lead to the same tree.
	In this case.  Finish this out, I think I'm almost down.  Right.
	Happy and green -- and, happy, gosh not quite done, there's another adjective, noun phrase, and noun phrase between a noun, there we are.
	Oh, I messed up a little bit.  Okay.  I think that's good, except for, there we are.
	Okay.  WHEW, I had extra happy instead of hot.
	This is the tree that goes with it, don't forget this little dot on the top.  How do you read this tree, in you want to get the non -- sorry, the terminals we ended up.  I guess, transversal, in order transverse sat, cat, run, happy, green, hot, happy, hot dog, period.
	There's this, the tree that goes with it, we call this the parse tree.  Corresponding to A derivation and what we care about is the tree, that's the real structure that goes on.  We can look at tree direct directly and see what cam from what non-terminal or derivation.  This is like sentence diagrams, if you did that when you were youngster, you have to be my age, sentence diagrams, drawing the parse tree, they have extra symbols to convey extra information, it's roughly doing that.
	Okay.  Let's switch back to note pad for a second and I want to look at a different grammar.  I want to look at a grammar for, simple expressions -- numbers with star, and plus.
	I'm going to go ahead and have new non-terminal arithmetic expression.
	I want this to be expression involving numbers and the just the plus and times operators.  What grammar should I do?  What rule should I do for that?  and I guess I'll have a, number, this will be, not sure, it will be something like F, some sort of rule beside how to get an actual number, series of digits.  Okay?  So -- also natural numbers.  Natural numbers of plus and times, how can I do that?  What can I do, expression can be, well, it can be a number, or it can be a, I could start doing stuff, make it rule B, I could say it's a number plus a number.
	Or number times a number.  Or number plus number times number, or number times number plus number, or number plus number plus number etc...  A I apologize to voice transcribe better for this examples.
	This is not a feasible way to continue, I'll have too many rules here -- what can I do instead to help?  Same trick we used before, -- how can I make this, add as many things as I like.  Like recursive, yeah, exactly how?  Let's leave rule A how it is.  Okay, so, ARITH expert plus number, and could be times a number.  So that let's us go ahead and do it.
	Okay.  Now to be a little careful, if I want to do something, I'll make it a little different here and say, really can be, arithmetic expression plus, -- what am I doing here?  I'm losing track of my editing.  Arithmetic expression plus any other arithmetic expression.  If I have 2 other arithmetic expressions I can go ahead and, put a plus in between them and get a new bigger expression.  So -- okay, here are my 4 rules here.
	Can you go ahead and give me a derivation of 2 plus 3 times 4?  -- whiteboard is in the way -- I think I'm done, where I want to go -- so the derivation of 2 plus 3 -- 4, other than that, draw me the tree, parse tree for, 2 plus 3 star 4.
	I think we can get 2 plus 3 star 4 out of these rules, ABCF, -- it is in the way, let me -- okay.
	Let me move that -- I'm going to make a new whiteboard -- move that around a little bit.
	Is that better?  See the whiteboard and the first lines of the thing?  So, that's a question about semantics, order of operations.
	Yeah, there is no meaning to star or plus.  These are symbols, for that matter, 2 and 3 and 4, those are symbol that's get types, no meaning at that point, just is it a valid expression.
	You're on to what I'm thinking, there are actually 2 different tree that's could account for this.  If I can, no longer able to write on the whiteboard -- oh,  I was using the wrong tool, there we are.
	I get, (Inaudible) sound going out.
	PROFESSOR:  Sorry, 3 children, you'll use rule B, ARITHEXPL plus ARITHEXPR -- I want to end up with 2 plus 3 times 4, so, this first, ARITHEXPR I want to end up in 2, I need to do in a couple step.
	I need to say hey -- do that.  Goes to number and goes to 2.  And under second ARITHEXPR this becomes another one with 3 children, yeah, -- see if I can -- ARITHEXPR, ARITHEXPR, now each of those can do the same thing, and we can get to the number we want.
	That's one tree, what's the other tree, can you get it on scratch paper at home.  You can give me another tree that's different than this one?  -- and hopefully it will should be pretty clear, I think -- trying to do a big wicked copy paste . can have the same thing but the root would be the star.  And then off the right-hand side would be shallow and left-hand side would be another sub tree that included the plus.
	So I'm going to say that.
	Okay, I've shown one tree but there's another possible tree.  And they both follow the grammar.  Are we happy with this situation?  No, because, these trees, the meaning is really -- I mean they're different trees, does the, what operator is suppose to be at the root of this tree, we get different answers and yet they both follow the grammar.  So, back in notes page, I'll go ahead, the definition -- a grammar -- there is some string which has -- 2 different parse trees.  Okay.  -- we don't like grammars that are ambiguous, we want to, that means it's not clear how to take the string and turn it into the tree and different trees tend to have different meanings.
	Or could have different meanings.
	Yeah, and, like Steven was saying -- in the derivation it's like hey do I use rule C first or rule B first.  It's actually a little bit different.  If I use left most derivation yeah that's true.  If I switch where I'm going its sort of a little bit, you have to do several steps before you committing to one tree or the other.  Anyway, that doesn't matter -- so yeah, we need to be a little bit careful.  Try to make our grammar so they're not ambiguous.
	And one example is arithmetic expression, let me show you a link -- there's a couple of ways to sort of, solve this problem, -- one way is to, here we are -- this will be in the notes as well -- there's somebody's web page and let's look at the grammar they made there.  Grammar for arithmetic expressions, more complicate the grammar but not ambiguous.  If you're looking at that web page, the link I just gave, up at the top, he uses colon, colon equal, instead of right arrow.
	An expression could be an expression plus a term or expression minus term, what's a term?  A term is times a factor or term divided by a factor, and factor is either X or Y or a whole sub expression in parentheses.  Okay?  And this, he gives the grammar that now corresponds to the playground rules that you all had growing up about your lazy Aunt Suzy the pneumonic that you used.
	If you try to take the string, in this grammar there's only one way to do it.  3 times 4 is going to become a term, and terms are things that involve a whole strings of multiplications an divisions.
	And -- and, factor are individual things in that string of multiplications and divisions and plus in between different factors.
	And so this grammar is more complicated and not ambiguous and forces us into the precedence that we want for different operators.
	If you go to that page, that's one approach.  To say, I want operator precedent, be careful if you write a naive thing like we did, you get ambiguous grammar.  You can fix by making more complicated grammar that forces the precedence.  There's another way of doing this.  If you look at the Java grammar that I showed a moment ago, the grammar for expression, looks like the naive version we did and they say, in addition to how you make an expression, the grammar rules for that expression, you get some sort of tree, but now within that expression we have extra rules that are not part of tree, not part of grammar, extra rules about precedence and associatively and stuff like that.  If all the different trees that grammar can make, there's one that we mean and separate set of rules for that and put one more link in there.
	And that page there, if you look at it, this is just the Java operators.  And their leveling of priority.  Levels of precedence.  If you look at that, there are 14 levels of precedence.  There are 42 operators in Java.  42 operators.  There's a lost of them.
	You tend to think of plus times division, and subtraction, but really there's a lot of things, and just looking at them, I'm going to look at equals, equals, and there's assignment operator and plus plus and addition, and I'll point out -- when you say, think of what the tree should be for -- X gets plus, plus plus Y equal equal, new integer, something like this -- yeah, if you look at that expression, there's a plus plus operator, assignment operator, equal equal operator and new operator going on.  And how the tree should look like for that, is -- you know -- for computer to figure that out you need that table with 42 operators an 14 levels of precedence.  That knowing, makes grammar simpler but we have whole extra luggage and they take care of it in different place that, Tyler's class talking more about parsing. 
	So you can keep grammar simple and add extra rules later.  You can make the grammar more complicated and add terms an factors, and imagine, how complicated grammar is if doing full Java precedence.  How does Racket solve this problem of precedence.  Somebody may have mentioned this before.
	Yeah, every operation is in separate parentheses, basically it doesn't have the issue.  Why doesn't it have the issue?  Because it requires every function call.  It doesn't have operators it's all prefix functions, beyond that it says require parentheses for every function call, open and close paren.  If you require, if you say every time you use plus must be nd parentheses and every time you use star, sorry -- multiplication, must be open paren something asterisk something closed paren, everything something is either a number or operator -- if you require all of those parentheses you have a simple grammar and parser, no extra work to be done.  Puts burden on programmer, always having to include those parentheses, those are 3 ways to sort of handle this issue.
	And sort of interesting to compare and contrast those.
	We're going to be writing later on -- after we do the video game, write interpreter for our language, we'll makeup grammar rules, write a program that takes a string and turns it into the tree and once we have the tree we can start doing something with the program, something interesting.
	So, and so we'll see how to do all of those steps.
	We'll make the grammar we choose, I'll give you, people in this section or other section have some discussion about what futures you want.  I'm going to make certain constraints, it has to be unambiguous, but require, maybe not parentheses but some markers so we don't run into precedence issues.
	We'll add enough characters in there so it's never ambiguous.
	Okay, I think that's what I wanted to cover for the day, week -- any questions on this?  -- we're going to do a couple things in tandem, programming and working with union types and unions of structs and working with trees and tie these together.
	If you think about these grammars, it's kind of like data definition.  And we'll think about how, some of our rules correspond to union types or struct types and how we'll do that.  So -- okay.  Any questions?  Thought beside that?  -- notes are posted.  Video notes were, Steven pointed out to me there were bad links and I got those fixed.  And I'll post this video in a little bit, and, the notes are on the web page and new homework coming out in the next day or 2.
	-- and again I think I might have smaller thing due by Monday to make sure we're up on track by that.  If you get the whole homework done before Monday, that should be possible.  So -- okay -- I'll let you get off to your fun other classes.
	Take care.
	I hope your in the zone and interested and engaged and not frustrated and not feeling too pressured.