Return to Video

04-49 Parsing Tags

  • 0:00 - 0:02
    Let's say we want to continue formalizing
  • 0:02 - 0:04
    our HTML grammar in Python.
  • 0:04 - 0:07
    One of the other types of elements in HTML,
  • 0:07 - 0:09
    aside from bare words, is
  • 0:09 - 0:11
    tag-decorated words.
  • 0:11 - 0:13
    You might put or an
  • 0:13 - 0:16
    or even something more complicated, like this, that changes the color.
  • 0:16 - 0:19
    So just to remind you of what these HTML tags look like,
  • 0:19 - 0:23
    they start with this Left Angle, there's some name;
  • 0:23 - 0:26
    they might have some arguments, there's a Right Angle;
  • 0:26 - 0:28
    there can be any HTML in the middle;
  • 0:28 - 0:31
    then there's this Left Angle Slash, another word, and a Right Angle.
  • 0:31 - 0:33
    And here, I've just written out that grammar rule:
  • 0:33 - 0:36
    this LANGLE corresponds to this part.
  • 0:36 - 0:38
    this word goes here,
  • 0:38 - 0:42
    tag arguments--color = "Red",
  • 0:42 - 0:45
    Right Angle is that one, HTML is here,
  • 0:45 - 0:48
    LANGLESLASH is these two, and so on.
  • 0:48 - 0:50
    And, here, I'll build up my parse tree
  • 0:50 - 0:52
    by using part[2]: zero, 1, 2,
  • 0:52 - 0:55
    the word, like span or bold or underline;
  • 0:55 - 0:58
    the tag arguments--if there are any,
  • 0:58 - 1:02
    the body--the words that are being modified by bold or underline,
  • 1:02 - 1:04
    and then, finally, the final word--
  • 1:04 - 1:06
    just to make sure, later on, that you've opened
  • 1:06 - 1:08
    and closed or opened and closed .
  • 1:08 - 1:11
    Remember, we want those parentheses to match.
  • 1:11 - 1:14
    And our input text is: hello yaga,
  • 1:14 - 1:16
    and we've got bolded.
  • 1:16 - 1:20
    I'm going to ask you to take apart this concept and do it backwards.
  • 1:20 - 1:22
    I have written out the parse tree,
  • 1:22 - 1:24
    down here at the bottom,
  • 1:24 - 1:26
    but I've left 3 blanks.
  • 1:26 - 1:28
    I would like you to fill in the blanks
  • 1:28 - 1:30
    with a single word
  • 1:30 - 1:33
    that will make this parse tree correspond to
  • 1:33 -
    what our parser will produce on this input.
Title:
04-49 Parsing Tags
Description:

dummy description

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

English subtitles

Revisions