Concepts of Programming Languages FINAL Duplicate

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is a block?

Block is such a section of code.

What is coercion?

Coercion is when Lua performs automatic conversion of numbers to strings and vice versa where it is appropriate.

What are design issues for counter-controlled loop statements?

- 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?

What are the design issues for functions?

- Are side effects allowed? - What types of return values are allowed?

What are three semantic models of parameter passing?

- In mode - Out mode - Inout mode

What are the three general characteristics of subprograms?

- Each subprogram has a single entry point. - The calling program is suspended during the execution of the called subprogram. - Control always returns to the caller when the called subprogram's execution terminates.

What are design issues for all iterative control statement?

- How is the iteration controlled? - Where should the control mechanism appear in the loop statement?

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.

What are two potential problems with the static-chain method?

- It is difficult for a programmer working on a time-critical program to estimate the costs of nonlocal references, because the cost of each reference depends on the depth of nesting between the reference and the scope of declaration. - Subsequent code modifications may change nesting depths, thereby changing the timing of some references, both in the changed code and possibly in code far from the changes.

The design issues for logically controlled loop statements:

- Should the control be pretest or posttest? - Should the logically controlled loop be a special form of a counting loop or a separate statement?

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

1. Compile time checking better run-time efficiency. 2. Uncovers errors earlier so less costly to remove.

Define functional side effect.

Functional side effect when a function changes a two-way parameter or a non-local variable.

What is an overloaded subprogram?

An overloaded sub program is a sub program that has the same name with another subprogram in the same referencing environment, but has a different protocol.

Define abstract data types.

- the representation of objects of the type is hidden from the program units that use the type. - the declarations of the type and the protocols of the operations on objects of the type.

What is the design issues for arrays? Design issues for arrays:

1. What types are lehal for subscripts? 2. Are subscripting expressions in element references range-checked? 3. When are subscript ranges bound? 4. When does allocation take place? 5. What is the maximum number of subscripts? 6. Can array objects be initialized? 7. Are any kind of slices allowed?

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> <factor> → ( <expr> ) | <id>

What are the design issues for multiple-selection statement?

- 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 handled, if at all?

What design issues should be considered for two-way selection statements? // The design issues for two-way selectors can be summarized as

- 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?

Who is said to be the first programmer in human history? Use the Internet for help.

Ada Lovelace is the first that is said tobe the first programmer in human history.

What are the advantages of the two parts of the definition of abstract data type?

Information hiding, improved readability, and easier to manage.

What are the design issues for subprograms?

- Are local variable static or dynamic? - Can subprogram definitions appear in other subprogram definitions? - What parameter passing methods are provided? - Are parameters type checked? - If subprograms can be passed as parameters and subprograms can be nested, what is the refrencing enviroment of a passed subprogram? - Can subprograms be overloaded? - Can subprograms be generic?

Define strongly typed.

Strongly typed when every type error is always detected(compile or run time).

What are the modes, the conceptual models of transfer, the advantages, and the disadvantages or pass-by-value, pass-by-result, pass-by-value-result, and pass-by-reference parameter-passing methods?

pass-by-value: the value of the actual parameter is used to initialize the corresponding formal parameter. This formal parameter is then used as a local variable in the subprogram. Since the subprogram is receiving data from the actual parameter, this is a model of in-mode semantics. In most cases, pass-by-value is implemented using copy where an actual value is copied then transmitted. However, it can be implemented by passing an access path to the value of the actual parameter. Copy implementation is more efficient, because when using an access path the value is stored in a write protected cell that is not always simply enforced. An advantage of pass-by-value is it's speed. Since the actual value is passed there is no need to go find it. A disadvantage is that if a copy is used then that copy must be stored, and that storage could be costly if using a large variable. pass-by-result: With pass-by-result, no value is transmitted to the subprogram. Instead, the formal parameter acts like a local variable, and before control is transferred back to the caller the variables value is transmitted back to the actual parameter. Because no data is transferred to the subprogram, but it transmits data back to the actual parameter it is an out-mode semantic. Most typically pass-by-result uses a copy conceptual model. Pass-by result has all of the advantages and disadvantages of pass-by-value, but more disadvantages. An additional disadvantage is that there can be an actual parameter collision, because order of expressions matter. void Fixer(out int x, out int y) Unknown macro: { x=17; y=35; } f.Fixer(out a, out a); if x first then a = 35, else if y first then a = 17 pass-by-value-result: This passing method is actually a combination of pass-by-value and pass-by-result. The value of the actual parameter is used to initialize the corresponding formal parameter, which then acts as a local variable. The formal parameters must have local storage associated with the called subprogram. At termination, the subprogram transmits the value of the formal parameter back to the actual parameter. As such, it uses inout-mode semantics and copy passing conceptual model. Also, pass-by-value-result has the same advantages and disadvantages as pass-by-value and pass-by-result with some more advantages. The largest extra advantage of pass-by-value-result is that it solves pass-by-reference's aliasing problems (discussed in the pass-by-reference section). pass-by-reference: With pass-by-reference an address (reference to the memory location of the actual parameter) is passed to the subprogram. Pass-by-reference is another example of an inout-mode semantic. Also, the reference being passed is an example of an access path conceptual model. An advantage of pass-by-reference is that it is efficient in both time and space. This is no duplicate space required or copying. A disadvantage to pass-by-reference is the increase in time to access formal parameters because of the additional level of indirect addressing. Secondly, if only one way communication to the called subprogram is required, inadvertent and erroneous changes may be made to the actual parameter. Finally, aliasing should be expected with pass-by-reference. Since pass-by-reference makes access paths available to the called subprograms, it broadens their access to non-local variables. These aliasing problems lead to decreased readability and reliability.

What is the definition of block?

A block is a section of code which is grouped together. Blocks consist of one or more declarations and statements. A programming language that permits the creation of blocks, including blocks nested within other blocks, is called a block-structured programming language.

What is conditional expression?

A conditional expression is a compound expression that contains a condition that is implicity converted to type bool in C++ (operand1), an expression to be evaluated if the condition evaluates to true (operand2), and an expression to be evaluated if the condition has the value false (operand3).

What is definition of control structure?

A control structure is a primary concept in most high-level programming languages. In its simplest sense, it is a block of code. More specifically, control structures are blocks of code that dictate the flow of control. In other words, a control structure is a container for a series of function calls, instructions and statements.

What is a descriptor?

A descriptor is the collection of the attributes of a variable.

Describe the operation of a general language generator.

A general language generator is a device that can be used to generate the sentences of the language. It generates unpredictable sentences which makes a generator seems to be a device of limited usefulness as language descriptor.

Describe the operation of a general language recognizer.

A general language recognizer is a recognition device capable of reading strings of characters from the alphabet. It would analyze the given string and it would either accept or reject the string based from the language given.

What is hybrid implementation system?

A hybrid implementation system is a compromise between compilers and pure interpreters that is faster than pure interpretation because the source language statements are decoded only once.

What are the limitations of implementing a multiple selector from two-way selectors and gotos?

A multiple selector can be built from two-way selectors and gotos, but the resulting structures are cumbersome, unreliable, and difficult to write and read.

What is prefix operator?

A prefix operand means has some operators, which means they precede their operands.

What is ternary operator?

A ternary operator is an operator that takes three arguments. The arguments and result can be of different types.

Define type error.

A type error is thrown when a value is a different type than what was expected.

What are advantages and disadvantages of implicit declarations?

Advantage: writeability. Disadvantages: reliability and readability.

What are the advantages and disadvantages of dynamic local variables?

Advantages: - Gives you support for recursion. - Storage for locals is shared among some subprograms. Disadvantage: - Allocation/Deallocation, initialization time - Indirect addressing(???) - Subprograms can not be history sensitive

What are the advantages and disadvantages of dynamic scoping?

Advantages: The only advantage of dynamic scoping is writeability. It is more convenient and it provides more flexibility than static scoping. For example, in some cases, some parameters passed from one subprogram to another are variables that are defined in the caller. None of these need to be passed in a dynamic scoped language, because they are implicitly visible in the called subprogram. Disadvantages: 1. Inability to statically check for references to nonlocal variables. 2. Dynamics scoping also makes program difficult to read because the calling sequence of subprograms must be known to determine the meaning of references to nonlocal variables. 3. There's no way to protect local variables from being accessed to by subprograms because local variables of subprogram are all visible to all other executing subprograms, regardless of textual proximity. 4. Accessing to nonlocal variables in dynamic scoping takes far longer than accesses to nonlocal variables when static scoping is used.

What are advantages and disadvantages of dynamic type binding?

Advantages: flexibility and no definite types declared(PHP, JavaScript). Disadvantages: adds to the cost of implementation and type error detection by the compiler is difficult.

What are the advantages of user-defined enumeration types?

Advantages: readability and reliability.

What is an alias?

Alias is one variable name that can be used to access the same memory location.

What is aliasing?

Aliasing is having two or more distinct names that can be used to access the same memory cell.

In what ways are the coroutines different from conventional subprograms?

Coroutines have more than one entry point, where as subprograms have only one. Coroutines call is named resume.

Describe a situation in which the add operator in a programming language would not be commutative.

An expression such as a + fun(b) , as described on page 300.

What is an overloaded operator?

An overloaded operator if use of an operator for more than one purpose.

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.

What are the advantages and disadvantages of keyword parameters?

As the names would be the same as the formal parameters, which in their self represent their types and all parameters can appear in any order, so there would be no error with types and type checking. But as we are passing them with their real names, the person who is writing the subprogram should know their real names, which would be a hard deal every now and then.

Define binding and binding time.

Binding is an association such as between an attribute and an entity, or between an operation and a symbol. Binding time is the time at which a binding takes place.

What are the design issues for character string types?

Character string types design issues: 1. Is it a primitive type or just a special kind of array 2. Should the length of strings be static or dynamic

Which produces faster program execution, a compiler or a pure interpreter?

Compiler produces faster program execution than pure interpreter.

Define narrowing and widening conversions.

Narrowing conversion is one that converts an object to a type that cannot include all of the values of the original type, example: float to int. Widening conversions is one in which an object is converted to a type that can include at least approximations to all of the values of the original type, example: int to float.

Compare the use of closures by programming languages.

Nearly all functional programming languages, most scripting languages, and at least one primarily imperative language, C#, support closures. These languages are static-scoped, allow nested subprograms, and allow subprograms to be passed as parameters.

Why, in your opinion, do new scripting languages appear more frequently than new compiled languages?

In my opinion, new scripting languages appear more frequently than new compiled language because it's often smaller, more simple, and focused on more narrow applications, that means its libraries don't need to be large.

What are design issues for names?

Design issues for names are names are case sensitive or not and special words reserved words or keywords.

What are the design issues for pointer types?

Design issues of pointer types: 1. What are the scope of and lifetime of a pointer variable? 2. What is the lifetime of a heap-dynamic variable? 3. Are pointers restricted as to the type of value to which they can point? 4. Are pointers used for dynamic storage management, indirect addressing, or both? 5. Should the language support pointer types, references types, or both?

What are the disadvantages of multiple programming language?

Disadvantages of multiple programming languages are we need more time to learn many languages, sometimes maybe we forget the structure of the languages or even switched when use a language with other languages, and it isn't effective.

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.

Prove that the following grammar is ambiguous: <S> → <A> <A> → <A> * <A> | <id> <id> → x | y | z

Example ambiguous sentence: x * y * z Parse tree 1: <S> <A> <A> <A> <id> x * <A> <id> y * <A> <id> z Parse tree 2: <S> <A> <A> <id> x * <A> <A> <id> y * <A> <id> z Note in the above representation of a tree, all symbol(s) with N column indentations are children nodes of the parent node that is immediately above these symbol(s) and has N-1 column indentations.

What are two fundamental design considerations for parameter-passing methods?

First is how much the method is efficient. And second is whether its a one-way or a two-way data transfer. But obviously the collide since the beginning, cause a safe and reliable programming should be using as many one way parameters as possible and to avoid using two ways parameters as long as it can. But the most efficient way is to use pass-by-Refrence which is a two-way passing method.

What are formal parameters? What are actual parameters?

Formal parameter is a dummy variable, which is introduced in the subprogram header, and is used in the function body. Actual parameter is the value of address used in the statement calling the subprogram.

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.

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.

Does a Just-in-Time (JIT) implementation system affect the execution of code? Why or why not?

JIT implementation system affect the execution of code. It's initially translates programs to an intermediate language, during the execution it compiles intermediate language methods into machine code when they are called. In this cases, interpreter is used to develop and debug program, when the bug-free state is reached, the programs are compiled to increase their execution speed.

What is a mixed-mode expression?

Mixed-mode expression is one that has operands of different types.

What is name type equivalence?

Name type equivalence means the two variables have equivalent types if they are in either the same declaration or in declarations that use the same type name.

Would it be a good idea to eliminate all operator precedence rules and require parentheses to show the desired precedence in expressions ? Why and why not ?

No, it wouldn't be a good idea. Because it will affect the readability and writeabiity, even maybe there will be multiple answers that are ambiguous.

What is a nonassociative operator?

Nonassociative operator is operator that has no defined behavior when used in sequence in an expression.

Define operator precedence and operator associativity.

Operator precedence rules of expression evaluation define the other in which 'adjacent' operators of different precedence levels are evaluated. Operator associativity rules for expression evaluation define the order in which adjacent operators with the same precedence level are evaluated.

Explain how orthogonality in a programming language is closely related to simplicity.

Orthogonality in a programming language is closely related to simplicity because orthogonality 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.

What programming language has dominated artificial intelligence over the past 50 years?

Programming language has dominated artificial intelligence over the past 50 years was LISP (McCarthy et al.,1965).

What programming language has dominated business applications over the past 50 years?

Programming language has dominated business applications over the past 50 years was COBOL (ISO/IEC,2002).

Whanott programming language has dominated scientific computing over the past 50 years?

Programming language has dominated scientific computing over the past 50 years was Fortran.

Why is readability important to writeability?

Readability is important to writeability because the process of writing a program requires the programmer frequently to reread the part of the programmer that is already written.

What is referencing environment of a statement?

Referencing environment of a statement is the collection of all names that are visible in the statement.

What is referential transparency?

Referential transparency is a property whereby an expression can be replaced by its value without affecting the program.

What are the advantages of referential transparency?

The main advantage of referential transparency is that it makes it much easier to reason about programs, and to apply program transformations, including optimizations and partial evaluations at compile-time.

Describe the shallow-access method of implementing dynamic scoping.

Shallow access is an alternative implementation method, not an alternative semantics. The semantics of deep access and shallow access are identical. In the shallow-access method, variables declared in subprograms are not stored in the activation records of those subprograms.

What is short-circuit evaluation?

Short-circuit evaluation means that in a condition, control evaluates from left to right only the necessary expressions to know whether the condition is true or false.

Do you believe that solving a problem in a particular algorithmatic step requires programming language skills? Support your opinion.

Solving a problem in a particular algorithmic step doesn't always required programming language skills. Because algorithmic step is just steps that people make to finish a process from the start point until end point sequentially. The programming language skill is one of ways to make the steps in a computer.

Define static binding and dynamic binding.

Static binding: if it first occurs before run time and remains unchanged throughout program execution. Dynamic binding: if it first occurs during execution or can change during execution of the program.

Distinguish between static and dynamic semantics.

Static semantics is more on the legal forms of programs (syntax rather semantics) and is only indirectly related to the meaning of the programs during execution. Static semantics is so named because the analysis required checking these specifications can be done at compile time. Dynamic semantics is describing the meaning of the programs. Programmers need to know precisely what statements of a language do. Compile writers determine the semantics of a language for which they are writing compilers from English descriptions.

What is structure type equivalence?

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

What is the definition used in this chapter for "simple subprograms"?

Subprogram cannot be nested and all local variables are static.

Syntax error and semantic 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. Examples: 1. int x = "five"; In C++, this will not compile because it does not follow the syntax of the language and does not make any sense to the compiler. 2. printf("Hello World!"); printf() would be a syntax error, as the command was mistyped. 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. Examples: 1. A semantic error would compile, but be incorrect logically: const int pi = 12345; The program will likely compile and run without error but its results will be incorrect. (Note that these types of errors are usually much harder to debug). 2. 2+2=1; It would be a semantic error because it is incorrect logic.

Define syntax and semantics.

Syntax and semantics are terms used in relation to aspects of language. Syntax is concerned with the structure of language. Syntax is a matter of the logical or grammatical form of sentences, rather than what they refer to or mean. Semantics is concerned with the meaning of words and sentences. Semantics is a matter of the content or meaning of the syntax, often in relation to their truth and falsehood.

What is a compatible type?

The concept of compatible types combines the notions of being able to use two types together without modification, being able to subtitute one for the other without modification, and uniting them into a composite type.

What are the language design issues for abstract data types?

The first design issue for abstract data types is the form of the container for the interface to the type. The second design issue is whether abstract data types can be parameterized. The third design issue is what access controls are provided and how such controls are specified. MY ANSWER THAT GOT 2/3 Abstract data types raise the questions of whether they can be parameterized, what are the access controls, and what is the form of the container interfacing with the type.

What three extensions are common to most EBNFs?

The first extension denotes an optional part of a RHS, which is delimited by brackets. For example: <if_stmt> -> if ( <expr> ) stmt [ else <stmt> ] 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. For example: <ident_list> -> ident {, <ident> } The third extension deals with multiple choice options. For example: <term> -> <term> ( *|/|% ) <factor>

What is the potential danger of case-sensitive names?

The potential danger is a serious detriment to readability, because names that look very similar in fact denote different entities. Case-sensitive violates the design principle that language constructs that look similar should have similar meanings.

In what way do the languages for artificial intelligence differ from the languages for web software? Support your view.

The scientific applications different from the languages for business applications because scientific applications relatively simple data structures, but required large numbers of floating-point arithmetic computations. While business application characterized by facilities for producing elaborate reports, precise ways of describing and sorting decimal numbers and character data, and the ability to specify decimal arithmetic operations.

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 and load them into memory.

What are the two kinds of abstraction in programming languages?

The two fundamental kinds of abstraction in contemporary programming languages are process abstraction and data abstraction.

If a compiler uses the static chain approach to implementing blocks, which of the entries in the activation records for subprograms are needed in the activation records for blocks?

There are two options for implementing blocks as parameterless subprograms: One way is to use the same activation record as a subprogram that has no parameters. This is the most simple way, because accesses to block variables will be exactly like accesses to local variables. Of course, the space for the static and dynamic links and the return address will be wasted. The alternative is to leave out the static and dynamic links and the return address, which saves space but makes accesses to block variables different from subprogram locals.

What are the three general methods of implementing a programming language?

Three general methods of implementing a programming language are compilation, pure interpretation, and hybrid implementation.

What are two common problems with pointers?

Two common problems with pointers are dangling pointer and lost heap-dynamic variable.

What two programming language deficiencies were discovered as a result of the research in software development in the 1970s?

Two programming language deficiencies were discovered as a result of the research in software development in the 1970s were called top-down design and stepwise refinement.

In what language is most of UNIX written?

UNIX operating system is written almost entirely in C (ISO, 1999).

What is the utility of byte code?

Utility of byte code is provide portability to any machine that has a byte code interpreter and an associated run-time system.

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))

a. A = A* (B * (C + A)) <assign> <id> A = <expr> <id> A * <expr> ( <expr> <id> B * <expr> ( <expr> <id> C + <expr> <id> A ) ) b. B = C * (A + C * B) <assign> <id> B = <expr> <id> C * <expr> ( <expr> <id> A + <expr> <id> C * <expr> <id> B ) c. A = A + (B * (C)) <assign> <id> A = <expr> <id> A + <expr> ( <expr> <id> B * <expr> ( <expr> <id> C ) )

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: list[0] = 3 | list[1] = 5 b. Passed by reference list[0] = 4 | list[1] = 6 c. Passed by value-result list[0] = 4 | list[1] = 6

a. Passed by value: list[0] = 3 | list[1] = 5 b. Passed by reference list[0] = 4 | list[1] = 6 c. Passed by value-result list[0] = 4 | list[1] = 6

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: 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 }

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 }


Ensembles d'études connexes

3.2 Transport-Layer multiplexing and demultiplexing

View Set

NP4 Licensure/Statutes + Professional Practice

View Set

AP Computer Science Unit 3 Progress Check: FRQ

View Set

ATI Mobility & Tissue Integrity Quiz

View Set

Study Block 3: Chapter 20,21,19,18

View Set