KINDLY ANSWER IN AN HOUR Consider the language LangComments that defines the form of comments included in a computer pro
Posted: Fri May 20, 2022 11:05 am
KINDLY ANSWER IN AN HOUR
Consider the language LangComments that defines the form
of comments included in a computer program. Comments are denoted by
an opening comment symbol ‘{’ and a closing comment symbol ‘}’.
Each opening comment symbol must have a matching closing comment
symbol. Further, the symbols */ and /* can be used to denote two
opening and two closing comment symbols respectively. A string of
mixed comment symbols is legal if and only if the string produced
by replacing */ with {{ and /* with }} is a balanced comments
sequence.
Define an unambiguous grammar for LangComments. (6
marks)
Using your grammar defined in (i) above, draw the parse
tree for the following sequence: */{/*}. (2 marks)
Show that the following grammar is ambiguous by finding
a string that has two different syntax trees. (2
marks)
T → val | T - val | -T
Transform the grammar in (b) above into an unambiguous
grammar where prefix minus binds stronger than infix minus, and
show that your new grammar is unambiguous by using it to generate a
parse tree for the string you provided in (b) above. (5
marks)
Consider the language LangComments that defines the form
of comments included in a computer program. Comments are denoted by
an opening comment symbol ‘{’ and a closing comment symbol ‘}’.
Each opening comment symbol must have a matching closing comment
symbol. Further, the symbols */ and /* can be used to denote two
opening and two closing comment symbols respectively. A string of
mixed comment symbols is legal if and only if the string produced
by replacing */ with {{ and /* with }} is a balanced comments
sequence.
Define an unambiguous grammar for LangComments. (6
marks)
Using your grammar defined in (i) above, draw the parse
tree for the following sequence: */{/*}. (2 marks)
Show that the following grammar is ambiguous by finding
a string that has two different syntax trees. (2
marks)
T → val | T - val | -T
Transform the grammar in (b) above into an unambiguous
grammar where prefix minus binds stronger than infix minus, and
show that your new grammar is unambiguous by using it to generate a
parse tree for the string you provided in (b) above. (5
marks)