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

Give an EBNF grammar for each of the languages below. Use the EBNF extensions wh

ID: 3789443 • Letter: G

Question

Give an EBNF grammar for each of the languages below. Use the EBNF extensions wherever possible to simplify the grammars. In particular, you should eliminate explicit recursion from the grammars wherever possible. Don't forget to put single quotes around and EBNF metasymbol when using it as a token.
<S> :: = ab <S> | <empty>

g. The set of all strings consistingof one or more as with a semicolon after each one. h. The set of all strings consisting of the keyword begin, followed by one or more statements with a semicolon after each one, followed by the keyword end. Use the non-terminal

Explanation / Answer

In EBNF, a comma (,) is used for concatenation, curly braces { } for repetition. All productions end with a semi colon ;

For the first language, it accepts an empty string or any any number of 'ab' together. This is written in EBNF as a repetition
S={'ab'}

question g:
------------
We need a 'a' followed by semicolon and then this same pattern can repeat. So the terminal symbols like 'a' and semicolon or written in quotes and just remember comma is used to indicate concatenation

S='a',';',{'a',';'};

question h:
-----------
This has a keyword 'begin' followed by non-terminal <statment> followed by a semi-colon. This can be followed by a repeation of <statement> and semicolon and finally followed by keyword 'end'

S='begin',<statement>,';',{<statement>, ';'}, 'end';

question i:
-----------
Here comma itself is a character in the language. The production implies that 'a' is followed by repeatition of comma and 'a'. Since the comma is inside the repeatition group, it will only come in between any 2 'a's.

S='a', {',','a'};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote