1.3-3,14solution

1.3-3,14solution - <integer> <digit> |<digit><integer><digit> 0 | 1 | 2 | | 9<optional exponent> <exponent>

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS314 homework 3 solutions, January 31, 2008 Here are some suggested solutions to 1.3(3, 14). 3. Here’s a possible grammar, G = <N,T,<double>, P>. Of course, N and T are implied by the set of productions without your having to state them explicitly. I borrowed some notation from Alex Diehl’s good answer. Thanks! There are several ways of interpreting the problem. If by “Java double” you mean Java constants, then the following is a solution. If instead you mean Java literals, then omit the productions labeled (*). N = {<double>, <sign>, <number>,<integer>, <digit>, <optional exponent>, <exponent>, <D>, <E>, } T = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN, 0, 1, . .., 9, +, –, . , e, E, d, D} P = { <double> ÷ <sign><number><optonal_exponent> | <sign><integer><D> | <sign><integer><exponent> | (*) Double.POSITIVE_INFINITY | Double.NEGATIVE_INFINITY | Double.NaN <sign> ÷ + | – | 8 <number> ÷ <integer> . <integer> | . <integer>
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: <integer> ÷ <digit> | <digit> <integer> <digit> ÷ 0 | 1 | 2 | . .. | 9 <optional exponent> ÷ <exponent> | 8 <exponent> ÷ <E> <sign> <integer> <D> ÷ d | D | . <E> ÷ e | E Matt jokingly offered the following as well, which is the underlying bit pattern guaranteed by the Java documentation. <IEEEdouble> ÷ <bit><bit><bit><bit> . .. <bit> [there are 64 <bit>s here] <bit> ÷ 0|1 If I were writing the grammar of an IEEE double, Matt, I would instead tell you what that bit pattern represented in order from left to right, by using meaningful names as follows. <IEEE double> ÷ <sign> <exponent> <mantissa> <sign> ÷ <bit> <exponent> ÷ <bit> <bit> . .. <bit> [there are 11 <bit>s here] <mantissa> ÷ <bit> <bit> <bit> . .. <bit> [there are 52 <bit>s here] <bit> ÷ 0 | 1 14. The following Mealy machine by Doyle or by Das solves problem #14. Notice the convention of labeling the states meaningfully....
View Full Document

This homework help was uploaded on 04/19/2008 for the course COMP 314 taught by Professor Chase during the Spring '08 term at Dickinson.

Ask a homework question - tutors are online