29 29 votes An identifier in a programming language consists of up to six letters and digits of which the first character must be a letter. Derive a regular expression for the identifier. Build an $LL(1)$ parsing table for the language defined by the $LL(1)$ grammar with productions $\text{Program} \rightarrow \text{ begin } d \text{ semi } X\text{ end}$ $X \rightarrow d \text{ semi } X \mid sY$ $Y \rightarrow \text{ semi } s Y \mid \epsilon$ Compiler Design gate1998 compiler-design parsing descriptive + – Kathleen 6.4k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 35 35 votes a. $(letter)(letter+digit+\epsilon)^5$ b. Program $\rightarrow$ begin d semi $X$ end $X \rightarrow d \ semi X$ $X \rightarrow sY$ $Y \rightarrow semi \ sY$ $Y \rightarrow \epsilon$ $$\begin{array}{|l|l|l|}\hline \textbf{Variable} & \textbf{First} & \textbf{Follow} \\\hline \text{Program} & \text{begin} & \text{\$} \\\hline \text{X} & \text{d, s} & \text{end} \\\hline \text{Y} & \text{semi, } \epsilon & \text{end}\\\hline \end{array}$$ Here, First$(Y)$ contains $\epsilon$ so we need to add $Y \rightarrow \epsilon$ to Follow$(Y)$ $$\begin{array}{|l|l|l|l|l|l|l|}\hline \textbf{Variable} & \textbf{begin} & \textbf{d} & \textbf{semi} & \textbf{s} & \text{end} & \textbf{\$} \\\hline \text{Program} & \text{A} & \text{} & \text{}& \text{}& \text{}& \text{}\\\hline \text{X} & \text{} & \text{B} & \text{} & \text{C} & \text{} & \text{} \\\hline \text{Y} & \text{}& \text{} & \text{D} & \text{} & \text{Y} \rightarrow \epsilon \\\hline \end{array}$$ papesh answered Dec 18, 2016 • edited Apr 17, 2019 by akash.dinkar12 papesh comment Share Follow See all 7 Comments 7 7 Comments reply Show 4 previous comments Mohnish commented Dec 9, 2020 reply Follow flag y->epsilon should also be under $ . please correct if wrong 1 1 replyShare kickassakash commented Dec 5, 2023 reply Follow flag @Mohnish If follow of y contained $ then you would’ve been right. but here follow of y contains only one terminal = end so what you are saying is wrong 0 0 replyShare shekhar12 commented Jan 19, 2025 reply Follow flag Shouldn't the follow be Follow(X) = {space} and Follow(Y) = {space} as there is blank space after X in production A 0 0 replyShare Please log in or register to add a comment.
8 8 votes a. $(letter)(letter + digit + epsilon)^5$ b. 1.program ---> begin d semi X end 2. X -----> d semi x 3. | sY 4. Y -----> semi sY 5. | epsilon begin d semi s end $ program 1 X 2 3 Y 4 5 Digvijay Pandey answered May 7, 2015 • edited Dec 2, 2017 by Manu Thakur Digvijay Pandey comment Share Follow See all 6 Comments 6 6 Comments reply Show 3 previous comments Angkit commented Jun 21, 2017 reply Follow flag How did you decide "semi" is variable or terminal? 0 0 replyShare shefali1 commented Jul 21, 2017 reply Follow flag terminals are given in small letters. 1 1 replyShare vishalshrm539 commented Dec 24, 2017 reply Follow flag if any symbol(semi in this case) is a non terminal, then we must have it at the LHS of a production.So semi is a terminal. 1 1 replyShare Please log in or register to add a comment.