Tuesday, June 25, 2013

Concepts of Programming Languages 10th Edition : Chapter 16

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

REVIEW QUESTIONS

1. What are three primary uses of symbolic logic in formal logic?
   => - to express propositions
- to express the relationships between propositions, and
- to describe how new propositions can be inferred from other propositions that are assumed to be true.

2. What are the two parts of a compound term?
   => Two parts of a compound term are:  a functor, which is the function symbol that names the relation, and an ordered list of parameters, which together represent an element of the relation.

3. What are the two modes in which a proposition can be stated?
   => Propositions can be stated in two modes: one in which the proposition is defined to be true, and one in which the truth of the proposition is something that is to be determined. In other words, propositions can be stated to be facts or queries.

5. What are antecedents? Consequents?
   => Antecedents are the right side of clausal form propositions, whereas Consequents are the left side of clausal form propositions, because it is the consequence of the truth of the antecedent.

Concepts of Programming Languages 10th Edition : Chapter 15

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

REVIEW QUESTION

2. What does a lambda expression specify?
   => The predicate function is often given as a lambda expression, which in ML is defined exactly like a function, except with the fn reserved word, instead of fun, and of course the lambda expression is nameless.

5. Explain why QUOTE is needed for a parameter that is a data list.
   => To avoid evaluating a parameter, it is first given as a parameter to the primitive function QUOTE, which simply returns it without change.

6. What is a simple list?
   => A list which membership of a given atom in a given list that does not include sublists.

7. What does the abbreviation REPL stand for?
   =>REPL stand for read-evaluate-print loop.

11. What are the two forms of DEFINE?
    => The simplest form of DEFINE is one used to bind a name to the value of an expression. This form is (DEFINE symbol expression) The general form of such a DEFINE is (DEFINE (function_name parameters) (expression)

Concepts of Programming Languages 10th Edition : Chapter 14

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

REVIEW QUESTION

6. What is exception propagation in Ada?
   => Exception propagation allows an exception raised in one program unit to be handled in some other unit in its dynamic or static ancestry. This allows a single exception handler to be used for any number of different program units. This reuse can result in significant savings in development cost, program size, and program complexity.

9. What is the scope of exception handlers in Ada?
   => Exception handlers can be included in blocks or in the bodies of subprograms, packages, or tasks.

10. What are the four exceptions defined in the Standard package of Ada?
    => There are four exceptions that are defined in the default package, Standard:
- Constraint_aError
- Program_Error
- Storage_Error
- Tasking_Error
11. Are they any predefined exceptions in Ada?
    => Yes, they are.

12. What is the use of Suppress pragma in Ada?
    => The suppress pragma is used to disable certain run-time checks that are parts of the built-in exceptions in Ada.

14. What is the name of all C++ exception handlers?
    => Try clause.

30. In which version were assertions added to Java?
    => Assertions were added to Java in version 1.4.

31. What is the use of the assert statement?
    => The assert statement is used for defensive programming. A program may be written with many assert statements, which ensure that the program’s computation is on track to produce correct results.

32. What is event-driven programming?
    => Event-driven programming is a programming where parts of the program are executed at completely unpredictable times, often triggered by user interactions with the executing program.

Concepts of Programming Languages 10th Edition : Chapter 13

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

REVIEW QUESTION

1. What are the three possible levels of concurrency in programs?
   => - Instruction level (executing two or more machine instructions simultaneously)
        - Statement level (executing two or more high-level language statements simultaneously)
        - Unit level (executing two or more subprogram units simultaneously)

7. What is the difference between physical and logical concurrency?
   => Physical concurrency is several program units from the same program that literally execute simultaneously. Logical concurrency is multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor.

8. What is the work of a scheduler?
   => Scheduler manages the sharing of processors among the tasks.

12. What is a heavyweight task? What is a lightweight task?
    => Heavyweight task executes in its own address space. Lightweight task all run in the same address space.

Concepts of Programming Languages 10th Edition : Chapter 12



Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

REVIEW QUESTION

2. What are the problems associated with programming using abstract data types?
   => -In nearly all cases, the features and capabilities of the existing type are not quite right for the new use.
      -The type definitions are all independent and are at the same level.

4. What is message protocol?
   => Message protocol is the entire collection of methods of an object.

5. What is an overriding method?
   => Overriding method is method that overrides the inherited method.

7. What is dynamic dispatch?
   => Dynamic dispatch is the third characteristic (after abstract data types and inheritance) of object-oriented programming language which is a kind of polymorhphism provided by the dynamic binding of messages to method definitions.

Concepts of Programming Languages 10th Edition : Chapter 11

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review Question

1. What are three primary uses of symbolic logic in formal logic?
   => - to express propositions
- to express the relationships between propositions, and
- to describe how new propositions can be inferred from other propositions that are assumed to be true.

2. What are the two parts of a compound term?
   => Two parts of a compound term are:  a functor, which is the function symbol that names the relation, and an ordered list of parameters, which together represent an element of the relation.

3. What are the two modes in which a proposition can be stated?
   => Propositions can be stated in two modes: one in which the proposition is defined to be true, and one in which the truth of the proposition is something that is to be determined. In other words, propositions can be stated to be facts or queries.

5. What are antecedents? Consequents?
   => Antecedents are the right side of clausal form propositions, whereas Consequents are the left side of clausal form propositions, because it is the consequence of the truth of the antecedent.

7. What are the forms of Horn clauses?
   => Horn clauses can be in only two forms: They have either a single atomic proposition on the left side or an empty left side. The left side of a clausal form proposition is sometimes called the head, and Horn clauses with left sides are called headed Horn clauses. Headed Horn clauses are used to state relationships, such as likes( bob, trout ) likes( bob, fish ) x fish( trout )

11. What is an uninstantiated variable?
    => An uninstantiated variable is a variable that has not been assigned a value.

13. What is a conjunction?
    => Conjunctions contain multiple terms that are separated by logical AND operations.

PROBLEM SET

1.”All predicate calculus propositions can be algorithmically converted to clausal form”. Is this statement true or false?
   => This statement is true. Nilsson (1971) gives proof that this can be done, as well as a simple conversion algorithm for doing it.

2. Describe how a logic programming language is different from a general programming language.
   => Programming that uses a form of symbolic logic as a programming language, unlike other general programming language, is often called logic programming; languages based on symbolic logic are called logic programming languages, or declarative languages.

10. Using the internet for reference, find some of the applications of expert systems.
    => - Expert system in healthcare: The Electronic health record (EHR) is designed to replace the traditional medical and bring together a more versatile, expansive and robust expert system to provide greater quality care.
       - Expert systems in the financial field: Loan departments are interested in expert systems for morgages because of the growing cost of labour, which makes the handling and acceptance of relatively small loans less profitable.

       - A new application for expert systems is automated computer program generation. Funded by a US Air Force grant, an expert system-based application (hprcARCHITECT) that generates computer programs for mixed processor technology (FPGA/GPU/Multicore) systems without a need for technical specialists has recently been commercially introduced.

Monday, June 24, 2013

Concepts of Programming Languages 10th Edition : Chapter 10

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review Question

2. Which of the caller or callee saves execution status information?
   => Called.

4. What is the task of a linker?
   => The task of a linker is to find the files that contain the translated subprograms referenced in that program and load them into memory.

6. What is the difference between an activation record and an activation record instance?
   => An activation record is the format, or layout, of the moncode part of a subprogram, whereas an activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.

8. What kind of machines often use registers to pass parameters?
   => RISC.

11. What is an EP, and what is its purpose?
    => EP is a point or first address of the activation record instance of the main program. It is required to control the execution of a subprogram.


Problem Set

6. Although local variables in Java methods are dynamically allocated at the beginning of each activation,
   under what circumstances could the value of a local variable in a particular activation retain the value of
   the previous activation?
   => If the variable is declared as static. Static modifier is a modifier that makes a variable history – sensitive.

8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint:Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found(see Section 10.4.2).
   =>  Following the hint stated with the question, the target of every goto in a program could be represented as an address and a nesting_depth, where the nesting_depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. Then, when a goto is executed, the static chain is followed by the number of links indicated in the nesting_depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.

9. The static-chain method could be expanded slightly by using two static links in each activation  record instance where the  second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?
   =>  Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs.

Concepts of Programming Languages 10th Edition : Chapter 9

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review Questions

1. What are the three general characteristics of subprograms?
   => - Each subprogram has a single entry point.
      - The calling program unit is suspended during the execution of the called subprogram, which implies that there is only subprogram in execution at any given time.
      - Control always returns to the caller when the subprogram execution terminates.

8. What are formal parameters? What are actual parameters?
   => Formal parameters are the parameters in the subprogram header, whereas actual parameters are a list of parameters to be bound to the formal parameters of the subprogram.

10. What are the differences between a function and a procedure?
    => Functions structurally resemble procedures bu are semantically modeled on mathematical function.

11. What are the design issues for subprograms?
    => The design issues for subprograms are:
- Are local variables statically or dynamically allocated?
- Can subprogram definitions appear in other subprogram definitions?
- What parameter-passing method or methods are used?

24. What is an overloaded subprogram?
    => An overloaded subprogram is one that has the same name as another subprogram in the same referencing environment.

25. What is ad hoc binding?
    => The environment of the call statement that passed the subprogram as an actual parameter is called ad hoc binding.

26. What is multicast delegate?
    => Multicast delegate is the all of the methods stored in a delegate instance are calles in the order in which they were placed in the instance.

32. What exactly is a delegate?
    => Delegate is a power and flexibility of method pointers which is increased by making them objects.

34. What is a closure?
    => Closure is a nested subprogram to be called from anywhere in a program.



Problem Set

3. Argue in support of the templated functions of C++. How is it different from the templated functions of other languages?
   => It is different as C++ differentiates function based on overloading. It is not practical to make multiple function overloading in regard to writability and readability. Instead, creating a template allows a function to receive any datatype as long as the variation is based on the formal parameter definition.

5. Consider the following program written in C syntax:
void swap(int a, int b) {
int temp;
temp = a;
a = b;
b = temp;
}

void main() {
int value =1, list[5]= {2,4,6,8,10};
swap (value,list[0]);
swap(list[0],list[1]);
swap(value,list[value]);
}
   for each of the following parameter-passing methods, what are all of the values of the variables value, and list after each of the three calls to swap?
a. Passed by value
b. Passed by reference
c. Passed by value-result

   => a. Passed by Value
          -value =1 , list[5] = {2,4,6,8,10}
         b. Passed by reference
         -value =6, list[5] ={4,1,2,8,10}
         c. Passed by value-result
         -value =6, list[5] ={4,1,2,8,10}

7. Consider the following program written in C syntax:
void fun(int first, int second){
first+=first;
second+=second;
}

void main(){
int list[2] ={3,5};
fun(list[0],list[1]);
}
   for each of the following parameter-passing methods, what are the values of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result

   =>   a. 3, 5
  b. 6, 10
  c. 6, 10

15. How is the problem of passing multidimensional arrays handled by Ada?

    => Ada compilers are able to determine the defined size of the dimensions of all arrays that are used as parameters at the time subprograms are compiled.

Concepts of Programming Languages 10th Edition : Chapter 8

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review Questions

1. What is the definition of control structure?
   => A control structure is a control statement and the collection of statements whose execution it controls.

3. What is the definition of block?
   => A block is a sequence of code, delimited by either braces or the do and end reserved words.

5. What are the design issues for selection structures?
   => The design issues for selection structures are :
- What is the form and the type of the expression that controls the selection?
- How are the then and else clauses specified?
- How should the meaning of nested selectors be specified?

9. What are the design issues for multiple-selection statements?
   => The design issues for multiple-selection statements are:
- What is the form and type of the expression that controls the selection?
- How are the selectable segments specified?
- Is execution flow through the structure restricted to include just a single selectable segment?
- How are the case values specified?
- How should unrepresented selector expression values be handles, if at all?

15. What are design issues for counter-controlled loop statements?
    => The design issues for counter-controlled loop statements are:
- What are the type and scope of the loop variable?
- Should it be legal for the loop variable or loop parameters to be changed in the loop, and if so, does the change affect loop control?
- Should the loop parameters be evaluated only once, or once for every iteration?

19. What does the range function in Phyton do?
    => Range function in Phyton takes one, two, or three parameters and it never returns the highest value in a given parameter range.

20. What contemporary languages do not include a goto?
    => Ruby

26. What is a user-defined iteration control?
    => A user-defined iteration control is a primary iteration that an alternative form that is in class by itself.



Problem Set

1. What design issues should be considered for two-way selection statements?
   =>The design issues for two-way selectors can be summarized as follows:

      - What is the form and type of the expression that controls the selection?

      - How are the then and else clauses specified?

      - How should the meaning of nested selectors be specified?

11. Explain the advantages and disadvantages of the Java switch statement, compared to C++'s switch statement.
    => The Java variable in the argument of a switch statement can be of type integral ( byte, short etc.), char and String( JDK 1.7 onwards), whereas in C++ the argument can be int or char.

14. State one of the main legitimate needs for gotos.
    => It is useful for programmer who wants to check errors in their program. Rather than fully modifying their code, they can put some goto statement inside the if statement and return the value of the error in case if an error happens.

Saturday, April 6, 2013

Concepts of Programming Languages 10th Edition : Chapter 7


Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

 Review questions

 2.    What is a ternary operator?
        => A ternary operator is an operator with three operands.

 3.    What is a prefix operator?
          => A prefix operator is an operator that precede their operands

 9.    What is a coercion?
        => A coercion is the implicit type convertion.

10. What is a conditional expression?
        => Conditional expression is a statement that uses if-then-else statements.

11. What is an overloaded operator?
        => An overloaded operator is the multiple uses of an operator.

15. What is referential transparency?
        => Referential transparency is 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.

28. What is a cast?
        => A cast is an operator to convert a data type into another data types.


Problem Set

 3.    Do you think the elimination of overloaded operators in your favorite language would be beneficial? Why or why not?
=> I think it is not beneficial because it can be ambigious if we want to use that operator with the same type.


5.    Should C’s assigning operations (for example, +=) be included in other languages (that do not already have them)? Why or why not?
=> Yes, because we can make the operator simpler than before. We can just write a+=b instead a=a+b.

20.  Consider the following C program:
             int fun(int *i) {
                    *i += 5;
                      return 4;
              }
             void main() {
                      int x = 3;
                      x = x + fun(&x);
               }

What is the value of x after the assignment statement in main, assuming
a. operands are evaluated left to right.
b. operands are evaluated right to left.

=> a. 12
     b. 7

21. Why does Java specify that operands in expressions are all evaluated in left-to-right order?
=> Java specify that operands in expressions are all evaluated in left-to-right order because Java is an associative language because associative in common language is evaluated from left to right.


Concepts of Programming Languages 10th Edition : Chapter 6


Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT


Review Questions
1. What is a descriptor?
=> 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. 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, for reasons discussed in the following paragraph.

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.
                       - An enumeration type is one in which all of the possible values, which are named constants, are provided, or enumerated, in the definition.
                       - A subrange type is a contiguous subsequence of an ordinal type.

 8.    What are the design issues for arrays?
=> The primary design issues specific to arrays are the following:
                    - What types are legal for subscripts?
                    - Are subscripting expressions in element references range checked?
                    - When are subscript ranges bound?
                    - When does array allocation take place?
                    - Are ragged or rectangular multidimensioned arrays allowed, or both?
                    - Can arrays be initialized when they have their storage allocated?
                    - What kinds of slices are allowed, if any?

12. What languages support negative subscripts?
=> Language that supports negative subscripts is Perl.

15. What is an aggregate constant?
=> Aggregate constant is the parenthesized lists of values in Fortran language.

17. Define row major order and column major order.
=> In Row major order is 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. 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.

32. What are the design issues for unions?
=> The design issues for unions are:
                    - Should type checking be required? Note that any such type checking must be dynamic.
                    - Should unions be embedded in records?

35. What are the design issues for pointer types?
=> The design issues for pointer types are:
                   - What are the scope and lifetime of a pointer variable?
                 - What is the lifetime of a heap-dynamic variable (the value a pointer references)?
                 - Are pointers restricted as to the type of value to which they can point?
                 -  Are pointers used for dynamic storage management, indirect addressing, or both?
                 - Should the language support pointer types, reference types, or both?

43.  What is a compatible type?
=> compatible type is one that either is legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code (or the interpreter) to a legal type.

50. What is name type equivalence?
=> Name type equivalence means that two variables have equivalent types if they are defined either in the same declaration or in declarations that use the same type name.

51. What is structure type equivalence?
=> Structure type equivalence means that two variables have equivalent types if their types have identical structures.

52.  What is the primary advantage of name type equivalence?
=> The primary advantage of name type equivalence is easy to implement.

53. What is the primary disadvantage to structure type equivalence?
=> The primary disadvantage to structure type equivalence is difficult to implement.


Problem Set
2.    How are negative integers stored in memory?
=> A negative integer could be stored in sign-magnitude notation, in which the sign bit is set to indicate negative and the remainder of the bit string represents the absolute value of the number.

7.    Compare the pointer and reference type variable in C++.
=> C++ pointers can point at any variable, regardless of where it is allocated. A C++ reference type variable is a constant pointer that is always implicitly dereferenced.

8.    What are the differences between the reference type variable in C++ and those of Java?
=> C++ reference type variable is a constant, it must be initialized with the address of some variable in it definition, and after initialization a reference type variable can never be set to reference any other variable, besides Java reference variables can be assigned to refer to different class instances, they are not constants.

9.    C provides two derived data types both for name and structure type equivalence: struct and union. Make a study on when to use struct type variables and union type variables.
=>  With a union, we're only supposed to use one of the elements, because they're all stored at the same spot. This makes it useful when we want to store something that could be one of several types. A struct, on the other hand, has a separate memory location for each of its elements and they all can be used at once.

21. In what way is dynamic type checking better than static type checking?
=> Dynamic type checking better than static type checking is when we want to provide more programming flexibility.

Concepts of Programming Languages 10th Edition : Chapter 5


Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review questions
1. What are the design issues for names?
=> The design issues for names are :
               - Are names case sensitive?
               - Are the special words of the language reserved words or keywords?

4. What is an alias?
=> Alias is the variables of names that can be used to access the same memory location.

7.    Define binding and binding time.
=> binding is an association between an attribute and an entity, such as between variable and its type or value, or between an operation and a symbol. The time at which a binding takes place is called binding time.

 9.  Define static binding and dynamic binding.
=> A binding is static if it first occurs before run time begins and remains unchanged throughout program execution. If the binding first occurs during run time or can change in the course of program execution, it is called dynamic.

11. What are the advantages and disadvantages of dynamic type binding?
=> The advantages are:
       - Dynamic type binding allows any variable to be assigned a value of any type.
       - It provides more programming flexibility.
        The disadvantages are:
       -  It causes programs to be less reliable, because the error-detection capability of the compiler is diminished relative to a compiler for a language with static type bindings.
        - The cost of implementing dynamic attribute binding is considerable, particularly in execution time.

18. What is a block?
=> A block is a section of codes.


Problem Set
  1. Decide which of the following identifier names is valid in C language. Support your decision.
_Student
int
Student
123Student
Student123
=> The valid identifiers are: _Student, Student, and Student123. It’s because an identifier in C language has its own rule. There are:
             - An identifier can’t be started with number. The number is valid as long as it is not in the front of an identifier.
               - An identifier can’t include any data types.
               - An identifier can’t be started with symbol.
               - There are not allowed if the name of identifiers if same.

 4.  Why is the type declaration of a variable necessary? What is the value range of the int type variable in Java?
=> The type declaration of a variable is necessary because, in a program it documented information about its data, which provides clues about the program’s behavior. The value range of the int type variable in Java is 32 bits (4 bytes).

10. Consider the following C program:
void fun(void) {
int a, b, c; /* definition 1 */
. . .
while (. . .) {
int b, c, d; /*definition 2 */
. . . <-1 p="">
while (. . .) {
int c, d, e; /* definition 3 */
. . . <-2 p="">
}
. . . <-3 p="">
}
. . . <-4 p="">
}
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.
=>  - In 1 and 3 : the visible variables are a, b(both), c(both), and d from definition 1 and 2.
      - In 2: the visible variables are a, b(both), c(both), d(both), and e from definition 1, 2, and 3.
      - In 4: the visible variables are a, b, and c from the definition 1.

Tuesday, March 26, 2013

Concepts of Programming Languages 10th Edition : Chapter 3



Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT


Review Questions

1. Define syntax and semantic.
=> The syntax of a programming language is the form of its expressions, statements, and program units. Semantics is the meaning of those expressions, statements, and program units.

5. What is the difference between a sentence and a sentential form?
=> Sentence is the strings of a language and a sentential form is the start symbol S of a grammar or any string in (V union T)* that can be derived from S. 

7. What three extensions are common to most EBNFs?
=> The three extensions are common to most EBNFs are brackets, braces, and multiple-choice options.

8. Distinguish between static and dynamic semantics.
=> The static semantics of a language is only indirectly related to the meaning of programs (syntax rather than semantics) and the dynamic semantics of a language is the meaning of the expression, statements, and program units of a programming language.

10. What is the difference between a synthesized and an inherited attribute?
=> Synthesizes attributes are used to pass semantic information up a parse tree, while inherited attributes pass semantic information down and across a tree.

15. Describe the two levels of uses of operational semantics.
=> The two levels of uses of operational semantics are natural operational semantics which is the highest level that interest in the final result of the execution of a complete program and the lowest level is structural operational semantics which 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.

17. What is stored in the state of a program for denotational semantics?
=> The state of a program for denotational semantics is the value of all its current variable.

18. Which semantics approach is most widely known?
=> The Denotational semantics is the most widely known semantics approach.

22. Give an example of an ambiguous grammar.
=> <assign>   -><id>< expr >
< id > -> A|B|C
< expr >-> < expr >+< expr>
|< expr >*< expr >
| (< expr >)
< id >

28. What is the use of the wp function? Why it is called a predicate transformer?
=> wp function is used to treat the process of producing a weakest precondition. It is called a predicate transformer because it takes a predicate, or assertion, as a parameter and returns another predicate.

Problem Set

1. Syntax error and semantics error are two types of compilation error. Explain the difference between the two in a program with examples.
=> Syntax Error: error due to missing colon, semicolon, parenthesis, etc. Syntax is the way in which we construct sentences by following principles and rules. 

Example: In C++, it would be a syntax error to say 

int x = "five";

This will not compile because it does not follow the syntax of the language and does not make any sense to the compiler. 


Semantic Error: it is a logical error. it is due to wrong logical statements. Semantics is the interpretations of and meanings derived from the sentence transmission and understanding of the message. Semantics errors are Logical, while Syntax errors are code errors. 

Example: A semantic error would compile, but be incorrect logically:

const int pi = 12345;

3.   Rewrite the BNF of Example 3.4 to represent operator -  and operator / instead of operator + and operator *.
=> <assign>   -><id>< expr >
< id > -> A|B|C

< expr >-> < expr >- < term >
 |< term >
< term > -> < term > / < factor >
                  |< factor >
< term > -> (< expr >)
 | < id >


4. Rewrite the BNF of Example 3.4 to add the += and *= operators of Java.
=><assign>   -><id>< expr >
< id > -> A|B|C

< expr >-> < expr >+=< term >
 |< term >
< term > -> < term > *= < factor >
                  |< factor >
< term > -> (< expr >)
 | < id >



 6. Using the grammar in Example 3.2, show a parse tree for each of the following statements:
a. A = A * (B * (C + A))
b. B = C * (A + C * B)
c. A = A + (B * (C))


7. Using the grammar in Example 3.4, show a parse tree for each of the following statements:
a. A = ( A * B ) + C
b. A = B * C + A
c. A = A + (B * C)
d. A = B * (C + (A *







10. Describe, in English, the language defined by the following grammar:
<S>-> <X> <Y>
<X>-> x < X >  | x
<Y>->y < Y > | y

=> <S>-> <X> <Y>   = S includes X and Y

<X>-> x < X >  | x                  = x is the element of X
<Y>->y < Y > | y                    = y is the element of Y