Docsity

CS 164, Spring 1993 Midterm 1: Problem Set, Exams of Programming Languages

Toggle sidebar
bg1
CS 164, Spring 1993
Midterm #1
Professor Rowe
Problem #1 (10 points; 1 point each)
Circle T or F to indicate the true or false statements.
T F The following grammar is ambiguous.
S-->SaS
S-->SbS
S-->c
T F It is possible to build a deterministic finite state automation for the
language { a* b* } with only two states.
T F We use a scanner to convert characters to tokens rather than having the
parser do the conversion because it simplifies the parser and leads to
smaller, more time efficient compilers.
T F A sentential form is a string of terminals and non-terminals that can be
derived from the distinguished start symbol.
T F In OO93, two routines can have the same name or identifier.
T F In constructing a compiler, it is a good idea to use a program, like flex
or lex, because it simplifies the coding of a scanner.
T F A shared library contains code that can be shared by several processes
running different programs.
T F Dynamically allocated space is placed in the heap.
T F All objects in OO93 contain a pointer to an object that represents the
class of the object.
T F A grammar is a representation for a possibly infinite set of sentences.
Problem #2 (15 points)
(a) (5 points) Define a right-most derivation.
(b) (5 points) A possible definition for a floating point BINARY number input
format is the following: an optional + or - sign followed by a string of zero
or more 0's or 1's followed by a decimal point followed by a string of one or
CS164 Spring 1993, MT1
CS 164, Spring 1993 Midterm #1 Professor Rowe 1
pf3
pf4

Partial preview of the text

Download CS 164, Spring 1993 Midterm 1: Problem Set and more Exams Programming Languages in PDF only on Docsity!

CS 164, Spring 1993

Midterm

Professor Rowe

Problem #1 (10 points; 1 point each)

Circle T or F to indicate the true or false statements.

T F The following grammar is ambiguous.

S-->SaS S-->SbS S-->c

T F It is possible to build a deterministic finite state automation for the language { a* b* } with only two states.

T F We use a scanner to convert characters to tokens rather than having the parser do the conversion because it simplifies the parser and leads to smaller, more time efficient compilers.

T F A sentential form is a string of terminals and non-terminals that can be derived from the distinguished start symbol.

T F In OO93, two routines can have the same name or identifier.

T F In constructing a compiler, it is a good idea to use a program, like flex or lex , because it simplifies the coding of a scanner.

T F A shared library contains code that can be shared by several processes running different programs.

T F Dynamically allocated space is placed in the heap.

T F All objects in OO93 contain a pointer to an object that represents the class of the object.

T F A grammar is a representation for a possibly infinite set of sentences.

Problem #2 (15 points)

(a) (5 points) Define a right-most derivation.

(b) (5 points) A possible definition for a floating point BINARY number input format is the following: an optional + or - sign followed by a string of zero or more 0's or 1's followed by a decimal point followed by a string of one or

more 0's or 1's.

Some valid numbers in this format are: +.1 10.01 -101.0.

Some invalid numbers are: 1. -

Show a finite state automation that will recognize BINARY floating point numbers.

(c) (5 poinst) Explain a reduce/reduce confilict and give an example grammar with one.

Problem #3 (25 points) Answer the questions below base on the following program fragment:

uses "stdobj.ooh" List: class object is &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp item: object; &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp next: List; &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp end ; Student: class object is &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp name: string; &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp login: string; end ; WorkStudy: class Student is &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp hours: int; end; BandMember: class Student is &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp instrument: string; end; Employee: class object is &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp name: string; &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp jobtitle: string; &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp hours: int; end;

(a) (5 points) What is the type of "new(BandMember)"?

(b) What is the type of "new(Employee.classof)"?

(c) (10 points) Suppose you wanted to write a generic procedure named "works" that returned true if the object passed was a work study student or an employee and otherwise it returned false. Write the methods required to implement this procedure. Note that the solution should be modular so that if we add a new category of student who works, we don't have to modify your existing definitions.

1&nbsp&nbsp 0 ) ) id ) id ( ( ( $ shift 3 2&nbsp&nbsp... 3&nbsp&nbsp... 4&nbsp&nbsp... 5&nbsp&nbsp... 6&nbsp&nbsp... 7&nbsp&nbsp... 8&nbsp&nbsp... 9&nbsp&nbsp... 10&nbsp&nbsp... 11&nbsp&nbsp... 12&nbsp&nbsp... 13&nbsp&nbsp... 14&nbsp&nbsp... 15&nbsp&nbsp... 16&nbsp&nbsp... 17&nbsp&nbsp... 18&nbsp&nbsp... 19&nbsp&nbsp... 20&nbsp&nbsp... 21&nbsp&nbsp... 22&nbsp&nbsp... 23&nbsp&nbsp... 24&nbsp&nbsp... 25&nbsp&nbsp...

Problem #5 (20 points) Given the following grammar, construct the finite state automation that represents the sets of collections of LR(0) items and the transitions between the sets.

S' --> S$ S --> A 'a' S --> A 'a' S A --> 'b' 'c' A --> 'b' A 'c'

Notice that the rule for S' has already been added to the grammar.