4.- [11 points] Give the predictive parsing table for the following grammar: (Do not forget to...
Give the predictive parsing table for the following grammar: E -> T E’ (Do not forget to consider $) E’ -> + T E’ | e ( e stand for empty string) T -> F T’ T’ -> * F T’ | e F -> ( E ) | id | num
(Do not forget to consider $) (€ stand for empty string) E → TE E' →+TE' E T → FT T' → *FT' € F→ (E) id num 5.- ( 11 points) Armed with a predictive parsing table of question 4, it is easy to write a recursive- descent parser. Write, using pseudocode or C-syntax, the fragment of parser to parse l' and E'.
Question 1. (15 points) Consider the following LL (1) grammar with starting symbol S s→(ST) F → id F → num a) Compute the First and Follow sets of all non-terminals (5 points) b) Construct the LL (1) parsing table for the grammar (5 points) c) Show step-by-step (content of stack and input string, as well as the production taken) how the following string is parsed: ((20+30 + a)) (5 points)
7- Show a complete LR(0) and SLR(1) parsers, including the canonical collection of LR(0) and parsing table, using the following grammar E-→ E + T / T T-, T F / F l a l b Is this grammar LR(0) or SLR(1)? Why? 7- Show a complete LR(0) and SLR(1) parsers, including the canonical collection of LR(0) and parsing table, using the following grammar E-→ E + T / T T-, T F / F l a l b Is...
Q6) Consider the following grammar for arithmetic expressions. F ? (E) l i Using top-down parsing, find a leftmost derivation in this grammar for the expression i/i + . Show your work. 10 Points
Compute CLR-1 and LALR-1 Table of following grammar, Analyze the table and find, if there are any conflicts?? If YES, what type of conflicts are they?? Also parse following input along semantic rules by showing stack state while parsing. a id bi id * + [CLO-4, PLO-36] (10+4) S→SE+|Ef|F { print top of stack 2 times} E→EE*|F {if top of stack is E , print Good, else print Bad } F→aF|bi|id {print how many elements are there in stack}
(10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1 d A Ad IB A BA ASJAE Consider the following grammar G: S'S S (S)S|e fa) (10] Construct the collection of the sets of LR(0) items (b) [5] When constructing the action table of SLR parser of G what are the rules to determine the parsing actions? That is, what is the rule for a shift action at state /? What is the rule...
Consider the following grammar G: S'S SA xb AaAb B 3. do ed bisbon s LR Bx where S, A, and B are nonterminals, and a, b and x are terminals (a) [10] Is G SLR(1)? If yes, give the parsing table. Otherwise, explain why (b) [15] Is G LR(1)? If yes, give the parsing table. Otherwise, explain why. (c) [15] Is G LALR(1)? If yes, give the parsing table. Otherwise, explain why. umi Consider the following grammar G: S'S...
Name: 3. (10 points) Given grammar: <program> → <stmts> Page: 2 <term> → <var> 1 const 1), write down derivation of: c-5+a 2) What are terminals and what are non-terminals in the grammar? Show a complete parse, including the parse stack contents, input string, and action for the string: id - id + id, using the grammar and parse table below. (10 points) 4. Grammar State id S4 4. T F 5. F (E) R2 S7 R4 R4 R2İR2 Parse...
Consider the following context free grammar. Write an attribute grammar that specifies the calculation rules, i.e. how the value of E or T is calculated. There is no need to perform type checking. We assume all types are matched correctly. Please clearly specify the type of attribute(s) you introduce, i.e. synthesized, inherited, or intrinsic. E ::= E + T | T T ::= T * F | F F ::= NUM NUM ::= 1 | 2 | 3 | 4...