0 Up votes0 Down votes

4 views7 pagesMELJUN CORTES Automata Lecture Ambiguity 1

Jun 12, 2015

© © All Rights Reserved

PDF, TXT or read online from Scribd

MELJUN CORTES Automata Lecture Ambiguity 1

© All Rights Reserved

4 views

MELJUN CORTES Automata Lecture Ambiguity 1

© All Rights Reserved

- GSM UMTS LTE PM and CM program
- Bai Chua Band 6.5_Ngoc Bach
- Embedded Seminar
- class9
- In-class flip
- 204
- azFatCFG.ppt
- PDF2015_Paper II_J 8715 Paper II Computer Science
- Y3 English P2
- SciAm 1983 12 Hayes FSA
- More Ties Than We Thought
- CS2303-2mark.pdf
- Worksheet 1 - 11th Grade - 3rd Term
- Newsletter Midterm
- CD-tut2.doc
- TOC Questions
- oct ('06)-1 - Spoken English
- inglês 7º
- Syslog Ng Ose v3.4 Guide Admin
- TP7

You are on page 1of 7

Specific Objectives:

At the end of the topic session, the students are expected to:

Cognitive:

1. Formally define ambiguity in context-free grammars.

2. Show if strings are derived ambiguously given a certain

grammar.

Affective:

1. Listen to others with respect.

2. Participate in class discussions actively.

MATERIALS/EQUIPMENT:

o

o

topic slides

OHP

TOPIC PREPARATION:

o

o

o

o

Ambiguity

previous courses.

Prepare the slides to be presented in class.

It is imperative for the instructor to incorporate various kinds of

teaching strategies while discussing the suggested topics.

Prepare additional examples on the topic to be presented.

*Property of STI

Page 1 of 7

Ambiguity

Page 1 of 9

Ambiguity

Ambiguity in Context-Free Grammars

Introduction

This section will deal with grammars that may generate the same string in different

ways. This means that a string may have different meanings or structures. For

some situations, this may not cause any problem. But for applications like

programming languages where it is important to have a unique structure or

interpretation for each line of code, this may cause numerous errors.

Consider the following grammar G = (V, , R, S) where

V = {<expr>}

= {+, , a, b, c, (, )}

S = {<expr>}

and the set of rules R is

R = {<expr><expr>+<expr><expr><expr>(<expr>)abc}

Context-Free Languages

Page 2 of 9

Assume that the string a + b + c is to be derived from this grammar. The leftmost

derivation for the given string will be as follows:

1.

Starting production

<expr> <expr> + <expr>

2.

<expr> a + <expr>

3.

<expr> a + <expr> + <expr>

4.

<expr> a + b + <expr>

5.

<expr> a + b + c

<expr>

<expr>

<expr>

<expr>

Ambiguity

<expr>

*Property of STI

Page 2 of 7

Context-Free Languages

Page 3 of 9

follows:

1.

Starting production

<expr> <expr> + <expr>

2.

<expr> <expr> + <expr> + <expr>

3.

<expr> a + <expr> + <expr>

4.

<expr> a + b + <expr>

5.

<expr> a + b + c

<expr>

<expr>

<expr>

Context-Free Languages

Page 4 of 9

<expr>

<expr>

Looking at the parse tree of the first derivation, it can be shown that b and c were

added first because they are grouped together in the same subtree. This is shown

below:

<expr>

<expr>

is grouped together

<expr>

<expr>

<expr>

After performing b + c, a is then added to the sum. In other words, the string

a + b + c in this derivation actually meant a + (b + c).

Ambiguity

*Property of STI

Page 3 of 7

In the second derivation, the parse tree shows that a and b are added first because

they are grouped together in the same subtree. This is shown below:

<expr>

<expr>

<expr>

<expr>

<expr>

is grouped together

After performing a + b, c is then added to the sum. In other words, the string

a + b + c in this derivation actually meant (a + b) + c.

This is now an example of how a certain string can be derived differently using the

same grammar. For each derivation, the string a + b + c actually has two different

meanings or interpretations.

If a string can be derived from a grammar in more than one way, then the grammar

is said to be ambiguous and the string is derived ambiguously. So the string

a + b + c was derived ambiguously using grammar G. Therefore, grammar G is

ambiguous.

Another way of stating this is when a string has two or more different leftmost

derivations (or rightmost derivations) or two or more derivation trees, then the

grammar is ambiguous.

In this example, no damage was done by this ambiguity since a + (b + c),

(a + b) + c, and a + b + c give the same result as a mathematical expression.

Context-Free Languages

Page 5 of 9

derivation for this string is as follows:

1.

Starting production

<expr> <expr> + <expr>

2.

<expr> a + <expr>

3.

<expr> a + <expr> <expr>

4.

<expr> a + b <expr>

5.

<expr> a + b c

Ambiguity

*Property of STI

Page 4 of 7

<expr>

<expr>

<expr>

<expr>

Context-Free Languages

Page 6 of 9

<expr>

follows:

1.

Starting production

<expr> <expr> <expr>

2.

<expr> <expr> + <expr> <expr>

3.

<expr> a + <expr> <expr>

4.

<expr> a + b <expr>

5.

<expr> a + b c

<expr>

<expr>

<expr>

Ambiguity

<expr>

<expr>

*Property of STI

Page 5 of 7

Context-Free Languages

Page 7 of 9

Looking at the parse tree of the first derivation, it can be shown that b and c were

multiplied first because they are grouped together in the same subtree. This is

shown below:

<expr>

<expr>

<expr>

<expr>

is grouped together

<expr>

After performing b c, a is then added to the product. In other words, the string

a + b c in this derivation actually meant a + (b c).

In the second derivation, the parse tree shows that a and b were added first

because they are grouped together in the same subtree. This is shown below:

<expr>

<expr>

<expr>

<expr>

<expr>

b

This implies that a + b

is grouped together

After performing a + b, c is then multiplied to the sum. In other words, the string

a + b c in this derivation actually meant (a + b) c.

As in the previous example, the string a + b c now has two different meanings or

interpretations.

Because the multiplication operation has a higher precedence over the addition

operation, the first derivation will produce the correct result. In other words the

string a + b c may be interpreted as a + (b c) but not (a + b) c.

Hence, in this example, there will be an error if the second interpretation was used.

If ambiguity in a context-free grammar will produce erroneous results, the grammar

must be rewritten to remove any ambiguities. Although removing ambiguity from a

CFG is not a part of this lesson, it will be shown in the next slide as an example.

Ambiguity

*Property of STI

Page 6 of 7

Context-Free Languages

Page 8 of 9

1.

2.

3.

<factor> (<expr>)abc

<expr>

<expr>

<term>

<term>

<term>

<factor>

<factor>

<factor>

Since there is only one leftmost (or rightmost derivation) for the string a + b c,

then there is only one interpretation and that is, a + (b c). The ambiguity has

therefore been removed.

Take note that it is not necessary to show how the grammar G was rewritten since

resolving ambiguity is not part of this discussion. IT is sufficient to simply show that

rewriting a grammar is just one method of address the problems caused by

ambiguity in context-free grammars.

Context-Free Languages

Page 9 of 9

A string w is derived ambiguously in context-free grammar G if it has two or more

distinct leftmost derivations, two or more distinct rightmost derivations, or two or

more distinct parse trees.

Grammar G is ambiguous if it generates some string ambiguously.

[Ambiguity, Pages 19 of 9]

Ambiguity

*Property of STI

Page 7 of 7

- GSM UMTS LTE PM and CM programUploaded byozturk
- Bai Chua Band 6.5_Ngoc BachUploaded byvantienbk
- Embedded SeminarUploaded byRasesh Shah
- class9Uploaded byapi-20012397
- In-class flipUploaded byAlejandraLeguizamon
- 204Uploaded byarash
- azFatCFG.pptUploaded bypaksmiler
- PDF2015_Paper II_J 8715 Paper II Computer ScienceUploaded byPreeti Singh
- Y3 English P2Uploaded byYuthishDheeranManiam
- SciAm 1983 12 Hayes FSAUploaded byseila09
- More Ties Than We ThoughtUploaded byJeremy Dotson
- CS2303-2mark.pdfUploaded bymariadem
- Worksheet 1 - 11th Grade - 3rd TermUploaded bywilliamces507
- Newsletter MidtermUploaded bykelliedeaton
- CD-tut2.docUploaded byShivani Varshney
- TOC QuestionsUploaded byjyothimidhuna
- oct ('06)-1 - Spoken EnglishUploaded bySridevi Voduru
- inglês 7ºUploaded byAngel Wood
- Syslog Ng Ose v3.4 Guide AdminUploaded byJeanderson Soares
- TP7Uploaded bySapnaDileesh
- 8-11-2010-ANTLR_ ASTUploaded bythinkpink
- Welcome 2(English Version)Uploaded byarmir_h
- DCSUploaded bySK
- Prolog CodingUploaded bycaixadelixo
- Freer Practice for Inf and GerundUploaded byAnonymous I69vE0c3A
- Presente, Pasado y Futuro SimpleUploaded byLily Bc
- Curso de Ingles Nivel MedioUploaded byapi-3707729
- Present Continuous Tense NewUploaded byIrna Nurhidayah
- CL I Index 2013-14Uploaded bypoopapule
- Present Tense1Uploaded byRafidah Eksan

- TCU 2019 Certificate Recognization SERVICE AWARD 5 YearsUploaded byMELJUN CORTES, MBA,MPA
- TCU 2018 Certificate of Recognition Outstanding FacultyUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 2nd Semester 2018 2019Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 1st Semester 2018 2019Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 2nd Semester 2017 2018Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 1st Semester 2017 2018Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 2nd Semester 2016 2017Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 1st Semester 2016 2017Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 2nd Semester 2015 2016Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 1st Semester 2015 2016Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 2nd Semester 2014 2015Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Evaluation Faculty TCU Taguig City 1st Semester 2014 2015Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU 2019 Certificate Recognization SERVICE AWARD 5 years of TCU OSASUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU 2018 Certificate of Recognition Outstanding Faculty of TCUUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA License NC III BookkeepingUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA License NC II CSS Computer Systems ServicingUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA TM 1 2016 Trainer's Methodology IUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA Data Encoder Eligibility 2Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA Data Encoder Eligibility 1Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA License NC II PC OperationsUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA License NC I Data EncoderUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA License NC I TechnicianUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA 2009 Tm Am Trainers AMUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TESDA 2009 CHS NC II 392 Hours Certificate of Training Computer Hardware ServicingUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU OSAS 2019 Certificate Recognization SERVICE AWARD 5 YearsUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU 2018 Certificate of Recognition Outstanding Faculty - TEACHERUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES IBM COGNOS Certified 2013Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES IBM Training Certificate DATA WareHousingUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES IBM Training Certificate BIG DATAUploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES IBM Training Certificate Predictive AnalyticsUploaded byMELJUN CORTES, MBA,MPA

- Introduction of Linguistics ( Makalah )Uploaded byAtiQa
- Music Educators Journal 1982 Elliott 33 60Uploaded byJovana Dobrijević
- Prokofiev Troika LessonPlansK-5Uploaded byCamile Tatiane
- Jamia Millia IslamiaUploaded byMushtak Mufti
- Total Physical Response&Silent WayUploaded bymuhittin yakut
- Icaew Cfab Asr 2019 Study GuideUploaded byAnonymous ulFku1v
- Marko Markovic- Primjer Za CVUploaded byCuriousMinddd
- digital unit plan fitnessUploaded byapi-388372875
- scoringandgradingppt-170104085136Uploaded byAulia Dina Wahyuningtyas
- Table 3 - Diploma Projek Tahun Akhir 2Uploaded byFord Katim
- MOVs-jm.docxUploaded byshai24
- 295117459 St Louis Reviewer 1Uploaded byRodel
- roche syllabus physical scienceUploaded byapi-293196694
- Pre - School Teacher Trainer Handbook : KannadaUploaded byAkshara Foundation
- Tuitions Should Be BannedUploaded byAkshit Gupta
- TnD(3)Uploaded byKop Pradeep
- Assessing ReadingUploaded byFrancisco Naranjo
- cardinal stritch advisor resume 0 6 2017Uploaded byapi-367964020
- Distributed Leadership and Psychological SafetyUploaded bySerdar Yener
- MFDS Part 1.pdfUploaded byferasallan
- Population Welfare Program and ServicesUploaded byAdeel Ahmed Khan
- Sf 5 Modified2 BethUploaded byYrneh Maquiling
- copyofilluminatedletters-56Uploaded byapi-300439474
- Teaching Thinking Skill ScienceUploaded byElditya Fransiska
- LOGIC Instructional Material Module 1Uploaded byJun Bernados
- internalization guide 5-8 eurekaUploaded byapi-377842893
- Classroom Assessment (Marzano, 2006).docxUploaded byKadek Satya
- project web essay final draftUploaded byapi-254004647
- Snowden CV 2013Uploaded bySteven Snowden
- The Impact of Free Primary Education on Pupil-Teacher Ratio in Kuria East Constituency, KenyaUploaded byIOSRjournal

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.