2013-06-22

Programming Language Concept (5)

Book : Concept of Programming Language

Page 235
Review Questions

1.  What are the design issues for names?
The following are the primary design issues for names:
-          Are names case sensitive?
-          Are the special words of the language reserved words or keywords?

2. What is the potential danger of case-sensitive names?
To some people, the problems are about writability and readability. For readability, because names that look very similar in fact denote different entities. For writability, many of the predefined names including both uppercase and lowercase letters.

3. In what way are reserved words better than keywords?
As a language design choice, reserved words are better than keywords because the ability to redefine keywords can be confusing.

4. What is an alias?
Aliases are the variables when more than one variable name can be used to access the same memory location.

6.  State transition diagram is a directed graph. The nodes of a state diagram are labeled with state names. The arcs are labeled with the input characters that cause transitions among the states.

8. What are the two distinct goals of syntax analysis?
First, the syntax analyzer must check the input program to determine whether it is syntactically correct.
When an error is found, the analyzer must produce a diagnostic message and
recover. In this case, recovery means it must get back to a normal state and
continue its analysis of the input program. This step is required so that the
compiler finds as many errors as possible during a single analysis of the input
program. If it is not done well, error recovery may create more errors, or at
least more error messages. The second goal of syntax analysis is to produce a
complete parse tree, or at least trace the structure of the complete parse tree,
for syntactically correct input. The parse tree (or its trace) is used as the basis
for translation.

9.  The differences between top-down and bottom-up parsers:
-    Syntax analyzers are either top-down, meaning they construct left most derivations and a parse tree in top-down order, which mean the tree built from the root downward to the leaves.
-    Bottom-up meaning case they construct the reverse of a rightmost derivation and a parse tree in bottom-up order, which mean the parse tree is built from leaves upward to the root


18. What is left factoring?
This states that a <variable> is either an identifier or an identifier followed by
an expression in brackets (a subscript). These rules clearly do not pass the
pair-wise disjointness test, because both RHSs begin with the same terminal, identi-fier.

20. What is a simple phrases of a sentential form?
simple phrases is just a phrase that takes a single derivation step from its root nonterminal node.

21. What is the handle of a sentential form?
mathematically concise, it provides little help in finding the handle
of a given right sentential for

Page 236
Problem Set
2. What is l-value? Write a statement in C language which gives the compile time error “l-value required”.
The address of a variable is called its l-value.

4. Why is the type declaration of a variable necessary? What is the value range of the int type variable in Java?
because it must include an initial value, byte

5. approaches to building a lexical analyzer:
-    Write a formal description of the token patterns of the language using a descriptive language related to regular expressions. These descriptions are used as input to a software tool that automatically generates a lexical analyzer. There are many such tools available for this. The oldest of these, named lex, is commonly included as part of UNIX systems.
-    Design a state transition diagram that describes the token patterns of the language and write a program that implements the diagram.
-    Design a state transition diagram that describes the token patterns of the language and hand-construct a table-driven implementation of the state diagram.

6.  State transition diagram is a directed graph. The nodes of a state diagram are labeled with state names. The arcs are labeled with the input characters that cause transitions among the states.

8.a.Assuming static scooping, in the following, which declaration of x is the correct one for a reference to x?
b.Repeat part a, but assume dynamic scoping.
(a) i. Sub1
ii. Sub126
iii. Main
(b) i. Sub1
ii. Sub1
iii. Sub1

9.  The differences between top-down and bottom-up parsers:
-    Syntax analyzers are either top-down, meaning they construct left most derivations and a parse tree in top-down order, which mean the tree built from the root downward to the leaves.
–    Bottom-up meaning case they construct the reverse of a rightmost derivation and a parse tree in bottom-up order, which mean the parse tree is built from leaves upward to the root

Tidak ada komentar:

Posting Komentar