1. Consider the grammar in Figure 1 (a) [5 marks] Give a parse tree for the following program fragment def fibn if less_than( ParamList ParamList Param ParamListTail ParamListTail -> ParamList Tail Param Param” src=”https://files.transtutors.com/cdn/qimg/c541ff8c454d432cb100dbe94eba4820.jpg” aria-describedby=”jmu”>

1. Consider the grammar in Figure 1 (a) [5 marks] Give a parse tree for the following program fragment def fibn if less_than( n, 2 ) ) { return n } return add fib( sub( n, 1 ) ), fib( sub( n, 2 ) ) } (b) [5 marks] Is this grammar ambiguous? Give an intuitive justification (c) 10 marks] Prove that this grammar is not LL(1). Hint: You can do this by constructing the FIRST, FOLLOW, and PREDICT sets (d) 10 marks] Modify the grammar so that it is LL(1) ‘def’ id ‘ ParamList ‘Block MethodDecl -> ParamList ParamList Param ParamListTail ParamListTail -> ParamList Tail Param ParamList Tail Param id ‘Statements ‘ Block Statements € Statements Statement Statements Statement IfStatement Statement ReturnStatement ‘ir’ ”Eapression ‘Y Block Else IfStatement Else ‘else’ Block Else ‘else’ IfStatement ‘return’ Erpression integer Else ReturnStatement Expression id Expression -> id ‘ArgList ‘ Еарression ArgList ArgList Expression ArgistTail ArgListTail Arg ArgListTail ArgList Tail Arg Earpression



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *