In: Computer Science
Write EBNF descriptions for the following:
• a Java For each statement
Assume that EBNF descriptions for statement(s), type, array, white space are given. (statmnts, type, array, and whitespace respectively)
You have to create EBNF descriptions for For each statement and also variable.
Use the following Java variable naming rules to create EBNF description for variable.
o All variable names must begin with a letter of the alphabet, an underscore ( _ ) , or a dollar sign ( $ ).
o After the first initial letter, variable names may also contain letters and the digits 0 to 9. No spaces or special characters are allowed.
Assume that EBNF description for alphabet (including both upper and lower cases) and digits (0 – 9) are given. (alphabet and digit respectively)
EBNF:-
<statements> -> statmnts; | <for> | statmnts;<statements>
<for> -> for '(' <type> <variable> ':' <array> ')' '{' <statements> '}'
<variable> -> ('_' | '$' | <alpha>)<var>
<var> -> ('' | '$' | <alpha> | <num>)<var> | '' | '$' | <alpha> | <num>|epsilon
<type> -> type
<array> -> array
<alpha> -> alphabet
<num> -> digit
let example:-
for(type alphabet : array){
statmnts;
}
<statements> -> <for>
-> for '(' <type> <variable> ':' <array> ')' '{' <statements> '}'
-> for '(' type <variable> ':' <array> ')' '{' <statements> '}'
->for '(' type <alpha><var> ':' <array> ')' '{' <statements> '}'
->for '(' type alphabet<var> ':' <array> ')' '{' <statements> '}'
->for '(' type alphabet ':' <array> ')' '{' <statements> '}'
->for '(' type alphabet ':' array ')' '{' <statements> '}'
->for '(' type alphabet ':' array ')' '{' statmnts; '}'
one more example:-
for(type alphabet : array){
for(type _alphabet : array){
statmnts;
statmnts;
}
}
<statements> -> <for>
-> for '(' <type> <variable> ':' <array> ')' '{' <statements> '}'
-> for '(' type <variable> ':' <array> ')' '{' <statements> '}'
->for '(' type <alpha><var> ':' <array> ')' '{' <statements> '}'
->for '(' type alphabet<var> ':' <array> ')' '{' <statements> '}'
->for '(' type alphabet ':' <array> ')' '{' <statements> '}'
->for '(' type alphabet ':' array ')' '{' <statements> '}'
->for '(' type alphabet ':' array ')' '{' <for> '}'
->for '(' type alphabet ':' array ')' '{' for '(' <type> <variable> ':' <array> ')' '{' <statements> '}' '}'
->for '(' type alphabet ':' array ')' '{' for '(' type <variable> ':' <array> ')' '{' <statements> '}' '}'
->for '(' type alphabet ':' array ')' '{' for '(' type _<alpha> ':' <array> ')' '{' <statements> '}' '}'
->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' <array> ')' '{' <statements> '}' '}'
->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' array ')' '{' <statements> '}' '}'
->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' array ')' '{' statmnts;<statements> '}' '}'
->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' array ')' '{' statmnts; statmnts; '}' '}'