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>
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'};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.