Skip to content

Lecture 25

Intro to parsing

The rules matter

Dear John:

I want a man who knows what love is all about. You are generous, kind, thoughtful. People who are not like you admit to being useless and inferior. You have ruined me for other men. I yearn for you. I have no feelings whatsoever when we’re apart. I can be forever happy–will you let me be yours?

Jane

VS

Dear John,

I want a man who knows what love is. All about you are generous, kind, thoughtful people, who are not like you. Admit to being useless and inferior. You have ruined me. For other men, I yearn. For you, I have no feelings whatsoever. When we’re apart, I can be forever happy. Will you let me be?

Yours,

Jane

One more:

Let's eat, grandma

How could that possibly go wrong?

A CS example

map

Steps:

  1. Press Export in the top left
  2. Press the blue Export button
  3. save as "map.osm"
  4. open in any text editor/JGrasp (Sublime is best)

parseMapTemplate.zip

Today's task:

  1. Form groups of 2 or 3
  2. Write one method getWayName (String[] osm, int i) that uses getAttribute to print the name of a road (type = "way")
  3. In the main, print the names of all the roads (type = "way") in your parsed file.
  4. Show to a TA

Parsing language

Check this video (use headphones or at home): parsing grammar

Parsing as part of compilation

Check this video (use headphones or at home): parsing for compilation

previous lecture | next lecture