[PDF] [PDF] 131 Languages and Grammar

ICS 241: Discrete Mathematics II (Spring 2015) 13 1 Languages and Grammar Formal Language Formal language is a language that is specified by a 



Previous PDF Next PDF





[PDF] Languages, Grammars, and Machines - UTSA computer science

from S by applying a sequence of productions CS 2233 Discrete Mathematical Structures Languages, Grammars, and Machines – 3 3 Example Grammar 1



[PDF] 131 Languages and Grammar

ICS 241: Discrete Mathematics II (Spring 2015) 13 1 Languages and Grammar Formal Language Formal language is a language that is specified by a 



[PDF] CST 2016-17 Part IA Discrete Mathematics Formal Languages and

CST 2016-17 Part IA Discrete Mathematics Formal Languages and Automata Exercise Sheet 1 Inductive definitions Exercise 1 1 Let L be the subset of {a, 



[PDF] Formal Languages

Languages Discrete Mathematical Structures A language is a set of strings over some alphabet L Σ¡ The concatenation of languages L and M LM £ ¡ st



[PDF] 21-Words and Languageskey

Discrete Mathematics – Words and Languages 21- Alphabets and Strings An alphabet is any finite set Σ Its elements are called symbols or letters {0,1} a 



[PDF] Notes on Discrete Mathematics - Rensselaer Computer Science

These notes contain the material from Discrete Mathematics that you need to know in Problem 8 Rephrase the definition of a partition in a simpler language



[PDF] CPS 102: Discrete Mathematics Assignment 1 1 A Tool for Proving

12 sept 2007 · When proving that a language isn't regular, a tool that is often used is the following lemma Below is its formal statement: If L is a regular 



[PDF] The Mathematical Theory of Formal Languages - itscaltechedu

3, 295–310 Matilde Marcolli and Doris Tsao Formal Languages Page 3 A very general abstract setting to describe languages (natural or artificial: human 



[PDF] 1 Grammars - TCD Maths home

MA2C03 - DISCRETE MATHEMATICS - TUTORIAL NOTES A The language generated by the context-free grammar (V,A,< s >,P) is a subset L ⊆ A∗



[PDF] CSE 20 Discrete math - UCSD CSE

Yes: every finite language is regular D I don't know Page 10 Regular languages: general facts

[PDF] languages in south korea

[PDF] langue and parole ignou

[PDF] langue and parole in linguistics with examples

[PDF] langue and parole meaning in hindi

[PDF] langue and parole pdf

[PDF] langue and parole short notes

[PDF] langue des gitan d'espagne 4 lettres

[PDF] langue des signes québécoise (lsq)

[PDF] langue des signes québécoise alphabet

[PDF] langue des signes québécoise dictionnaire

[PDF] langue des signes québécoise gatineau

[PDF] langue elfique traducteur

[PDF] langue elfique traduction

[PDF] langue elfique traduire

[PDF] langue en pays zoulou

ICS 241: Discrete Mathematics II (Spring 2015)

13.1 Languages and Grammar

Formal Language

Formal languageis a language that is specified by a well-defined set of rules of syntax.

Formal Grammar

Aformal grammarGis any compact, precise definition of a languageL. A grammar implies an algorithm that would generate all legal sentences of the language.

Phrase-structure Grammar

First, some definitions.

Vocabulary

Avocabulary(oralphabet)Vis a finite, nonempty set of elements calledsymbols. Word Aword(orsentence) overVis a string of finite length elements ofV.

Empty String

The empty string or null string, denoted by, is the string containing no symbols.

Set of Words & Set of Language

The set of all words overVis denoted byV. AlanguageoverVis a subset ofV.

Phrase-Structure Grammar

Aphrase-structure grammarG= (V;T;S;P)consists of a vocabularyV, a subsetTofVcon- sisting of terminal symbols, a start symbolSfromV, and a finite set of productionsP. The set VTis denoted byN. Elements ofNare callednonterminal symbols. Every production inP must contain at least one nonterminal on its left side.

Derivability

LetG= (V;T;S;P)be a phrase-structure grammar. Letw0=lzor(that is, the concatenation of l;z o;andr) andw1=lz1rbe strings overV. Ifzo!z1is a production ofG, we say thatw1is directly derivablefromw0and we writew0)w1. Ifw0;w1;:::;wnare strings overVsuch that w

0)w1;w1)w2;:::;wn1)wn, then we say thatwnisderivable fromw0, and we write

w

0=)wn. The sequence of steps used to obtainwnfromw0is called aderivation.

1

ICS 241: Discrete Mathematics II (Spring 2015)

Language Generated byG,L(G)

LetG= (V;T;S;P)be a phrase-structure grammar. Thelanguage generated byG(or thelan- guage ofG), denoted byL(G), is the set of all strings of terminals that are derivable from the starting stateS. In other words,

L(G) =fw2TjS=)wg

Types of GrammarsTypeRestrictions on Productionsw1!w20No restrictions 1w

1=lArandw2=lwr, whereA2N;l;r;w2(N[T)andw6=; orw1=Sand

w

2=as long asSis not on the right-hand side of another production2w

1=A, whereAis a nonterminal symbol3w

1=Aandw2=aBorw2=a, whereA2N;B2N;anda2T; orw1=Sand

w

2=Derivation Trees

A derivation in the language generated by a context-free grammar can be represented graphically using an ordered rooted tree, called aderivation, orparse tree. The root of this tree represents the starting symbol. The internal vertices of the tree represent the nonterminal symbols that arise in the derivation. The leaves of the tree represent the terminal symbols that arise. If the production A!warises in the derivation, wherewis a word, the vertex that representsAhas as children vertices that represent each symbol inw, in order from left to right.

Backus-Naur Form

TheBackus-Naur form (BNF)is used to specify the syntactic rules of many computer languages, including Java. The productions in a type 2 grammar have a single nonterminal symbol as their left-hand side. Instead of listing all the productions separately, we can combine all those with the same nonterminal symbol on the left-hand side into one statement. Instead of using the symbol! in a production, we use the symbol ::=. We enclose all nonterminal symbols in brackets,hi, and we list all the right-hand sides of productions in the same statement, separating them by bars.

An example of BNF

hlcletteri::=ajbjcjjz

13.1 pg. 856 # 5

LetG= (V;T;S;P)be the phrase-structure grammar withV=f0;1;A;B;Sg,T=f0;1g, and set of productionsPconsisting ofS!0A;S!1A;A!0B;B!1A;B!1. a) Sho wthat 10101 bel ongsto the language generated by G.

S)1A)10B)101A)1010B)10101

2

ICS 241: Discrete Mathematics II (Spring 2015)

b) Sho wthat 10110 does not belon gto the language generated by G. Notice the two adjacent 1s in the string. By looking at our set of productions,Pdoes not contain any rules that allow two 1s to be adjacent to each other. c)

What is the language generated by G?

By looking at our set of production rules, we can easily see that our string must first start with either 0 or 1 because ofS!0AandS!1A. The question now becomes what comes after the first symbol. We first consider the rulesA!0B, andB!1A. By looking at these rules, we know that the symbols that follow the first symbol will alternate between

0 and 1. So we get101Aor001A. We also know that our string can only terminate by

using the ruleB!1. In addition, we know that each 1 is preceded by a 0. So this means we will have one or more01"s following the first symbol. The language generated byGis f0(01)njn1g [ f1(01)njn1g.

13.1 pg. 856 # 13

Find a phrase-structure grammar for each of these languages. a) the set cons istingof the bit strings 0, 1, and 11 LetG= (V;T;S;P)be the phrase-structure grammar withV=f0;1;Sg,T=f0;1g, and set of productionsPconsisting ofS!0;S!1;S!11. b) the set of bit stri ngscontaining only 1s LetG= (V;T;S;P)be the phrase-structure grammar withV=f1;S;Ag,T=f1g, and set of productionsPconsisting ofS!1A;A!1A;A!. c) the set of bi tstrings that start with 0 and end with 1 LetG= (V;T;S;P)be the phrase-structure grammar withV=f0;1;S;Ag,T=f0;1g, and set of productionsPconsisting ofS!0A1;A!0A;A!1A;A!. d) the set of bit stri ngsthat consist of a 0 follo wedby an e vennumber of 1s. LetG= (V;T;S;P)be the phrase-structure grammar withV=f0;1;S;Ag,T=f0;1g, and set of productionsPconsisting ofS!0A;A!11A;A!.

13.1 pg. 856 # 17

Construct phrase-structure grammars to generate each of these sets. a)f0njn0g LetG= (V;T;S;P)be the phrase-structure grammar withV=f0;Sg,T=f0g, and set of productionsPconsisting ofS!0S;S!. b)f1n0jn0g LetG= (V;T;S;P)be the phrase-structure grammar withV=f0;1;S;Ag,T=f0;1g, and set of productionsPconsisting ofS!A0;A!A1;A!. 3

ICS 241: Discrete Mathematics II (Spring 2015)

c)f(000)njn0g LetG= (V;T;S;P)be the phrase-structure grammar withV=f0;Sg,T=f0g, and set of productionsPconsisting ofS!000S;S!.

13.1 pg. 857 # 27

Construct a derivation tree for109using the given grammar. hsigned integeri::=hsignihintegeri hsigni::= +j hintegeri::=hdigitijhdigitihintegeri

hdigiti::= 0j1j2j3j4j5j6j7j8j9hsigned integerihintegerihintegerihintegerihdigiti9hdigiti0hdigiti1hsigni

13.1 pg. 857 # 31

Give production rules in Backus-Naur form for an identifier if it can consist of a) one or more lo wercasele tters. hlcletteri::=ajbjcjjz b) at least t hreeb utno more than six lo wercaseletters. hlcletteri::=ajbjcjjz 4

ICS 241: Discrete Mathematics II (Spring 2015)

c) one to six upperc aseor lo wercaseletters be ginningwith an uppercase letter . hidentifieri::=hucletterij hucletterihletterij hucletterihletterihletterij hucletterihletterihletterihletterij hletteri::=hucletterijhlcletteri hucletteri::=AjBjCjjZ hlcletteri::=ajbjcjjz d) a lo wercaseletter ,follo wedby a digit or an underscore, follo wedby three or four alphanu- meric characters (lower or uppercase letters and digits). hletteri::=hucletterijhlcletteri hucletteri::=AjBjCjjZ hlcletteri::=ajbjcjjz hdigiti::= 0j1j2jj9 5quotesdbs_dbs10.pdfusesText_16