April 29, 2013

IRON MAN 3

IRON MAN 3




IRON MAN 3
MKV DONWLOAD HERE :
PART 1

ENJOY

download iron man 3 movie, iron man 3, iron man 3 watch, watch iron man 3 online, watch iron man 3, download iron man 3 free, watch iron man 3 movie online, iron man 3 download, iron man 3 watch online, iron man 3 movie download,watch iron man 3 movie free, download iron man 3, watch iron man 3 film, iron man 3 movie watch, watch iron man 3 film online, download iron man 3 free in hd, iron man 3 movie watch online, watch iron man 3 movie, iron man 3 movie download free

April 7, 2013

KBP chapter 7


Review Questions

Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono


1. Define operator precedence and operator associativity.

-The operator precedence rules for expression evaluation partially define
the order in which the operators of different precedence levels are evaluated.

-An operator can have either left or right associativity, meaning that when
there are two adjacent operators with the same precedence, the left operator is
evaluated first or the nright operator is evaluated first, respectively.

2. What is a ternary operator?

-ternary, meaning it has three operands.


3. What is a prefix operator?

-means they precede their operands.


8. Define functional side effect.

-A side effect of a function, naturally called a functional side effect, occurs
when the function changes either one of its parameters or a global variable. (A
global variable is declared outside the function but is accessible in the
function.)


10. What is a conditional expression?

-is a if-then-else that has more convinient form :

expression_1 ? expression_2 : expression_3
where expression_1 is interpreted as a Boolean expression.

If expression_1 evaluates to true, the value of the whole expression is the
value of expression_2;
otherwise, it is the value of expression_3.


13. In JavaScript, what is the difference between == and ===?

== is equality relational operator
=== is similiar to == but prevent their operands from being coerced.


14. What is a mixed-mode expression?

-language that allow expressions is whether an operator can have operands of
different types.

15. What is referential transparency?

-A program has the property of referential transparency if any two
expressions in the program that have the same value can be substituted for one
another anywhere in the program, without affecting the action of the program.

20. How does C support relational and Boolean expressions?
relational :
-for example, inequality, the C-based languages use !=

boolean :
-Highest postfix ++, --
unary +, -, prefix ++, --, !
*, /, %
binary +, -
<, >, <=, >=
=, !=
&&
Lowest ||

21. What is the purpose of a compound assignment operator?

-A compound assignment operator is a shorthand method of specifying a
commonly needed form of assignment. The form of assignment that can be
abbreviated with this technique has the destination variable also appearing as
the first operand in the expression on the right side.

28. What is a cast?

-In the C-based languages, explicit type conversions are called casts.



Problem Set

1. When might you want the compiler to ignore type differences in an
expression?

ANSWER :
-When it's overflow or underflow.


3. Do you think the elimination of overloaded operators in your favorite
language would be beneficial? Why or why not?

ANSWER:

-no.
overloaded operators can give more advantages, if it's eliminated, it will only
have one function.
the benefit in the following will be no more exist, which harden the coding
process.

For example, if + and * are overloaded for a matrix abstract data type and A,
B,
C, and D are variables of that type, then

A * B + C * D

can be used instead of

MatrixAdd(MatrixMult(A, B), MatrixMult(C, D))



9. Assume the following rules of associativity and precedence for
expressions:

Precedence Highest *, /, not
+, –, &, mod
– (unary)
=, /=, < , <=, >=, >
and
Lowest or, xor
Associativity Left to right

Show the order of evaluation of the following expressions by parenthesizing
all subexpressions and placing a superscript on the right parenthesis
to indicate order. For example, for the expression

a + b * c + d

the order of evaluation would be represented as

((a + (b * c)1)2 + d)3

a. a * b - 1 + c
b. a * (b - 1) / c mod d
c. (a - b) / c & (d * e / a - 3)
d. -a or c = d and e
e. a > b xor c or d <= 17
f. -a + b

ANSWER :

a. (((a * b)1 - 1)2 + c)3
b. ( (a * (b - 1)1)3 / (c mod d)2 )4
c. ( ((a - b)1 / c)2 & ((d * e)3 / (a – 3)4)5 )6
d. ((-a)1 or ((c = d)2 and e)3 )4
e. ((a > b)1 xor (c or (d <= 17)2)3)4
f. ((-a)1 + b)2


21. Why does Java specify that operands in expressions are all evaluated in
left-to-right order?

ANSWER: 
-because left-to-right order is a common used.

22. Explain how the coercion rules of a language affect its error detection
ANSWER:

-As a simple illustration of the problem, consider the following Java code:

int a;
float b, c, d;
. . .
d = b * a;

Assume that the second operand of the multiplication operator was supposed
to be c, but because of a keying error it was typed as a. Because mixed-mode
expressions are legal in Java, the compiler would not detect this as an error.
It would simply insert code to coerce the value of the int operand, a, to
float. If mixed-mode expressions were not legal in Java, this keying error
would have been detected by the compiler as a type error.

KBP chapter 6


Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono


Review Questions


1. What is a descriptor?

-A descriptor is the collection of the attributes of a variable. In
an implementation, a descriptor is an area of memory that stores the attributes
of a variable.


2. What are the advantages and disadvantages of decimal data types?

-Decimal types have the advantage of being able to precisely store decimal
values, at least those within a restricted range, which cannot be done
with floating-point. For example, the number 0.1 (in decimal) can be exactly
represented in a decimal type, but not in a floating-point type,

-The disadvantages of decimal types are that the range of values
is restricted because no exponents are allowed, and their representation in
memory is mildly wasteful.
Decimal types are stored very much like character strings, using binary
codes for the decimal digits. These representations are called binary coded
decimal (BCD). In some cases, they are stored one digit per byte, but in

others, they are packed two digits per byte. Either way, they take more storage

than binary representations. It takes at least four bits to code a decimal

digit. Therefore, to store a six-digit coded decimal number requires 24 bits of

memory. However, it takes only 20 bits to store the same number in binary.



3. What are the design issues for character string types?

-The two most important design issues that are specific to character string

types
are the following:
• Should strings be simply a special kind of character array or a primitive

type?
• Should strings have static or dynamic length?



4. Describe the three string length options.

-First,the length can be static and set when the string is created. Such a

string is called a static length string.

-The second option is to allow strings to have varying length up to a
declared and fixed maximum set by the variable’s definition, as exemplified
by the strings in C and the C-style strings of C++.

-The third option is to allow strings to have varying length with no maximum,
as in JavaScript, Perl, and the standard C++ library. These are called
dynamic length strings. This option requires the overhead of dynamic storage
allocation and deallocation but provides maximum flexibility.



5. Define ordinal, enumeration, and subrange types.

-An ordinal type is one in which the range of possible values can be easily
associated with the set of positive integers. In Java, for example, the

primitive ordinal types are integer, char, and boolean.
There are two user-defined
ordinal types that have been supported by programming languages: enumeration
and subrange.

-An enumeration type is one in which all of the possible values, which are
named constants, are provided, or enumerated, in the definition. Enumeration
types provide a way of defining and grouping collections of named constants,
which are called enumeration constants.

-A subrange type is a contiguous subsequence of an ordinal type. For example,
12..14 is a subrange of integer type.



6. What are the advantages of user-defined enumeration types?

-Readability is enhanced very directly: Named values are easily recognized,
whereas coded values are not.
In the area of reliability, the enumeration types of Ada, C#, F#, and Java
5.0 provide two advantages: (1) No arithmetic operations are legal on

enumeration types; this prevents adding days of the week, for example, and
(2) second, no enumeration variable can be assigned a value outside its defined

range.4 If the colors enumeration type has 10 enumeration constants and uses

0..9 as its internal values, no number greater than 9 can be assigned to a

colors type variable.


12. What languages support negative subscripts?

-Ruby and Lua.


15. What is an aggregate constant?

-consider the following:
List : array (1..5) of Integer := (1, 3, 5, 7, 9);
Bunch : array (1..5) of Integer := (1 => 17, 3 => 34,
others => 0);
In the first statement, all the elements of the array List have initializing

values, which are assigned to the array element locations in the order in which

they appear. In the second, the first and third array elements are initialized

using direct assignment, and the others clause is used to initialize the

remaining elements. As with Fortran, these parenthesized lists of values are

called aggregate values.

17. Define row major order and column major order.

-In row major order, the
elements of the array that have as their first subscript the lower bound value

of that subscript are stored first, followed by the elements of the second

value of the first subscript, and so forth. If the array is a matrix, it is

stored by rows.
For example, if the matrix had the values

3 4 7
6 2 5
1 3 8

it would be stored in row major order as
3, 4, 7, 6, 2, 5, 1, 3, 8

-In column major order, the elements of an array that have as their last

subscript the lower bound value of that subscript are stored first, followed by

the elements of the second value of the last subscript, and so forth. If the

array is a matrix, it is stored by columns.
If the example matrix were stored in column major order, it would have the

following order in memory:
3, 6, 1, 4, 2, 3, 7, 5, 8

21. What is the purpose of level numbers in COBOL records?

-indicate by their relative values the hierarchical structure of the record.

Any line that is followed by a line with a higher-level number is itself a

record.


23. What is the primary difference between a record and a tuple?

-Tuples are similar to records, but do not have names for their constituent
parts.


24. Are the tuples of Python mutable?

-Python’s tuples are closely related to its lists, except that tuples are
immutable. A tuple is created by assigning a tuple literal, as in the following
example:

myTuple = (3, 5.8, 'apple')

Notice that the elements of a tuple need not be of the same type.
The elements of a tuple can be referenced with indexing in brackets, as in
the following:

myTuple[1]

This references the first element of the tuple, because tuple indexing begins

at 1.


26. In what primarily imperative language do lists serve as arrays?

-Python.


31. Define union, free union, and discriminated union.

-A union
is a type whose variables may store different type values at different
times during program execution.

-free unions
are unions that allowed complete freedom from type checking in their use.

-Type checking of unions requires that each union construct include a type
indicator. Such indicator is called tag or discriminant, and a union with
a discriminant is called a discriminated union.


36. What are the two common problems with pointers?

-Pointers have some inherent dangers: Dangling pointers are difficult
to avoid, and memory leakage can occur.



44. Define type error.

-A type error is the application of an operator to an operand of an

inappropriate type.
For example, in the original version of C, if an int value was passed to a

function that expected a float value, a type error would occur
(because compilers for that language did not check the types of parameters).


45. Define strongly typed.

-A programming language is strongly typed if type errors are always
detected.

46. Why is Java not strongly typed?

-expressions are strongly typed in Java.
However,
an arithmetic operator with one floating-point operand and one integer operand
is legal. The value of the integer operand is coerced to floating-point, and
a floating-point operation takes place. This is what is usually intended by the
programmer. However, the coercion also results in a loss of one of the benefits
of strong typing—error detection.


50. What is name type equivalence?

-Type equivalence is a strict form
of type compatibility—compatibility without coercion.


51. What is structure type equivalence?

-Structure type equivalence
means that two variables have equivalent types if their types have identical
structures.

PROBLEM SET

1. What are the arguments for and against representing Boolean values as
single bits in memory?

ANSWER : 

A Boolean value could be represented by a single bit, but because a single
bit of memory cannot be accessed efficiently on many machines, they are often
stored in the smallest efficiently addressable cell of memory, typically a

byte.



2. How does a decimal value waste memory space?

ANSWER :

-Their representation in memory is mildly wasteful, for reasons discussed in

the following paragraph.
-Decimal types are stored very much like character strings, using binary
codes for the decimal digits. These representations are called binary coded
decimal (BCD). In some cases, they are stored one digit per byte, but in

others,
they are packed two digits per byte. Either way, they take more storage than
binary representations. It takes at least four bits to code a decimal digit.

Therefore,
to store a six-digit coded decimal number requires 24 bits of memory.
However, it takes only 20 bits to store the same number in binary.



7. What significant justification is there for the -> operator in C and C++?

ANSWER :

-In C and C++, there are two ways a pointer to a record can be used to

reference a field in that record. If a pointer variable p points to a record

with a field named age, (*p).age can be used to refer to that field. The

operator ->, when used between a pointer to a record and a field of that

record, comfbines dereferencing and field reference. For example, the

expression p -> age is equivalent to (*p).age. In Ada, p.age
can be used, because such uses of pointers are implicitly dereferenced.


9. The unions in C and C++ are separate from the records of those languages,
rather than combined as they are in Ada. What are the advantages
and disadvantages to these two choices?

ANSWER : 

-Ada :

Advantage:
Unconstrained variant records in Ada allow the values of their variants to

change types during execution.

disadvantage:
However, the type of the variant can be changed only by
assigning the entire record, including the discriminant. This disallows

inconsistent records because if the newly assigned record is a constant data

aggregate, the value of the tag and the type of the variant can be statically

checked for consistency.

13. Analyze and write a comparison of using C++ pointers and Java reference
variables to refer to fixed heap-dynamic variables. Use safety and convenience
as the primary considerations in the comparison.

ANSWER:

-In c and C++ pointer can be use the same way as addresses. This design offer

no solutions to the dangling pointer or lost heap-dynamic variable problems.

-Reference types, such as those in Java and C#, provide heap management
without the dangers of pointers.

so its clear that Java has more safety for the heap-dynamic variables.


21. In what way is static type checking better than dynamic type checking?

ANSWER :
It allows many type errors to be caught early in the development cycle. Static

type checkers evaluate only the type information that can be determined at

compile time, but are able to verify that the checked conditions hold for all

possible executions of the program, which eliminates the need to repeat type

checks every time the program is executed

KBP chapter 5


Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono

Review questions

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.
These statements declare the program variable Real to be of Integer type
and the variable Integer to be of Real type.3 In addition to the strange
appearance of these declaration statements, the appearance of Real and Integer
as variable names elsewhere in the program could be misleading to program
readers.


4. What is an alias?

-When more than one variable name can be used to access the same memory location, the variables are called aliases.


5. Which category of C++ reference variables is always aliases?

-Two pointer variables are aliases when they point to the same memory
location. The same is true for reference variables. This kind of aliasing is simply
a side effect of the nature of pointers and references. When a C++ pointer is set
to point at a named variable, the pointer, when dereferenced, and the variable’s
name are aliases.


6. What is the l-value of a variable? What is the r-value?

-A variable’s value is sometimes called its r-value
-To access the r-value, the l-value must be determined first.

9. Define static binding and dynamic binding.

-An explicit declaration is a statement in a program that lists variable names
and specifies that they are a particular type. An implicit declaration is a means
of associating variables with types through default conventions, rather than
declaration statements. In this case, the first appearance of a variable name in a
program constitutes its implicit declaration. Both explicit and implicit declarations
create static bindings to types.

-With dynamic type binding, the type of a variable is not specified by a declaration
statement, nor can it be determined by the spelling of its name. Instead,
the variable is bound to a type when it is assigned a value in an assignment statement.


13. Define lifetime, scope, static scope, and dynamic scope.

-The lifetime of a variable is the time during which the variable is bound
to a specific memory location.

-The scope of a variable is the range of statements in which the variable is visible. A variable
is visible in a statement if it can be referenced in that statement.

-the method of binding names to nonlocal variables called static scoping.

-Dynamic scoping is based on the calling sequence of subprograms, not
on their spatial relationship to each other. Thus, the scope can be determined
only at run time.


15. What is the general problem with static scoping?

-First, in most cases it allows
more access to both variables and subprograms than is necessary. It is simply
too crude a tool for concisely specifying such restrictions. Second, and perhaps
more important, is a problem related to program evolution. Software is highly
dynamic—programs that are used regularly continually change. These changes
often result in restructuring, thereby destroying the initial structure that
restricted variable and subprogram access.
-Designers are encouraged to use far more globals than are necessary.


18. What is a block?

-allows a section of code to have its own local variables whose scope is minimized. Such variables
are typically stack dynamic, so their storage is allocated when the section
is entered and deallocated when the section is exited. Such a section of code
is called a block.


19. What is the purpose of the let constructs in functional languages?

-These constructs have two parts:
-The first of which is to bind names to values, usually specified as
expressions.
-The second part is an expression that uses the names defined in the
first part. Programs in functional languages are comprised of expressions, rather
than statements. Therefore, the final part of a let construct is an expression, rather than a statement.


23. What are the advantages of named constants?

-named constants are useful to increase readbility of program
for example, by using name pi instead of the constant 3.14159265

Problem Sets

1. Which of the following identifier forms is most readable? Support your decision.
SumOfSales
sum_of_sales
SUMOFSALES

answers :
sum_of_sales
seperated by underscore will give more space, also seperate each wort, so it will be more readable than those are not seperated.


2.Some programming languages are typeless. What are the obvious advantages
and disadvantages of having no types in a language?

answers :
-advantages : the programmer allowed to code programs quickly without worrying about data types
-disadvantages : it is slow for parser that has to keep track on whats on the variable.


5. Describe a situation when a history-sensitive variable in a subprogram is
useful.

answer :
-Globally accessible variables are often used throughout the execution
of a program, thus making it necessary to have them bound to the same
storage during that execution. Sometimes it is convenient to have subprograms
that are history sensitive.


10. Consider the following C program:

void fun(void) {
int a, b, c; /* definition 1 */
. . .
while (. . .) {
int b, c, d; /*definition 2 */
. . . <-------- 1
while (. . .) {
int c, d, e; /* definition 3 */
. . . <-------2
}
. . . <-------3
}
. . . <-------4
}
For each of the four marked points in this function, list each visible variable,
along with the number of the definition statement that defines it.

answers :
1 : a,b,c <definition 1> ; b,c,d <definiton 2>
2 : a,b,c <definition 1> ; b,c,d <definiton 2> ; c,d,e <definition 3>
3 : a,b,c <definition 1> ; b,c,d <definiton 2>
4 : a,b,c <definition 1>

KBP chapter 4

Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono

Review questions


2.Explain the three reasons why lexical analysis is separated from syntax analysis.

1. Simplicity—Techniques for lexical analysis are less complex than those
required for syntax analysis, so the lexical-analysis process can be simpler
if it is separate. Also, removing the low-level details of lexical analysis
from the syntax analyzer makes the syntax analyzer both smaller and
less complex.
2. Efficiency—Although it pays to optimize the lexical analyzer, because
lexical analysis requires a significant portion of total compilation time,
it is not fruitful to optimize the syntax analyzer. Separation facilitates
this selective optimization.
3. Portability—Because the lexical analyzer reads input program files
and often includes buffering of that input, it is somewhat platform
dependent. However, the syntax analyzer can be platform independent.
It is always good to isolate machine-dependent parts of any software
system.


3.define lexeme and token.

-Formal descriptions of the syntax of programming languages, for simplicity’s
sake, often do not include descriptions of the lowest-level syntactic
units. These small units are called lexemes.

-token of a language is a category of its lexemes. For example, an identifier is a token
that can have lexemes, or instances, such as sum and total. In some cases, a
token has only a single possible lexeme. Each lexeme group is represented by a name, or token.

Consider the following
Java statement:

index = 2 * count + 17;
The lexemes and tokens of this statement are
Lexemes Tokens
index identifier
= equal_sign
2 int_literal
* mult_op
count identifier
+ plus_op
17 int_literal
; semicolon


4. what are the primary task of a lexical analyzer?

-A lexical analyzer is essentially a pattern matcher. A pattern matcher attempts to
find a substring of a given string of characters that matches a given character pattern.
Pattern matching is a traditional part of computing.


6.What is a state transition diagram?

-A state transition diagram, or just state 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 the transitions among the states. An arc may also
include actions the lexical analyzer must perform when the transition is taken.


7.Why are character classes used, rather than individual characters, for the letter and digit transitions of a state diagram for a lexical analyzer?

-Suppose we need a lexical analyzer that recognizes only arithmetic expressions,
including variable names and integer literals as operands. Assume that
the variable names consist of strings of uppercase letters, lowercase letters, and digits but must begin with a letter. Names have no length limitation. The first
thing to observe is that there are 52 different characters (any uppercase or lowercase letter) that can begin a name, which would require 52 transitions from the transition diagram’s initial state. However, a lexical analyzer is interested only in determining that it is a name and is not concerned with which specific
name it happens to be. Therefore, we define a character class named LETTER
for all 52 letters and use a single transition on the first letter of any name.


13.Why are named constants used, rather than numbers, for token codes?

-for the sake of readability of lexical and syntax analyzers.


14.Describe how a recursive-descent parsing subprogram is written for a rule with a single RHS.

-A recursive-descent subprogram for a rule with a single RHS is relatively
simple. For each terminal symbol in the RHS, that terminal symbol is compared
with nextToken. If they do not match, it is a syntax error. If they match,
the lexical analyzer is called to get the next input token. For each nonterminal, the parsing subprogram for that nonterminal is called.


15.What is the FIRST set for a given grammar and sentential form?

FIRST( ) = {a => * a } (If => * , is in FIRST( ))
in which =>* means 0 or more derivation steps.



18.What is left factoring?

-Left factoring is the action taken when a grammar leads backtracking while making parsing/syntax tree

Let us have a grammar:-
A->bcW | bcE
W->x
E->q

Now lets have a look on the production A->bcW | bcE, here 'bc' is repeating.
If we want to parse a string "bcq", then firstly we have two choices - either choose A->bcW or A->bcE. Since both have the same probability, we choose A->bcW. Then when we are finished with "bc" and turn to parse "_ _ q". After this, we have to backtrack because this production is in "A->bcE".

This shows the problem with such type of problem. Now to overcome this problem we have a concept of Left factoring.
In this we take common symbols in a new non terminal. Lets have a look on how we can do it.
Above grammar after applying left factoring is

A->bcX
X->W | E
W->x
E->q


http://en.wikipedia.org/wiki/Left_factoring


Problem Set

(1)1. Perform the pairwise disjointness test for the following grammar rules.
a. A → aB | b | cBB
b. B → aB | bA | aBb
c. C→ aaA | b | caB

answer :
A -> aB | b | CBB

first(aB) = a

first(b) = b

first(CBB) = aaA = a


B -> aB | ba | aBb

first(aB) = a

first(ba) = b

first(aBb) = a

They are intersected & thus the rule fails the test.


C -> aaA | b | caB

first(aaA) = a

first(b) = b

first(caB) = c

are not intersected & thus the rule passes


(2)2. Perform the pairwise disjointness test for the following grammar rules.
a. S→ aSb | bAA
b. A → b{aB} | a
c. B → aB | a

answer : 
 S→ aSb | bAA

first(aSb) = a

first(bAA) = b

are not intersected, the rule passes

A → b{aB} | a

first(b{aB}) = b

first(a) = a

are not intersected, the rule passes

B → aB | a

first(aB) = a

first(a) = a

They are intersected the rule fails the test.



(3)3. Show a trace of the recursive descent parser given in Section 4.4.1 for
the string a + b * c.

Consider the following EBNF description of simple arithmetic expressions:
<expr> → <term> {(+ | -) <term>}
<term> → <factor> {(* | /) <factor>}
<factor> → id | int_constant | ( <expr> )

answer :

Next token is: 10 Next lexeme is a
Enter <expr>
Enter <term>
Enter <factor>

Next token is: 21 Next lexeme is +
Exit <factor>
Exit <term>

Next token is: 10 Next lexeme is b
Enter <term>
Enter <factor>

Next token is: 10 Next lexeme is *
Exit <factor>

Next token is: 26 Next lexeme is c
Enter<factor>

Next token is: -1 Next lexeme is EOF
Exit <term>
Exit <expr>


4. Show a trace of the recursive descent parser given in Section 4.4.1 for
the string a * (b + c).

answer: 

Next token is: 10 Next lexeme is a
Enter <expr>
Enter <term>
Enter <factor>

Next token is: 21 Next lexeme is *
Exit <factor>

Next token is: 25 Next lexeme is (
Enter <factor>

Next token is: 10 Next lexeme is b
Enter <expr>
Enter <term>
Enter <factor>

Next token is: 21 Next lexeme is +
Exit <factor>

Next token is: 26 Next lexeme is c
Enter <factor>

Next token is: 26 Next lexeme is )
Exit <term>
Exit <expr>

Next token is: -1 Next lexeme is EOF
Exit <factor>
Exit <term>
Exit <expr>

March 26, 2013

KBP chapter 3


Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono

Review questions

1.Define syntax and semantics.
-Syntax is the form of its expresions, statements, and program units.
Semantics is the meaning of those expressions, statements and program units.


2.Who are language descriptions for?
-Language user's



3.Describe the operation of a general language generator.
-A language generator is a device that can be used to generate the sentences of
a language. We can think of the generator as having a button that produces a
sentence of the language every time it is pushed.



4.Describe the operation of a general language recognizer.
-The syntax analysis part of a compiler is a recognizer for the language the
compiler translates. In this role, the recognizer need not test all possible
strings of characters from some set to determine whether each is in the
language. Rather, it need only determine whether given programs are in the
language. In effect then, the syntax analyzer determines whether the given
programs are syntactically
correct.



5.What is the difference between a sentence and a sentential form?
-sentence is the string of a language
-Sentential form is string in the derivation of a program, including the
<program> itself.



7.What three extensions are common to most EBNFs?
-The first of these denotes an optional part of an RHS, which is delimited by brackets.
-The second extension is the use of braces in an RHS to indicate that the enclosed part can be repeated indefinitely or left out altogether. This extension allows lists to be built with a single rule, instead of using recursion and two rules.

-The third common extension deals with multiple-choice options. When a
single element must be chosen from a group, the options are placed in parentheses
and separated by the OR operator, |


10. what is the diffrence between a synthesized and an inherited attribute?
-Synthesized attributes are used to pass semantic information up a parse tree,
while
-Inherited attributes pass semantic information down and across a tree.



12. what is the primary use of attribute grammars?
-Attribute grammars are context-free grammars to which have been added attributes,
attribute computation functions, and predicate functions. Attributes,
which are associated with grammar symbols (the terminal and nonterminal
symbols), are similar to variables in the sense that they can have values assigned
to them.


15.Describe the two levels of a methodology and notation for describing the

semantics of programming languages.
-There are different levels of uses of operational semantics. At the highest
level, the interest is in the final result of the execution of a complete program.
This is sometimes called natural operational semantics.

-At the lowest level,
operational semantics can be used to determine the precise meaning of a program
through an examination of the complete sequence of state changes that
occur when the program is executed. This use is sometimes called structural
operational semantics.



18. which semantics approach is most widely known?
Denotational semantics is the most rigorous and most widely known formal
method for describing the meaning of programs. It is solidly based on recursive
function theory.


21. when is a grammar rule said to be left recursive?
When a grammar rule has its LHS also appearing at the beginning of its
RHS, the rule is said to be left recursive. This left recursion specifies left
associativity.


22.Give an example of an ambiguous grammar.

if done == true
then if denom == 0
then quotient = 0;
else quotient = num / denom;

it's ambiguous which the "else" is not determined for first if or the second
else.



Problem SET

(1)The two mathematical models of language description are generation
and recognition. Describe how each can define the syntax of a programming
language.
answer :
-Suppose we have a language L that uses an alphabet of characters. To define L formally using the recognition method, we would need to construct a mechanism R, called a recognition device, capable of reading strings of characters from the alphabet . R would indicate whether a given input string was or was not in L. In effect, R would either accept or reject the given string. Such devices are like filters, separating legal sentences from those that are incorrectly formed. If R, when fed any string of characters over , accepts it only if it is in L, then R is a description of L.

-generator is a device that can be used to generate the sentences of
a language. We can think of the generator as having a button that produces a
sentence of the language every time it is pushed.


(2)3. Rewrite the BNF of Example 3.4 to give + precedence over * and force +
to be right associative.
answer :
<assign> → => A = (B + C) ** A

(3)4. Rewrite the BNF of Example 3.4 to add the ++ and -- unary operators
of Java.
answer : 
<assign> => A = B ++ C * A

(4)11. Consider the following grammar:
<S> → <A> a <B> b
<A> → <A> b | b
<B> → a <B> | a
Which of the following sentences are in the language generated by this
grammar?

answer : NONE of them

a) bbaabb
impossible to have 2 "b"s at the end of <S>

b) bbaba
impossible to have "a" at the end since <S> has always ends with "b"

c) bbaaaabb
impossible to have 2 "b"s at the end of <S>

d) abaabb
impossible to have "a" at the start of <S>



(5)12. Consider the following grammar:
<S> → a <S> c <B> | <A> | b
<A> → c <A> | c
<B> → d | <A>
Which of the following sentences are in the language generated by this
grammar?

answers :NONE OF THEM

rules from analysis :
1.the end of a statement will always either "b", "c", "d"
2.Since "b" obtained from <S> , impossible if "c" is after the "b".
3.<B> is the last part of <S>, so the "d" will always be the last and

impossible to have others following.
4.since "b" is called by <S>, take a look at the <S> is only one which can only

produce 1 "b" in a statement.

a) abbccd
impossible breaking rule 4

b) acccbda
impossible, breaking rule 1

c) accbcbccc
impossible, breaking rule 2

d) acddaccd
impossible, breaking rule 3

e) acccdc
impossible, breaking rule 3




(6)17. Convert the following EBNF to BNF:
S -> A{bA}
A -> a[b]A

answer:
<S> -> <A> | <S> b <A>
<A> -> a



(7)15. Convert the BNF of Example 3.1 to EBNF.

<program> → begin <stmt_list> end

<stmt_list> → <stmt>
| <stmt> ; <stmt_list>
<stmt> → <var> = <expression>
<var> → A | B | C
<expression> → <var> + <var>
| <var> – <var>
| <var>

answer : 

Program -> begin <stmt_list> end
<stmt_list -> <stmt> {; <stmt>)
stmt -> var = expression
var -> A | B | C
<exppression> -> <var> {(+|-) <var>}



(8)16. Convert the BNF of Example 3.3 to EBNF.
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> + <expr>
| <expr> * <expr>
| ( <expr> )
| <id>

answer :
<assign> -> <id> = <expr>
<id> -> A | B | C
<expr> -> <expr> { (+|*) <expr>}
| (<expr>)
| <id>

(9)18. What is the difference between an intrinsic attribute and a nonintrinsic
synthesized attribute?
answer:
-Intrinsic attributes are synthesized attributes of leaf nodes whose values are determined outside the parse tree.
nonintrinsic means the opposite, the values are not determined.


(10)28. Prove the following program is correct:
{n > 0}
count = n;
sum = 0;
while count <> 0 do
sum = sum + count;
count = count - 1;
end
{sum = 1 + 2 + . . . + n}

answer : 

assume input is 4
{n > 0}
count = n;
sum = 0;
while count <> 0 do

first round (count = 4)
sum = sum + count;
//sum = 4
count = count - 1;
//count = 4-1 = 3

second round (count = 3)
sum = sum + count;
//sum = 4 + 3
count = count - 1;
//count = 3-1 = 2

third round (count = 2)
sum = sum + count;
//sum = 4+3+2
count = count - 1;
//count = 2-1 = 1

first round (count = 1)
sum = sum + count;
//sum = 4+3+2+1 (prove the answer)
count = count - 1;
//count = 1-1 = 0

end
{sum = 1 + 2 + . . . + n}

March 11, 2013

KBP Chapter 2


Rickvian Aldi / 01PBT / 1601253441
Assignment By Mr. Tri Djoko Wahjono

Review Questions

1. In what year was Plankalkul designed? In what year was that design published?
-Designed 1945, published at 1972

2. Mention an interesting feature of Zuse's programs.
-The inclusion of mathematical expressions showing the current relationships between program variables. These expression stated what would be true during execution at the points in the code where they appreared.

3.What does plankakul mean?
-Plankalkul means program calculus.

4.Speedcoding was invented to overcome two significant shortcomings of the computer hardware of early 1950s. What were they?
-The system included prseudoinstructions for the four arithmetic operations on floating-point data, as well as operations such as square root, sine arc tanget exponent. On the other hand, Speedcoding included the novel facility of automatically incrementing address registers.

5.What is the number of bits in a single word of the UNIVAC  I's memory? How are the bits grouped?
-The words of the UNIVAC I's memory had 72 bits, grouped as 12 six-bit bytes.

6.What hardware capability that first appeared in the IBM 704 computer strongly affected the evolution of programming languages? Explain why.
-Because of its capabilities prompted the development of FORTRAN.
With both indexing and floating-point instructions in hardware, heralded the end of the interpretive era, at least for scientific computation.

7.Who developed the speedcoding system for the IBM 701?
-John Backus 1954

8.Who developed Short Code? Why Short Code called automatic programming?
-Developed by John Mauchly in 1949.
-Short code was not translated to machine code; rather, it was implemented with a pure interpreter.

9.Under what enviromental consideration was Fortran developed? Which is the first version of the Fortran?
-The environment in which Fortran was developed was as follows:
-Computers had small memories and were slow and relatively unreliable
-The primary use of computers was for scientific computations
-There were no existing efficient and effective ways to program computers
-Because of the high cost of computers compared to the cost of programmers, speed of the generated object code was the primary goal of the first FORTRAN compilers.
The first version of FORTRAN is fortran 0.

10.What was the most significant feature added to fortran I to get Fotran II?
-The most important being the independent compilation of subroutines. Without independent compilation, any change in a program required that the entire program be recompled.

11.What control flow statements were added to Fortran IV to get Fortran 77?
-Fortran 77 retained most of the features if Fortran IV and added character string handling, logical loop control statements, and an if with an optional else clause.

12.Which version of Fortran was the first to have any sort of dynamic variables?
-Fortran 90.

13.Which version of Fortran was the first to have character string handling?
-Fortran 77.

14.Why were linguist interested in artificial intelligence in the late 1950s?
-Linguists were concerned with natural language processing.

15.What are the different data types and structures in Common LISP?
-records, arrays, complex number, character strings, many more.

16.In what way are Scheme and Common LISP opposites of each other?
-Scheme is small language with simple sytax and semantics.
-Common LISP is relatively large and complex language.

17.What dialect of LISP is used for introductory programming courses at some universities?
-Scheme is well suited to educational applications, such as courses in functional programming and general introductions to programming.

Problem set

1. What features of Fotran IV do you think would have had the greatest influence on Java if the Java designers had been familiar with Fotran?
-Amon its most important additions were explicit type declaration for variables, a logical if construct and capability of passing subprograms as paramaters to others subprograms.

3.Write a short history of the Fotran 0, Fotran I, Fotran II, and Fotran IV systems.
-Fotran 0:
Even before the 704 sysetem was announced, plans were begun for Fortran. John Backus and his group at IBM had produced the report titled "The IBM Mathematical FORmula TRANsalating System: FORTRAN". This document described the first version of Fortran, the first fortran compiler included little syntax error checking.
Fortran 0 was modified during the implementation periond, which began in january 1955.

-Fortran I :
The implemented language, which we called Fortran I, is described in the first Fortran Programmer's Reference Manual, published October 1956.
the most audacious claim made by the fortran development group during the design of the language was that the machine code produce by the compailer would be about half as efficient as what could be produced by hand.

- Fortran II :
compiler was distributed on 1958. It fixed many bugs in the Fortran I and added some significant features to the language, the most important being the independent compilation of subroutines. Few years after, it also added support for double precision and complex data types

Fortran IV :
- Fortran IV was developed in 1961 and released in 1962. It became the most used programming language of its time. IT contains many improvements from Fortran II, like explicit type declarations for variables, logical if construct and capability of passing subprograms as parameters to other subprograms

4. As a research project, compare the features of C with those of the BASIC.
-BASIC was easy for beginners to learn, especially those who were not science oriented, and its smaller dialects can be implemented on computers with very small memories.
-C has adequate control statements and data-structuring facilities to allow its usee in many applications areas. It also has a rich set of operators that provide a high degree of expressiveness.

5.Which of the three original goals of the Fotran design commitee, in your opinion, was most difficult to achieve at that time?
-Speed of the generated object was the most difficult to achieve because of computers at that time has slow and not reliable performances.

6.Make an educated guess as to the most common syntax error in C programs.
-C has lack of complete type checking, this will cause syntax error difficult to found. For example, in versions before C99, functions could be written for which parameters were not type checked

7.LISP began a a pure functional language but gradually acquired more and more inverative features. Why?
-LISP-The first functional programming language was invented to provide language features for list processing. Interest in AI grew out liguistics were concerned with natural language processing, pyschologist were interested in modeling human information storage and retrieval, mathematiicians were interested in mechanizing certain intelligent processes.
Some method must be developed to allow computers to process symbolic data in linked lists which make LISP gradually developed.

9. Why, in your opinion, did Fortran allow names that began with I,J,K,L,M, and N as implicitly integer type?
-Scientists and engineers, used those alphabets to represent an unknown number as variable so they can process the problem. In my pure opinion, it is because it’s easier to use those alphabets as names since most likely Fortran was not yet used to develop a program that is too complex / has too many parts that using such variable name would confuse the programmer

13. What is the primary reason why C became more widely used than Fortran ?
-Fortran can’t allocate new variables or space during execution time. This made recursive subprograms to run and made it difficult to implement a data structure that change shape dinamically. Kinds of program being built were simpler than recent. Thus Fortran are not able to accomodate the requirements of recent software developments. But, C is able to cover most of Fortran’s weakness on developing software that has advanced requirements. That is why C is more widely used.