Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

While passwords generally have few restrictions, they are normally not totally f

ID: 3793773 • Letter: W

Question

While passwords generally have few restrictions, they are normally not totally free. Suppose that in a certain system passwords can be of arbitrary length, but must contain at least one letter, a...z and one number 0...9. Construct a grammar that generates the set of such legal passwords. Suppose that in some programming language numbers are restricted as follows: (a) a number may be signed or unsigned. (b) the value field consists of two nonempty parts, separated by a decimal point. (c) there is an optional exponent field. If present this field must contain the letter e, followed by a signed two-digit integer.Design a grammar for the such numbers. Suppose that a certain programming language permits only identifiers that begin with a letter, contain at least one but no more than three digits, and can have any number of letters. Give a grammar and an accepter for such a set of identifiers.

Explanation / Answer

PART 1:

GRAMMAR GENERATING THE SET OF LEGAL PASSWORDS CONTAINING AT LEAST ONE LETTER FROM a TO z AND ONE NUMBER FROM 0 TO 9 AND OF ARBITRARY LENGTH:

S -> S1CS2 | S2CS1

C -> S1CS2 | S2CS1 | CS1C | CS2C | CC |

S1 -> a|b|……… |z

S2 -> 0|1| …… |9

                                                                                                                                                                                   

PART 2:

GRAMMAR GENERATING THE GIVEN TYPE OF NUMBERS:

S -> S1N1.N1S2

S1 -> + | -

S2 -> e N1C N1 |

N1 -> N1C N1 | 0 | 1 | … |9

C -> N1C N1 |

                                                                                                                                                            

S -> S1CS2 | S2CS1

C -> S1CS2 | S2CS1 | CS1C | CS2C | CC |

S1 -> a|b|……… |z

S2 -> 0|1| …… |9