Exam1_KEY - ICS 313-03 Fundamentals of Programming...

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ICS 313-03 Fundamentals of Programming Languages Exam I (15%) (75 Minutes) Student ID: Name: Key Solution Question Max 1 16 2 20 3 24 4 20 5 20 Total Mark 100 19 October 2002 (021) Question 1 1.1 [8, 8] Match the following four areas of computer applications with their associated languages: Areas of computer applications Computer languages Scientific application C : System programming Business applications LISP : Artificial Intelligence applications Artificial Intelligence applications COBOL : Business applications System programming FORTRAN: Scientific application 1.2 Complete the given statements by the following: Artificial intelligent languages Business languages Scientific languages System programming languages a. Business languages are characterized by elaborate input and output facilities and decimal data types. b. System programming languages are characterized by the use of low-level features that allow the software interfaces to external devices to be written. c. Artificial intelligent languages are characterized by the absence of exact algorithms and the use of symbolic computation rather than numeric computation. d. Scientific languages are characterized by the use of simple data structures but requires large number of floating-point arithmetic computations. Question 2 [20] Complete the following statements: a. Readability is the ease with which programs can be read and understood. b. Maintenance was recognized as a major part of the software life cycle, particularly in terms of cost. c. Readability problem occur whenever the program’s author learned a different subset from that subset with which the reader is familiar. d. Abstraction means the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored. e. Orthogonality in a programming language means that a relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the language. f. Writability is a measure of how easily a language can be used to create programs for a chosen problem domain. g. Expressivity in a language means that a language has relatively convenient, rather than cumbersome, ways of specifying computations. h. Exception handling is the ability of a program to intercept run-time errors, take corrective measures, and continue to execute. i. Aliasing is having two distinct referencing methods, or names, for the same memory cell. j. A program is said to be reliable if it performs to its specifications under all conditions. Question 3 3.1 [14, 10] Using the following grammar , show a parse tree and a left most derivation and a parse tree for the following statement: A := B * ( A * ( B + C ) ) <assign> <id> <expr> <term> <factor> <id> := <expr> A|B|C <expr> + <term> | <term> <term> * <factor> | <factor> ( <expr> ) | <id> <assign> => => => => => => => => => => => => => => => => => => => => => => <id> A := A := A := A := A := A := A := A := A := A := A := A := A := A := A := A := A := A := A := A := A := := <expr> <expr> <term> <term> * <factor> <factor> * <factor> <id> * <factor> B * <factor> B * (<expr>) B * (<term>) B * (<term> * <factor>) B * (<factor> * <factor>) B * (<id> * <factor>) B * ( A * <factor>) B * ( A * (<expr>)) B * ( A * (<expr> + <term>)) B * ( A * (<term> + <term>)) B * ( A * (<factor> + <term>)) B * ( A * (<id> + <term>)) B * ( A * ( B + <term>)) B * ( A * ( B + <factor>)) B * ( A * ( B + <id>)) B * ( A * ( B + C )) 3.2 Modify the grammar to add a unary operator that has higher precedence than either + or * . Assume that the unary operators can precede any operand. Replace the rule <factor> → <id> with <factor> → + <id> | - <id> Question 4 4.1 [10, 10] Parsing is the process of tracing or constructing a parse tree for a given input string. The basic idea of recursive decent parser is that there is a subprogram for each nonterminal in the grammar. Describe the responsibility of the subprogram for a particular nonterminal when given an input string. It traces out the parse tree that can be rooted at that nonterminal and whose leaves match the input string. In fact, a recursive-descent parsing subprogram is a parser for the language that can be generated by its associated nonterminal. 4.2 Describe the difference between top-down and bottom-up parsers. A top-down parser traces or builds the parse tree beginning with the root. The derivation that is produced during a top-down parse is a leftmost derivation. A bottom-up parser constructs a parse tree by beginning at the leaves and progressing toward the root. A bottom-up parser produces the reverse of a rightmost derivation. Question 5 5.1 [5, 10, 5] Define binding and binding time. Binding is an association, such is between an attribute and an entity or between an operation and a symbol. The time at which a binding takes place is called binding time. 5.2 Name the four categories of scalar variables according to their lifetime. Describe one of them and state its advantages and disadvantages. Static Variables bound to memory cells before execution begins and remains bound to the same memory cell throughout execution. Advantages: efficiency (direct addressing), history-sensitive subprogram support Disadvantage: no recursion Stack-dynamic Variables Explicit Heap-dynamic Variables Implicit Heap-dynamic Variables 5.3 What is the general problem with static scoping? A programmer could mistakenly call a subprogram that should not have been callable, which would not be detected as an error by the complier. Too much data access. Encourages the use of more globals than are necessary. ...
View Full Document

This note was uploaded on 09/15/2010 for the course ICS ics103 taught by Professor Alvi during the Spring '07 term at King Fahd University of Petroleum & Minerals.

Ask a homework question - tutors are online