nastygrammar

nastygrammar - The maximum line length is 80 characters....

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Nasty Grammar ----- ------- You have been asked to write a parser for the grammar E -> T E -> T < E T -> F T -> F * T F -> x F -> ( E ) F -> x < T > where in the second rule < is used as an operator and in the last rule < > are used as brackets. Note that the grammar is unambiguous (not obvious, but true). To keep things simple, the only terminals are x, *, (, ), <, and >. With this grammar the parse tree of x<x*x> is E | T | ___F___ / / \ \ x < | > | ___T___ / | \ F * T | | x F | x while the parse tree of x<x<x> is ___E___ / | \ T < E | | F T | | x ___F___ / / \ \ x < T > | F |
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 x and the parse tree of x<(x<x)> is E | T | ___F___ / / \ \ x < | > T | ___F___ / | \ ( | ) | ___E___ / | \ T < E | | F T | | x F | x Note ---- This grammar is a little nastier than JAVA in which `(t<x.y>)z' is a cast of z to the type `t<x.y>' where `x.y' is a parameter to the parameterized type `t'. ` Input ----- For each test case, an input string made of terminals on a line by itself. Only terminal characters will be on the line.
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The maximum line length is 80 characters. Input ends with an end of file. Output------For each test case, a single line. If the input string is an E, the line contains `accept' followed by the number of E, F, and T nodes in the parse tree, in the format indicated by the sample output. If the input Sheet1 Page 3 string is NOT an E, the line merely contains `reject'. Sample Input------ -----x*&lt;x&gt; x&lt;x*x&gt; x&lt;x&lt;x&gt; x&lt;(x&lt;x)&gt; x&lt;x&lt;x&gt;&gt;&lt;x&gt; Sample Output------ ------reject accept 1E 3T 3F accept 2E 3T 3F accept 3E 4T 4F reject r File: nastygrammar.txt Author: Bob Walton &lt;walton@deas.harvard.edu&gt; Date: Thu Oct 17 10:11:07 EDT 2002 The authors have placed this file in the public domain they make no warranty and accept no liability for this file. RCS Info (may not be true date or author): $Author: walton $ $Date: 2002/10/17 14:26:03 $ $RCSfile: nastygrammar.txt,v $ $Revision: 1.3 $...
View Full Document

This note was uploaded on 04/29/2011 for the course IT 201 taught by Professor K.v.arya during the Spring '11 term at IIT Kanpur.

Page1 / 3

nastygrammar - The maximum line length is 80 characters....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online