2. Below is the LL(1) parse table for a simple grammar for shell commands, con- sisting of a command name followed by (p
Posted: Sat May 14, 2022 3:46 pm
2. Below is the LL(1) parse table for a simple grammar for shell commands, con- sisting of a command name followed by (perhaps) some options and then some filenames. The start symbol is Shell. The terminals are com, opt, file. opt file $ com Shell com Args Args Opts Files Opts Files Opts Files Opts Files opt Opts file Files E € [10 marks] (a) Show how the LL(1) parsing algorithm executes on the input string com opt showing at each stage the operation performed, remaining input and stack state. Use the table format adopted in Lecture 23. (b) Explain what happens if we try to run the algorithm on the input com com How exactly does the algorithm detect the error? (c) One reason that LL(1) parsing may sometimes fail is that a predicted ter- minal does not match the symbol appearing next in the input. Could this ever happen for the grammar considered above? Justify your answer. (d) Consider now the following grammar (with start symbol S) for even-length palindromic strings over {a,b}: SelaSa bSb [5 marks] [4 marks Is this grammar ambiguous? Is it LL(1)? Briefly justify your answers. [6 marks]