+ All Categories
Home > Education > CS Example: Parsing a Sentence

CS Example: Parsing a Sentence

Date post: 27-May-2015
Category:
Upload: katrin-becker
View: 255 times
Download: 0 times
Share this document with a friend
Description:
A worked example of parsing a natural language sentence using syntax diagrams.
Popular Tags:
107
© K.Becker Cpsc 233 Parse a Sentence Parsing a Sentence Using the Syntax Diagrams "The bearded lady hides but the elephant thinks this thought."
Transcript
Page 1: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Parsing a Sentence Using the Syntax Diagrams

"The bearded lady hides but the

elephant thinks this thought."

Page 2: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Start with : <STATEMENT>

The bearded lady hides but the elephant thinks this thought.

<Sentence> PUNCT

- get the first string; - find it in the dictionary

Page 3: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Start with : <STATEMENT>

<Sentence> PUNCT

- got the first string; - found it in the dictionary

"The"ARTICLE

"*"

The bearded lady hides but the elephant thinks this thought.

Page 4: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

BEGIN : <SENTENCE>

<Sentence> PUNCT

- get the first string; - find it in the dictionary

"The"ARTICLE

"*"

The bearded lady hides but the elephant thinks this thought.

Page 5: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Now IN : <SENTENCE>

"The"ARTICLE

"*"

The bearded lady hides but the elephant thinks this thought.

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 6: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

EXPECTING : <NOUNPHRASE>

"The"ARTICLE

"*"

The bearded lady hides but the elephant thinks this thought.

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 7: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Now IN : <NOUNPHRASE>

"The"ARTICLE

"*"

The bearded lady hides but the elephant thinks this thought.

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 8: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

EXPECTING : ProNoun, ProperNoun, Article,

or Noun

"The"ARTICLE

"*"

The bearded lady hides but the elephant thinks this thought.

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 9: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

MATCHED : Article

"The"ARTICLE

"*"

The bearded lady hides but the elephant thinks this thought.

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 10: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

MATCHED : Article

"The"ARTICLE

"*"The bearded lady hides but

the elephant thinks this thought.

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 11: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : Article

"bearded"ADJECTIVE"baratus"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

"The"ARTICLE

"*"

Page 12: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still IN : <NOUNPHRASE>

"bearded"ADJECTIVE"baratus"

"The"ARTICLE

"*"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 13: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <ADJECTIVELIST>

"bearded"ADJECTIVE"baratus"

"The"ARTICLE

"*"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 14: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now IN : <ADJECTIVELIST>

"bearded"ADJECTIVE"baratus"

"The"ARTICLE

"*"

{nothing}

Adjective

Page 15: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : Adjective

"bearded"ADJECTIVE"baratus"

"The"ARTICLE

"*"

{nothing}

Adjective

Page 16: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : Adjective

"bearded"ADJECTIVE"baratus"

"The"ARTICLE

"*"

{nothing}

Adjective

Page 17: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : Adjective

"bearded"ADJECTIVE"baratus"

"The"ARTICLE

"*"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 18: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : Adjective

"lady"noun

"domina"

"The"ARTICLE

"*"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

"bearded"ADJECTIVE"baratus"

Page 19: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still IN : <ADJECTIVELIST>

"lady"noun

"domina"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

{nothing}

Adjective

Page 20: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still EXPECTING : Adjective

"lady"noun

"domina"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

{nothing}

Adjective

Page 21: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Adjective NOT FOUND, RETURN..

"lady"noun

"domina"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

{nothing}

Adjective

Page 22: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Back IN : <NOUNPHRASE>

"lady"noun

"domina"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 23: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : Noun

"lady"noun

"domina"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 24: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : Noun

"lady"noun

"domina"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 25: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : Noun

"lady"noun

"domina"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 26: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

MATCHED : Noun

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

Page 27: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Now Leaving : <NOUNPHRASE>

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 28: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Back IN : <SENTENCE>

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 29: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

EXPECTING : <VERBPHRASE>

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

CONJ <Sentence>

<NounPhrase><Verb-

Phrase>

Page 30: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

Now IN : <VERBPHRASE>

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 31: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

EXPECTING : <ADVERBLIST> or Verb

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 32: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

MATCHED : Verb

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 33: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

MATCHED : Verb

"hides"VERB

"abscondo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

The bearded lady hides but the elephant thinks this

thought.

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 34: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : Verb

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 35: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <NOUNPHRASE> OR <ADVERBLIST>

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 36: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

FOUND : Conjunction instead

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 37: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now Leaving <VERBPHRASE>

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 38: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Back IN : <SENTENCE>

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 39: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : CONJUNCTION

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 40: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : CONJUNCTION

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 41: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : CONJUNCTION

"but"CONJ

"ceterum"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 42: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCHED : CONJUNCTION

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 43: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still IN : <SENTENCE>

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 44: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now INTO : <SENTENCE> ** AGAIN**

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 45: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now IN : <SENTENCE> ** AGAIN**

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 46: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <NOUNPHRASE>

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

CONJ <Sentence>

<Noun-Phrase>

<VerbPhrase>

Page 47: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now IN : <NOUNPHRASE>

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 48: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : ProNoun, ProperNoun, Article,

or Noun

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 49: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Article

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 50: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Article

"the"ARTICLE

"*"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 51: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Article

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 52: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still IN : <NOUNPHRASE>

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 53: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <ADJECTIVELIST>

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

<Adjective-List>

ProNoun

ProperNoun

Article

Noun

Page 54: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now IN : <ADJECTIVELIST>

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

{nothing}

Adjective

Page 55: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : Adjective

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

{nothing}

Adjective

Page 56: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Adjective NOT FOUND, RETURN..

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

{nothing}

Adjective

Page 57: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Back IN : <NOUNPHRASE>

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 58: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : Noun

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 59: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Noun

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 60: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Noun

"elephant"NOUN

"barrus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 61: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Noun

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

"elephant"NOUN

"barrus"

Page 62: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Leaving : <NOUNPHRASE>

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 63: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Back IN : <SENTENCE>

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 64: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <VERBPHRASE>

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"CONJ <Sentence>

<NounPhrase><Verb-

Phrase>

Page 65: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now IN : <VERBPHRASE>

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 66: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <ADVERBLIST> or Verb

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 67: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Verb

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 68: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Verb

"thinks"VERB

"cogito"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 69: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Verb

"this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

"thinks"VERB

"cogito"

Page 70: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still IN : <VERBPHRASE>

"this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 71: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <NOUNPHRASE> OR <ADVERBLIST>

"this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 72: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

FOUND : Article GOTO <NOUNPHRASE>

"this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 73: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now IN : <NOUNPHRASE>

"this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 74: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : ProNoun, ProperNoun, Article,

or Noun

"this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 75: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Article

"this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 76: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Article "this"ARTICLE"addo"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 77: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Article

"thought"NOUN

"cogitatus"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

Page 78: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still IN : <NOUNPHRASE>

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 79: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <ADJECTIVELIST>

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

<Adjective-List>

ProNoun

ProperNoun

Article

Noun

Page 80: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now IN : <ADJECTIVELIST>

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

{nothing}

Adjective

Page 81: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : Adjective

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

{nothing}

Adjective

Page 82: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Adjective NOT FOUND, RETURN..

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

{nothing}

Adjective

Page 83: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Back IN : <NOUNPHRASE>

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 84: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : Noun

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 85: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Noun

"thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 86: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Noun "thought"NOUN

"cogitatus"

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"Push TOKEN onto QUEUE.

Get next symbol.Find in Dictionary.

Page 87: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : Noun

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"Push TOKEN onto QUEUE.

Get next symbol.Find in Dictionary.

"thought"NOUN

"cogitatus"

NOT FOUND....---but we don't know or

care yet---

Page 88: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Leaving : <NOUNPHRASE>

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

<AdjectiveList>

ProNoun

ProperNoun

Article

Noun

Page 89: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Still IN : <VERBPHRASE>

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 90: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : <ADVERBLIST> OR NOT

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 91: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

FOUND : NOT, RETURN..

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

<NounPhrase> <AdverbList>Verb

<AdverbList> Verb <NounPhrase>

Page 92: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Back TO : <SENTENCE> ** AGAIN**

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 93: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : CONJUNCTION or NOT

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 94: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

FOUND : NOT, RETURN..

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 95: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Back TO : <SENTENCE>

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 96: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now Leaving : <SENTENCE>

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

CONJ <Sentence>

<NounPhrase> <VerbPhrase>

Page 97: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Finally Back TO : <STATEMENT>

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

<Sentence> PUNCT

Page 98: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

EXPECTING : PUNCTUATION

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

<Sentence> PUNCT

Page 99: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : PUNCTUATION

"."??""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

<Sentence> PUNCT

Page 100: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : PUNCTUATION"." / ?? / ""

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

Push TOKEN onto QUEUE.Get next symbol.Find in Dictionary.

Page 101: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

MATCH : PUNCTUATION

EOLN

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

Push TOKEN onto QUEUE.Get next symbol.END-OF-LINE

"." / ?? / ""

Page 102: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

The bearded lady hides but the elephant thinks this

thought.

Now Leaving : <STATEMENT>

EOLN

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

"." / ?? / ""

Page 103: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

--DONE PARSING--

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

"." / ?? / ""

on to the next phase,but first.....

Page 104: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

What the QUEUE ACTUALLY Looks Like

(with TOKENS rather than WORDS)

Page 105: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

What the QUEUE ACTUALLY Looks Like

"The"ARTICLE

"*"

"bearded"ADJECTIVE"baratus"

"lady"NOUN

"domina"

"hides"VERB

"abscondo"

"but"CONJ

"ceterum"

"the"ARTICLE

"*"

"elephant"NOUN

"barrus"

"thinks"VERB

"cogito"

"this"ARTICLE"addo"

"thought"NOUN

"cogitatus"

"." / ?? / ""

the queue

tokens

Page 106: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

What remains is to pull off the TOKENS,

one by one,if it is a WORD

then print out the translation,if it is NOT

then print IT out.

Page 107: CS Example: Parsing a Sentence

© K.Becker Cpsc 233 Parse a Sentence

AND TA-DA!!!!

A ten-word nonsense statement gets translated into

equally non-sensical Latin using a mere few hundred

lines of code.


Recommended