170 likes | 264 Views
Introduction to Formal Languages. CSC 333. Introduction. A programming language like Java has rules of syntax that a programmer must obey in order for his program to compile. Likewise, a natural language, such as english or spanish , has syntax rules.
E N D
Introduction to Formal Languages CSC 333
Introduction • A programming language like Java has rules of syntax that a programmer must obey in order for his program to compile. • Likewise, a natural language, such as english or spanish, has syntax rules. • Without following them, some combinations of valid words would be meaningless or, worse, could convey the wrong meaning.
Definitions Alphabet Word Language
Definitions Alphabet Word Language Grammar – a system of rules that defines the structure of a language.
Definitions Grammar – a system of rules that defines the structure of a language. Generative grammar – a description in the form of a set of rules for producing grammatical sentences of a language.
Noam Chomsky • American linguist born in 1928 • Professor emeritus of linguistics at MIT • (also: an anarchist) • 1950’s – Developed theory of generative grammar in order to model natural languages.
Noam Chomsky • American linguist born in 1928 • Professor emeritus of linguistics at MIT • (also: an anarchist) • 1950’s – Developed theory of generative grammar in order to model natural languages. • Note that one can start with a grammar definition and derive a language, or one can attempt to define a grammar that can sufficiently describe an existing language. • Defining a grammar to describe a natural language can be quite difficult. Consider Example 40.
Examples Programming languages - 41 Use of Backus-Naur form (BNF) - 42
Chomsky Hierarchy Type 0 – unrestricted grammars Type 1- context-sensitive Type 2 – context- free Type 3 – regular
Definition A phrase-structure (type 0) grammar G is a 4-tuple, G = (V, VT, S, P), where V = vocabulary VT = a set of terminals S = the start symbol P = a set of productions (see p. 667)
Formal Languages Formal languages are languages that can be derived from grammars formally defined as in the manner of Example 36. As stated before, one can start with a grammar definition and derive a language, or one can attempt to define a grammar that can sufficiently describe an existing language.
The Erasing Convention Productions resulting in lambda, the empty string, have the effect of erasing symbols. See Example 44. The restricted Chomsky grammars obey the erasing convention, which says that if erasing is allowed, it is confined to S -> λ.
Grammars in the Chomsky Hierarchy Type 0 – unrestricted grammars. Type 1- context-sensitive: A grammar that obeys the erasing convention, and for every production α -> β (except S -> λ), the word β is at least as long as the word α. Type 2 – context- free Type 3 – regular
Grammars in the Chomsky Hierarchy Type 0 – unrestricted grammars. Type 1- context-sensitive: A grammar that obeys the erasing convention, and for every production α -> β (except S -> λ), the word β is at least as long as the word α. Type 2 – context- free: A grammar that also has the restriction that for a production α -> β, α is a single nonterminal. Type 3 – regular
Grammars in the Chomsky Hierarchy Type 0 – unrestricted grammars. Type 1- context-sensitive: A grammar that obeys the erasing convention, and for every production α -> β (except S -> λ), the word β is at least as long as the word α. Type 2 – context- free: A grammar that also has the restriction that for a production α -> β, α is a single nonterminal. Type 3 – regular: A grammar that adds the restriction that β is of the form t or tW, where t is a terminal and W is a nonterminal.
Grammar Relationships Consider the examples of grammar types cited on p. 674. See Figure 8.21.
Languages and Computational Devices FSMs recognize regular languages (type 3). PDAs recognize context-free languages (type 2). LBAs recognize context-sensitive languages. Turing machines recognize type 0 languages.