Return to Video

03-13 Statements Solution

  • 0:00 - 0:03
    All right, let's go over the possible answers together.
  • 0:03 - 0:07
    We say that a statement has to be an identifier followed by an equals sign
  • 0:07 - 0:09
    followed by an expression.
  • 0:09 - 0:13
    Lata, l-a-t-a, is definitely an identifier using our previous rules.
  • 0:13 - 0:17
    That's a collection of upper and lower case letters that may include an underscore,
  • 0:17 - 0:19
    but the underscore can't come first.
  • 0:19 - 0:23
    This is an identifier, and expression can go directly to number,
  • 0:23 - 0:26
    and 1 is a number, so this is totally valid.
  • 0:26 - 0:30
    Here we have Mangeshkar = 19 + 29.
  • 0:30 - 0:34
    Well, Mangeshkar is longer, but it's still an identifier.
  • 0:34 - 0:38
    It's a collection of letters, and it may have underscores, but it doesn't.
  • 0:38 - 0:40
    And then we have the equals sign. That matches.
  • 0:40 - 0:44
    And now we're going to use this rule here, expression goes to expression + expression
  • 0:44 - 0:48
    to get this + sign, and then expression will go to number for 19,
  • 0:48 - 0:51
    and expression will go to number for 29.
  • 0:51 - 0:53
    I like this.
  • 0:53 - 0:55
    Here we have Lata = Lata + 1.
  • 0:55 - 0:59
    This one is tricky because it's totally valid in Python,
  • 0:59 - 1:03
    but it's not valid in this grammar.
  • 1:03 - 1:06
    I haven't said that expression can go to identifier,
  • 1:06 - 1:08
    so Lata is an identifier.
  • 1:08 - 1:10
    The equals sign is an equals sign.
  • 1:10 - 1:14
    But over here I need something like 1 + 1.
  • 1:14 - 1:19
    I don't yet have a rule that would allow me to have Lata + 1.
  • 1:19 - 1:23
    If I had this mysterious fifth rule, then this would be in the language of the grammar.
  • 1:23 - 1:26
    But I don't yet, so it isn't.
  • 1:26 - 1:30
    And then over here, Mangeshkar = 25,000 - 1,
  • 1:30 - 1:33
    that's an identifier =,
  • 1:33 - 1:36
    and now we're going to use this rule here, expression - expression.
  • 1:36 - 1:38
    This totally works out.
  • 1:38 - 1:41
    Lata Mangeshkar is a famous Indian playback singer.
  • 1:41 - 1:45
    She's recorded over 25,000 songs,
  • 1:45 -
    a world record for quite some time, and she's also received India's highest civilian honor.
Title:
03-13 Statements Solution
Description:

dummy description

more » « less
Video Language:
English
Team:
Udacity
Project:
CS262 - Programming Languages
Duration:
01:51
Amara Bot added a translation

English subtitles

Revisions