Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 6 Introduction to grammars Vectors in C++ Lab Exercise.

Similar presentations


Presentation on theme: "Lab 6 Introduction to grammars Vectors in C++ Lab Exercise."— Presentation transcript:

1 Lab 6 Introduction to grammars Vectors in C++ Lab Exercise

2 What is a grammar A grammar is a 4-tuple (N, T, Π, S)
 A terminal symbol is one that cannot be broken down further A non-terminal symbol is a symbol that can be reduced further by the production rules N∩T The language of a grammar is the set of strings it generates. S → NP VP NP → the N VP → V NP V → sings | eats N → cat | song | canary

3 Terminals: the, sing, eat, cat, canary, song
Non-terminals: S, NP, VP, V, N Start-Symbol: S Some strings: “the canary sings the song” “the song eats the cat”

4 Recursive vs Non-Recursive
A grammar is called a recursive grammar if it contains production rules that are recursive, expanding a non-terminal according to these rules can eventually lead to a string that includes the same non- terminal again. Word -> A B A -> a A -> b A -> B B -> c B -> d

5 Vectors It is a container that can store elements, but its size can change dynamically Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators. vector<dataType> vectorName; Push_back(),pop_back(),size(),erase(),swap(),insert()…..

6 Lab 6


Download ppt "Lab 6 Introduction to grammars Vectors in C++ Lab Exercise."

Similar presentations


Ads by Google