Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A grammar is a set of rules for generating strings. Write a Python program that generates random strings using the rules of a grammar. For

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

A grammar is a set of rules for generating strings. Write a Python program that generates random strings using the rules of a grammar. For example, when the program was given the strings of a grammar, it generated the following random sentences the cat bit the dog. the girl chased the boy the cat chased the boy and the boy kissed the cat the cat bit the dog and the dog kissed the girl and the dog chased the girl . Theory. To write this program, you must have a way to generate random integers. You must also know what a grammar is, and how it works Random integers. No algorithm can generate truly random integers, but it can generate pseudo-random integers that seem random, even though they're not. Python has its own random number generators, but for this project, you must implement your own The Park-Miller algorithm (named for its inventors) is a simple way to generate a sequence of pseudo-random integer terms. It works like this. Let No be an integer called the seed. The seed is the first term of the sequence and must be between 1 and 231 - 2, inclusive. Starting from the seed, later terms N?, N2, .. are produced by the following equation Ne+,-(75 %) % (231-1) Grammars. The easiest way to explain a grammar is to show an example. This is the grammar that generated the simple sentences about boys, cats, dogs, and girls that appeared in the introduction 01 Noun ?'cat ' 02 Noun ?'boy' 03 Noun ?'dog' 04 Noun ?'girl' 05 Verb ? 'bit' 06 Verb ?'chased ' 07 Verb ?'kissed' 08 Phrase ? 'the 'Noun Verb 'the' Noun 09 Storv ?Phrase 10 Story? Phrase, and' Story 11 Start ? Story

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions