Compiler 2 nd Phase Syntax Analysis Unit-2 : Syntax Analysis1.
Syntax
description
Transcript of Syntax
![Page 1: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/1.jpg)
Syntax
LING 001 - October 11, 2006 Joshua Tauberer
![Page 2: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/2.jpg)
Syntax
How can the words of a languagebe put together?
![Page 3: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/3.jpg)
Syntax
What makes a valid combination or order of words?
What are the relations between the words in a sentence?
What is the mechanical system by which we put words together?
![Page 4: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/4.jpg)
Sentence or Word Salad?
good students take a linguistics course
students linguistics course good a take
students good take a course linguistics
take students course good linguistics a
good students a linguistics course take
![Page 5: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/5.jpg)
Sentence or Word Salad?
✓good students take a linguistics course
* students linguistics course good a take
* students good take a course linguistics
* take students course good linguistics a
* good students a linguistics course take
![Page 6: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/6.jpg)
Sentence or Word Salad?
✓good students take a linguistics course
* students linguistics course good a take
* students good take a course linguistics~ Romance languages
* take students course good linguistics a
* good students linguistics course a take~ Japanese, Turkish
![Page 7: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/7.jpg)
Sentence or Word Salad?
Sometimes rearranging the words yields word salad.
Sometimes rearranging the words gives a different meaning. John likes Mary. Mary likes John.
Sometimes one arrangement has two meanings I saw the man with a telescope. Is this syntax or semantics?
![Page 8: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/8.jpg)
What’s a valid sentence?
verb noun verb noun verb noun
![Page 9: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/9.jpg)
What’s a valid sentence?
verb Leave! noun verb I ate. noun verb noun Students like linguistics.
![Page 10: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/10.jpg)
What’s a valid sentence?
verb Leave! noun verb I ate. noun verb noun Students like linguistics. noun verb noun preposition determiner noun
Billy sent letters to his mom. noun verb det noun noun verb
Sally found the gold I burried. and on...
![Page 11: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/11.jpg)
What’s not a sentence?
*noun *noun noun verb verb determiner *noun adjective det det noun adjective verb
![Page 12: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/12.jpg)
What’s a valid sentence?
Can we list all valid POS strings? Is there a longest sentence?
Language is unbounded in many ways coordination X and Y and Z and . . . modifiers in the house on the table . . . recursion who chased the dog that ate the .
. . We need a finite set of rules (the grammar) that
gives us an infinite set of strings (the language).
![Page 13: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/13.jpg)
Two Models of Syntax
Words as Building Blocks
Constituent Structure
![Page 14: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/14.jpg)
Words as Building Blocks
A model of syntax: (loosely based on Tree Adjoining Grammar)
The mind’s vocabulary comprises a set (lexicon) of special domino-puzzle pieces.
nounS
verb
verb
adj
prep
verb prep
![Page 15: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/15.jpg)
Words as Building Blocks
Assemble the pieces any way so that there are no bumps or holes at the end.
Colors must match like dominos.
Start with the special S piece.
Bill
ate
S
cake
read words from left to right(actually “infix order”)
the mechanical system
![Page 16: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/16.jpg)
Words as Building Blocks
Bill
ate
S
cakesome
![Page 17: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/17.jpg)
Words as Building Blocks
ate
S
storetheBill cake
from
![Page 18: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/18.jpg)
Words as Building Blocks
S
store
the
ate
Bill cake
from
![Page 19: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/19.jpg)
Words as Building Blocks
S
store
the
ate
Bill cake
from
![Page 20: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/20.jpg)
Words as Building Blocks
S
cake
store
the
ate
Bill
from
![Page 21: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/21.jpg)
Words as Building Blocks
Bill
S
cake
store
the
atefrom
![Page 22: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/22.jpg)
Words as Building Blocks
Bill
S
cake
store
the
ate
from
![Page 23: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/23.jpg)
Words as Building Blocks
The way the pieces connect tell us how the words are related.
The organization of pieces tells us about the meaning.
Bill
ate
S
cake
![Page 24: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/24.jpg)
John
likes
S
Mary
Words as Building Blocks
The organization of pieces tells us about the meaning.
This bump isfor the subject.
This bump isfor the object.
Mary
likes
S
John
![Page 25: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/25.jpg)
I
S
saw
awith
mana
tele-scope
How many ways are there two assemble the pieces to make the sentence?
with
![Page 26: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/26.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
Prepositional Phrase Attachment
![Page 27: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/27.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”
![Page 28: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/28.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”
![Page 29: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/29.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”
![Page 30: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/30.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I
![Page 31: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/31.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw
![Page 32: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/32.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw
![Page 33: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/33.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw
![Page 34: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/34.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw a
![Page 35: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/35.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw a man
![Page 36: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/36.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw a man
![Page 37: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/37.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw a man
![Page 38: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/38.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw a man with
![Page 39: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/39.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw a man with a
![Page 40: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/40.jpg)
man
I
S
a
tele-scope
saw
aman
I
S
a tele-scope
saw a
with
with
“Infix Order”I saw a man with a telescope
![Page 41: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/41.jpg)
Garden Path Sentences
The horse raced past
the barn fell.
Grammatical?
![Page 42: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/42.jpg)
Garden Path Sentences More from Wikipedia:
The man who hunts ducks out on weekends.
The cotton clothing is usually made of grows in Mississippi.
The old man the boat.
The player kicked the ball kicked the ball.
![Page 43: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/43.jpg)
Garden Path Sentences
horse
S
the past
barn
fell
the
?raced
raced
![Page 44: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/44.jpg)
Garden Path Sentences
horse
thepast
barn
fell
the
raced
raced
S
![Page 45: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/45.jpg)
Garden Path Sentences
horse
S
thepast
barn
fell
the
raced
![Page 46: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/46.jpg)
Garden Path Sentences
horse
S
the
past
barn
fell
the
raced
![Page 47: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/47.jpg)
Garden Path Sentences
horse
S
the
past
barn
fell
the
raced
![Page 48: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/48.jpg)
Garden Path Sentences
horse
S
past
barn
fell
the
raced
The horse (that was) raced past the barn fell.
the
The yellow ‘raced’ pieceis used for relative clauses.
![Page 49: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/49.jpg)
Garden Path Sentences More from Wikipedia:
The man [who hunts] [ducks out on weekends].
The cotton (that) clothing is usually made of grows in Mississippi.
[The old] [man the boat].
The player (that was) kicked the ball kicked the ball.
![Page 50: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/50.jpg)
Constituency and Substitution
A second perspective on syntax. Sentences seem to have replaceable parts.
Billy ate peaches from the store
Billy ate cookies from the store
Billy ate the pie from the store
Billy ate the pie in the box
Billy ate the pie on the box
Billy sold the pie on the table
the store sold the pie on the table
![Page 51: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/51.jpg)
Constituency and Substitution
But parts can’t be replaced with just anything.
Billy ate peaches from the store
Billy ate sold from the store
on the table ate peaches from the store
Billy ate peaches the pie
Just as words are categorized by part of speech, replaceable parts (“constituents”/ phrases) come in different types.
![Page 52: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/52.jpg)
Constituency and Substitution
Billy ate the pie from the store
nouns = { pie , cookies , store , table , Billy } verbs = { ate , sold } prepositions = { from , in , on } noun phrases = { cookies , the pie } prepositional phrases
= { from the store , in the box , on the table , just until the clock struck seven }
![Page 53: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/53.jpg)
Constituency and Substitution
Billy ate the pie from the store
nouns = { pie , cookies , store , table , Billy } verbs = { ate , sold } prepositions = { from , in , on } noun phrases = { nouns , det + nouns } prepositional phrases
= { preposition + noun phrases }
determiner = article (‘the’, ‘a’)
![Page 54: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/54.jpg)
Context Free Grammar
Let’s say a sentence (S) is defined by a rule:
NounPhrase Verb NounPhrase
And a NounPhrase is defined as either: Noun or Determiner Noun
Keep substituting symbols with other constituents of the same category until only words in the language remain.
![Page 55: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/55.jpg)
Context Free Grammar
S
NounPhrase Verb NounPhrase
Noun ate Determiner Noun
Billy ate the cookies
![Page 56: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/56.jpg)
Context Free Grammar
S
NounPhrase Verb NounPhrase
Determiner Noun has Determiner Noun
the store has the pie
![Page 57: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/57.jpg)
Context Free Grammar
Trees show order symbols were replaced. Also shows the constituent structure.
![Page 58: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/58.jpg)
Context Free Grammar
![Page 59: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/59.jpg)
Recursion
Billy eats worms Ruthy made Billy eat worms The teacher let Ruthy make Billy eat worms I saw the teacher let Ruthy make Billy eat
worms The principle knows I saw the teacher let Ruthy
make Billy eat worms The superintendent wonders whether the
principle knows I saw the teacher let Ruthy make Billy eat worms
![Page 60: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/60.jpg)
Recursion
S
NP Verb S
NP let S
Det Noun let S
the teacher let S
the teacher let Noun Verb S
the teacher let Ruthy make S
the teacher let Ruthy make Noun Verb Noun
the teacher let Ruthy make Billy eat worms
![Page 61: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/61.jpg)
Recursion
![Page 62: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/62.jpg)
Recursion
verb
![Page 63: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/63.jpg)
Recursion
![Page 64: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/64.jpg)
Recursion
![Page 65: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/65.jpg)
Recursion
![Page 66: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/66.jpg)
Recursion
![Page 67: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/67.jpg)
Recursion
![Page 68: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/68.jpg)
PP Attachment with Trees How is PP-attachment ambiguity represented with
trees? Let’s define a Prepositional Phrase first:
S → NP Verb NP NP → Det Noun PP → Prep NP
Recursively define S’s and NP’s. S → S PP NP → NP PP
“Any valid S/NP can have a PP tacked on and still be a valid S/NP.”
![Page 69: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/69.jpg)
PP Attachment with Trees
![Page 70: Syntax](https://reader033.fdocuments.in/reader033/viewer/2022042822/56813fae550346895daa94f1/html5/thumbnails/70.jpg)
PP Attachment with Trees