LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG.

Slides:



Advertisements
Similar presentations
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27.
Advertisements

About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 16: 10/19.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 10: 9/27.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/4.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
LING 364: Introduction to Formal Semantics
LING 388: Language and Computers Sandiway Fong Lecture 21: 11/7.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/11.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 11: 10/3.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
Fall 2007CS 2251 Miscellaneous Topics Deque Recursion and Grammars.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/3.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/7.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
LING 388 Language and Computers Lecture 11 10/7/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 10: 9/26.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 5: 9/5.
LING 388 Language and Computers Lecture 9 9/30/03 Sandiway FONG.
Chapter 3: Formal Translation Models
LING 364: Introduction to Formal Semantics Lecture 5 January 26th.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
LING 388: Language and Computers Sandiway Fong Lecture 7.
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
Normal Forms for Context-Free Grammars Definition: A symbol X in V  T is useless in a CFG G=(V, T, P, S) if there does not exist a derivation of the form.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
Grammars CPSC 5135.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
Introduction to Language Theory
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
CSE 425: Syntax II Context Free Grammars and BNF In context free grammars (CFGs), structures are independent of the other structures surrounding them Backus-Naur.
Context Free Grammars.
LING 388: Language and Computers Sandiway Fong 9/27 Lecture 10.
Lecture 11 Theory of AUTOMATA
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong. Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers.
Re-enter Chomsky More about grammars. 2 Parse trees S  A B A  aA | a B  bB | b Consider L = { a m b n | m, n > 0 } (one/more a ’s followed by one/more.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
1 Chapter 6 Simplification of CFGs and Normal Forms.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
LING/C SC/PSYC 438/538 Lecture 16 Sandiway Fong. SWI Prolog Grammar rules are translated when the program is loaded into Prolog rules. Solves the mystery.
Formal Languages and Grammars
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Chapter 4: Syntax analysis Syntax analysis is done by the parser. –Detects whether the program is written following the grammar rules and reports syntax.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Syntax Analysis By Noor Dhia Syntax analysis:- Syntax analysis or parsing is the most important phase of a compiler. The syntax analyzer considers.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong. Last Time Talked about: – 1. Declarative (logical) reading of grammar rules – 2. Prolog query: s(String,[]).
Lecture 17: Theory of Automata:2014 Context Free Grammars.
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Describing Syntax and Semantics Chapter 3: Describing Syntax and Semantics Lectures # 6.
Complexity and Computability Theory I
PARSE TREES.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Regular Grammar.
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong.
CFGs: Formal Definition
Recap Lecture 3 RE, Recursive definition of RE, defining languages by RE, { x}*, { x}+, {a+b}*, Language of strings having exactly one aa, Language of.
Presentation transcript:

LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG

Administrivia Poll: 2 nd Call for votes Poll: 2 nd Call for votes  How many would want an extra (optional) introductory computer lab session?  Send to Charles

Administrivia Reminder Reminder  Next Tuesday  Computer Lab Class Meet in SBS 224Meet in SBS 224  Next Thursday  Computer Lab Class continues…  Homework 2 will be handed out

Review Last Lecture: Last Lecture:  Formal Grammars  production rules  X -> Y 1 …Y n n>=0 X  V N, Y i  (V N u V T ) 1<=i<=nX  V N, Y i  (V N u V T ) 1<=i<=n  rule application and sentential forms S =>* ,   (V N u V T )*S =>* ,   (V N u V T )* –=>* means “derives through zero or more rule applications”

Regular Grammars Regular Grammars are a class of formal grammars with a special restriction Regular Grammars are a class of formal grammars with a special restriction  aka Chomsky hierarchy type-3 grammars  Production rules are constrained to have format: X -> Y tX -> t (left recursive)X -> Y tX -> t (left recursive)  or X -> t YX -> t (right recursive)X -> t YX -> t (right recursive)  where X,Y  V N, t  V T i.e. all rules contain only a single non-terminal, and (possibly) a single terminal) on the right hand side  Note:  can’t have both left and right recursive rules at the same time

Regular Grammars (Remarkable) Property (Remarkable) Property  Regular grammars are formally equivalent to FSA (and regular expressions)

Regular Grammars Example: Example:  Grammar G ab  S -> aB  B -> aB  B -> bC  B -> b  C -> bC  C -> b  Note: G ab is right recursive  Starting non-terminal: S  V N = {S, B, C}(set of non-terminals)  V T = {a, b}(set of terminals)

Regular Grammars Question: Question:  What does grammar G ab generate? Answer: Answer:  Language: L(G ab ) = {a + b + } “one or more a s followed by one or more b s”

Regular Grammars Example of Derivation: Example of Derivation:  S  aB  aaB (using rule B -> aB)  … can iterate this to get aa…aB – i.e. any number of a s  From aaB, we can get:  aab(using rule B-> b) OR  aabC(using rule B-> bC)  aabbC(using rule C-> bC) … can iterate this to get aabb…bC – i.e. any number of b s… can iterate this to get aabb…bC – i.e. any number of b s  From aabbC, we can get: aabbbb(using rule C-> b)aabbbb(using rule C-> b)

Regular Grammars Consider a FSA equivalent to G ab that also describes L ab = {a + b + } Consider a FSA equivalent to G ab that also describes L ab = {a + b + }

Equivalent FSA SB C a a b b

Regular Grammars FSA Cases (right- recursive): Cases (right- recursive):  A -> a  A -> aB  A -> aA Note: Note:  A left-recursive grammar can be transformed to a weakly-equivalent right-recursive one a a A B A a A

Equivalent FSA Basically, we have that… Basically, we have that…  Each non-terminal corresponds to a state  Each terminal corresponds to a transition between two states  A recursive rule is implemented by a loop

Limitations Production Rule Limitation: Production Rule Limitation:  can’t have both left and right recursive rules at the same time  e.g. can’t have rules A -> aBA -> aB A -> BaA -> Ba in the same grammar  Question: Why?  Answer:  Would change the expressive power of the grammar formalism No longer preserve the equivalence with FSA and regular expressionsNo longer preserve the equivalence with FSA and regular expressions

Limitations Example: Example:  L = {a n b n | n>=0 } is not a regular language  However, the following grammar (with both left- recursive and right-recursive rules) will generate L :  A ->   A -> aB  B -> Ab  B -> b  Starting non-terminal: A

Limitations Sample Derivations : Sample Derivations :  A  aB  aAb  ab (using rule A -> )  or  aaBb aabb (using rule B -> b)aabb (using rule B -> b)  or aaAbbaaAbb aaaBbbaaaBbb aaabbb(using rule B -> b)aaabbb(using rule B -> b)

Definite Clauses Grammars (DCG) Introduction Introduction  DCGs are built-in to Prolog  Prolog was originally designed for natural language processing  Notation designed for a transparent encoding of grammar production rules in the database  Can handle general grammars  … not just regular grammars  Next Thursday’s Computer Lab

Definite Clause Grammars (DCG) Syntax : Syntax :  We have been writing production rules like  X -> Y t  In Prolog notation, the equivalent DCG rule looks something like  x --> y, [t]. Notes: Notes:  --> replaces ->  Terminal symbols are distinguished from non-terminal symbols by enclosing them in square brackets, e.g. [t]  All terminal and non-terminal symbols begin with a lowercase letter, i.e. are names  General case: can be structures  Commas separate symbols on the right hand side of the rule  A DCG rule ends with a period

Definite Clause Grammars (DCG) Example grammar: Example grammar:  Grammar G ab L(G ab ) = {a + b + }L(G ab ) = {a + b + }  Production Rules: S -> aBs --> [a],b.S -> aBs --> [a],b. B -> aBb --> [a],b.B -> aBb --> [a],b. B -> bCb --> [b],c.B -> bCb --> [b],c. B -> bb --> [b].B -> bb --> [b]. C -> bCc --> [b],c.C -> bCc --> [b],c. C -> bc --> [b].C -> bc --> [b].

Definite Clause Grammars (DCG) Querying the grammar: Querying the grammar:  Each DCG rule like x --> [a,b]. defines a clause for x/2  In x(X,Y)  X represents the input list to be parsed  Y represents the remainder of the input list after rule x has been parsed  In Prolog parlance, the pair X,Y is known as a difference list  Example queries:  ?- s([a,a,b,b,b],[]).  Yes.  ?- s([a,b,a],[]).  No.