Written Assignment 3: LL and LR Parser Questions - Prof. Westley Weimer, Assignments of Programming Languages

A written assignment for a computer science course focusing on ll and lr parsers. Students are asked to convert given grammars into ll(1) form, left-factor a grammar, construct an ll parsing table, and analyze the behavior of an ll parser on an incorrect input. No identification information is required for submission.

Typology: Assignments

Pre 2010

Uploaded on 03/10/2009

koofers-user-ouw
koofers-user-ouw ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Written Assignment 3
This assignment asks you to prepare written answers to questions on LL
and LR parsers. Each of the questions has a short answer. You may discuss
this assignment with other students and work on the problems together.
However, your write-up should be your own individual work.
Please print your name and email address on your homework!
We need this information so that we can give you credit for the assignment
and so that we can return it to you.
1. Use left-factoring and/or elimination of left recursion to convert the
following grammars into LL(1) grammars. You may assume that these
grammars are unambiguous.
(a)
Eโ†’E+T|T|E!
Tโ†’int |(E)
(b)
Lโ†’X|L, X
Xโ†’int |string |(L)
(c)
Pโ†’P H 4U|p
Hโ†’h
Uโ†’u|u P
2. Consider the following grammar fragment for a familiar syntax:
1
pf3

Partial preview of the text

Download Written Assignment 3: LL and LR Parser Questions - Prof. Westley Weimer and more Assignments Programming Languages in PDF only on Docsity!

Written Assignment 3

This assignment asks you to prepare written answers to questions on LL and LR parsers. Each of the questions has a short answer. You may discuss this assignment with other students and work on the problems together. However, your write-up should be your own individual work.

Please print your name and email address on your homework! We need this information so that we can give you credit for the assignment and so that we can return it to you.

  1. Use left-factoring and/or elimination of left recursion to convert the following grammars into LL(1) grammars. You may assume that these grammars are unambiguous.

(a)

E โ†’ E + T | T | E! T โ†’ int | (E)

(b)

L โ†’ X | L, X X โ†’ int | string | (L)

(c)

P โ†’ P H 4 U | p H โ†’ h U โ†’ u | u P

  1. Consider the following grammar fragment for a familiar syntax:

U RL โ†’ P ROT O : / / HOST / F ILE

P ROT O โ†’ http P ROT O โ†’ f tp HOST โ†’ id I I โ†’  I โ†’. HOST F ILE โ†’ id G G โ†’  G โ†’. F ILE G โ†’ / F ILE

The nonterminals are U RL, P ROT O, HOST , I, F ILE and G.

(a) Left-factor this grammar. (b) Give the First and Follow sets for each nonterminal in the gram- mar obtained in part (a). (c) Using this information, construct an LL parsing table for the grammar obtained in part (a). (d) Suppose we generated an LL parser for the grammar using the table you constructed. What would go wrong if it tried to parse the following input string?

f tp : //id.id/id./id..id (That is, when we get an error, how much of the input string has been consumed, and what is the parser trying to do?)

  1. Consider the following LR(1) grammar:

S โ†’ A

A โ†’ A + A | B + + (Each โ€™+โ€™ is a separate token.) B โ†’ y