Download presentation
Presentation is loading. Please wait.
Published byJaana Jääskeläinen Modified over 6 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.