Tip:
Highlight text to annotate it
X
Welcome back!
This is unit 4 of programming languages, and if we turn the clock back to last time,
we were posed the following question.
Given a string S, like a webpage or some embedded JavaScript or any program,
and a formal grammar describing our desired language,
a former grammar for HTML or JavaScript,
we want to know if that string S is in the language of G?
To do this, we use 2 key techniques--lexical analysis, which broke the string down
into a stream of tokens, and syntactic analysis or parsing,
which takes a string of tokens and checks to see if they adhere to,
if they conform to a context-free grammar.
While we're on the subject of time and grammars--grammars that may possibly
be ambiguous, let me introduce you to a phrase that you may not have run into yet.
The phrase is, "Time flies like an arrow. Fruit flies like a banana."
The ambiguity trick here is that time is a noun, flies is a verb--time flies--
and "like an arrow" is the modification.
So here I've got time flying.
You can tell because it's got labels, and those labels are always to be trusted.
So you might think, based on parallel structure, that fruit is a noun and verb is flies.
So here I've got a picture of an apple with wings,
and their flying in the manner of a banana.
But in fact, fruit flies is the noun.
They are little insects that go after fruit, and this time, like is the verb.
Fruit flies go after the banana. They enjoy the banana.
This is the sort of ambiguity that we can run into in a natural language like English.
We're going to have to deal with that same sort of issue in programming languages,
like in JavaScript or Python.