Concepts FULL Combined
Why, in your opinion, did Fortran allow names that began with I, J, K, L, M, and N as implicitly integer type?
In my opinion, Fortran allow names that began with I, J, K, L, M, and N as implicity integer type because they are integer variable otherwise, they are implicity declared as real variable. example: integer: INDEX, MONTH. while examples of real: Total, Sum, Value.
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.
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.
What are the issues with case sensitive names?
It harms readability in that names that look similar may denote different entities. It harms writeability in that you need to remember the exact cases of different variable names.
What is an overriding method?
It is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.
State why Java is said to be more pure object-oriented than C++.
Java is an object oriented language, which means that one of its core principles is inheritance. All classes (and hence the objects created from them) are derived from a parent. In this way, classes inherit variables, methods, and classes from their parent so that they do not have to redefine them. In Java's case, the common parent of all classes is Object. This gives every class some basic functionality, such as the equals, toString, and wait methods. Besides uniformity, another advantage of inheritance is clear organization. Imagine if we could not guarantee the comparison of two objects with the equals method. Finally, a global parent class means that every class, no matter how specific, can be generalized into the parent's type (Object o = new String()).
Give a brief general description of the Java servlet.
Java servlet is a foundation of the Java server-side technology. Extensions of the sevlet technology: JavaServer Pages (JSP), JavaServer Faces (JSF), Struts, Spring, Hibernate, and others.
Who developed Short Code? Why is Short Code called automatic programming?
John Mauchly developed Short Code; It's called automatic programming because is clearly simplified the programming process, but at the expense of execution time.
What is the l-value of a variable? What is the r-value?
L-value is the address of a variable, the address is what is required when the name of a variable appears in the left side of an assignment. R-value is a variable's value, it is what it is required when the name of the variable appears in the right side of an assignment statement.
What is l-value ? Write a statement in C language which gives the compile time error "l-value required".
L-value is the address of a variable, the address is what is required when the name of a variable appears in the left side of an assignment. scanf("%d",score);
Why were imperative features added to most dialects of LISP?
LISP began as a pure functional language but soon acquired some important imperative features to increased its execution efficiency.
Two distinct grammar characteristics prevent the construction of a recursive-descent parser based on the grammar. They are:
Left Recursion, Pairwise Disjoint
What is left factoring?
Left factoring is the action taken when a grammar leads backtracking while marking parsing/syntax tree.
What are the advantages of having support for exception handling built in to a language?
Less clutter to detect errors, allowing a single number of handling to handle a number of events.
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.
What are the legal return types of a destructor?
Neither constructors nor destructors have return types, and neither use return statements. Both constructors and destructors can be explicitly called.
Does Objective-C support multiple inheritance?
No Objective-C doesn't support it. (It supports only single inheritance).
What is busy waiting?
One or more threads is using a lot of CPU by continuously checking a value, or test&set() checking and writing a value in wiating for a lock to release, thus stealing CPU from the thread holding the lock.
Every derivation with an unambiguous grammar has ____
One unique derivation for the parse tree
What are the two problems with recursive descent?
Pairwise disjointness and left recursion
What does partial evaluation mean?
Partial evaluation means that the function is evaluated with actual parameters for one or more of the leftmost formal parameters.
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).
What are the 4 criteria for language evaluation?
Readability, writeability, reliability, and cost.
What kind of parsers did we study? // What are two kinds of parsers?
Recursive Descent (top down) and Shift Reduce Parser (bottom up)
Describe how a recursive-descent parsing subprogram is written for a rule with a single RHS.
Recursive-descent parsing subprogram is written for a rule with a single RHS is relatively simple. For each terminal symbol in the RHS, compared with nextToken terminal symbol. 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, parsing subprogram to be called nonterminal.
Describe the lazy and eager approaches to reclaiming garbage.
Reference counter(eager): maintain a ref count in every block, update it whenever a pointer to block changes. Mark-sweep(lazy): when no more available memory blocks, garbage collect by tracking every pointer into heap and 'marking' the block as used.
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 and disadvantages of the two types of comments?
Single Line Comments denoted by // at the beginning. Multiple Line Comments denoted by /* ----- */ at the beginning and end. Single line comments are better suited for smaller details and when you need to specify about a variable. Disadvantages include writeability and readability in that you have to create a // for every line you want to comment which can make looking at the code, messy. Multiple line comments are good for paragraph sized comments that are used for giving an overview of what a chunk of code does. Disadvantages include reliability in that if a certain piece of code changes, then it could change how the entire program works. Reduced reliability can also negatively impact cost.
Many contemporary languages allow two kinds of comments: one in which delimiters are used on both ends (multiple-line comments), and one in which a delimiter marks only the beginning of the comment (oneline comments). Discuss the advantages and disadvantages of each of these with respect to our criteria.
Single line comments are denoted by // at the beginning. Multiple line comments are denoted by /*-----*/ at the beginning and end. Single line comments are better suited for smaller details and when you need to specify about a variable. You can also quickly make a line of code invisible by turning it into a comment if need be. Disadvantages include writability and readability in that you have to create a // for every line you want to comment which can make looking at the code, messy. Multiple line comments are good for paragraph sized comments that are used for giving an overview of what a chunk of code does. If needed, a chunk of code can become invisible by turning it into a block comment, which is faster than typing // at the beginning of every line. Disadvantages include reliability in that if a certain piece of code changes, then it could change how the entire program works. In addition to that, sometimes you can make a mistake and forget to type */ at the end.
From where are Smalltalk objects allocated?
Smalltalk objects are allocated from the heap and are referenced through reference variables, which are implicitly dereferenced.
What kind of inheritance, single or multiple, does Smalltalk support?
Smalltalk supports single inheritance; it does not allow multiple inheritance.
What level of program concurrency is best supported by SIMD computers?
Statement-level concurrency.
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.
When might you want the compiler to ignore type differences in an expression?
Suppose Type1 is a subrange of Integer . It may be useful for the difference between Type1 and Integer to be ignored by the compiler in an expression.
What is concurrency?
Synchronization. Semaphores. Monitors, Mutex Locks
Compilers often base the semantics of the language structures on ______
Syntactic Form
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 kind of errors can you have that will cause the program to abort?
Syntax errors: errors due to the fact that the syntax of the language is not respected. Semantic errors: errors due to an improper use of program statements. Logical errors: The worst type of errors. errors due to the fact that the specification is not respected. Runtime errors: dynamic semantic errors, and logical errors, that cannot be detected by the compiler (debugging).
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.
What is the use of the fn reserved word in ML?
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.
What is the primary reason why C became more widely used than Fortran?
The primary reason why C became more widely used than Fortran because Fortran will never be much faster than C, moreover C is much more readable.
Explain the process of currying!
The process of currying replaces a function with more than one parameter with a function with one parameter that returns a function that takes the other parameters of the initial function.
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.
Why the type declaration if a variable is necessary? What is the value range of the int type variable in Java?
The type of a variable determines the range of values the variable can store and the set of operations that are defined for values of the type. The int type in Java have a value range of -2147483648 to 2147483647.
What is the use of the DISTRIBUTE and ALIGN specification of HPC?
The use of DISTRIBUTE and ALIGN specification of HPC is to provide information to the compiler on machines that do not share memory, that is, each processor has its own memory.
What is the use of the spawn primitive of CML?
The use of Spawn primitive of CML is to create a thread.
What is the use of subprograms BeginInvoke and EndInvoke in F#?
The use of subprograms BeginInvoke and Endinvoke in F# is to call threads asynchronously.
What is the use of the Ada use clause?
The use package clause allows for direct visibility of a visible part of a package and the use type clause is for the direct visibility of primitive operators of a type. It is like C++'s using namespace clause and can lead to similar problems that using namespace has.
Explain why lexical analysis is separated from syntax analysis.
There are 3 reasons: 1) Simplicity: Lexical analysis is not as complex as syntax analysis making the process simpler when separate. Lexical analysis provides details at a low level so separation also simplifies syntax analysis. 2) Portability: The lexical analyzer is platform dependent due to it reading input program files, and syntax analysis is platform independent. 3) Efficiency: Optimization of the lexical analyzer since the lexical analysis takes up a lot of compiling time. Optimization of syntax analysis does not have significant results.
In languages without exception-handling facilities, we could send an error-handling procedure as parameter to each procedure that can detect errors than must be handled. What disadvantage are there to this method?
There are several disadvantages of sending error handling subprograms to other subprograms. One is that it may be necessary to send several error handlers to some subprograms, greatly complicating both the writing and execution of calls. Another is that there is no method of propagating exceptions, meaning that they must all be handled locally. This complicates exception handling, because it requires more attention to handling in more places.
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.
How does a computer store doubles?
There is a bit called the sign and there are other bits that store the power of 10 called the exponent bit. The rest of the bits store the significant digits called significant precision.
Compilers often base the semantics of language structures on their syntactic form.
True
Dijkstra's guarded commands are alternative control statements with positive theoretical characteristics.
True
Implementing arrays requires more compile-time effort than implementing primitive types.
True
The advantage and disadvantage of representing Boolean values as single bits in memory, respectively are: Boolean variables stored as single bits are space efficient, but generally access to them is slower than if they were stored as bytes.
True
The lexical analyzer gathers the characters of the source program into lexical units.
True
The protocol of a subprogram is its parameter profile plus, if it is a function, its return type.
True
The syntax analyzer takes the lexical units from the lexical analyzer and uses them to construct hierarchical structures called parse trees.
True
The top symbol on the parse stack is always a state symbol that represents all of the information in the parse stack that is relevant to the parsing process.
True
What level of program concurrency is best supported by MIMD computers?
Unit-level concurrency is best supported by MIMD computers.
What is the use of the Ada use clause?
Use clause eliminates the need for explicit qualification of the references to entities from the named package.
What are the pros of named constants?
Useful as aids to readability and program reliability. Readability by using pi instead of the constant 3.14159265. Parameterize a program.
Decide which of the following identifier names is valid in C language. Support your decision. _Student int Student 123Student Student123
_Student is valid because identifier names that started by _ are allowed. int isn't valid because it's a reserved name for integer data type. Student is valid because identifier names that started by capital letter are allowed. 123Student isn't valid because identifier names in C can't started by numbers. Student123 is valid because identifier names can contain numbers in the middle or back.
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 }
Compute the weakest precondition for each of the following assignment statements and postconditions: a. a = 2 * (b - 1) - 1 {a > 0} b. b = (c + 10) / 3 {b > 6} c. a = a + 2 * b - 1 {a > 1} d. x = 2 * y + x - 1 {x > 11}
a. a = 2 * (b - 1) - 1 {a > 0} 2 * (b - 1) - 1 > 0 2 * b - 2 - 1 > 0 2 * b > 3 b > 3 / 2 b. b = (c + 10) / 3 {b > 6} (c + 10) / 3 > 6 c + 10 > 18 c > 8 c. a = a + 2 * b - 1 {a > 1} a + 2 * b - 1 > 1 2 * b > 2 - a b > 1 - a / 2 d. x = 2 * y + x - 1 {x > 11} 2 * y + x - 1 > 11 2 * y + x > 12
Compute the weakest precondition for each of the following sequences of assignment statements and their postconditions: a. a = 2 * b + 1 b = a - 3 {b < 0}
a. a = 2 * b + 1 b = a - 3 {b < 0} a - 3 < 0 a < 3 So, a = 2 * b + 1 {a < 3} 2 * b + 1 < 3 2 * b + 1 < 3 2 * b < 2 b < 1 b. a = 3 * (2 * b + a); b = 2 * a - 1 {b > 5} 2 * a - 1 > 5 2 * a > 6 a > 3 So, a = 3 * (2 * b + a) {a > 3} 3 * (2 * b + a) > 3 6 * b + 3 * a > 3 2 * b + a > 1 n > (1 - a) / 2
What are the 4 primary language evaluation criteria? Use all lower case letters in your responses.
readability writability reliability cost
When a program has any two expressions in the program with the same value that can be substituted for one another, anywhere in the program, without affecting the action of the program, it is a property known as
referential transparency
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 three semantic models of parameter passing?
- In mode - Out mode - Inout mode
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 is the best action a system can take when deadlock is detected?
- Interrupt (i.e. send a signal/exception to) all the threads holding the lock. They will have to be able to handle the resulting interrupt, though. - Kill all the threads/processes involved. This is a drastic action, and it saves the rest of the system at the expense of the risk that some data will probably be lost by the program.
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.
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?
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.
Describe the three string length options.
1. First: the length can be static and set when the string is created. Such a string is called a static length string. 2. Second: to allow strings to have varying length up to a declared and fixed maximum set by the variable's definition. There are called limited dynamic length strings. 3. Third: to allow strings to have varying length with no maximum. These are called dynamic length strings.
What are the 3 control forms of the RHS in EBNF?
1. Optional: [ ] elements can be included or discarded 2. Repeating: { } can be repeated indefinitely or left out all together. an item can be repeated zero or more times. 3. Grouping: ( ) means either/or. multiple items can be grouped together for modifiers to be applied
Explain the three reasons why lexical analysis is separated from syntax analysis.
1. Simplicity - Techniques for lexical analysis are less complex that those required for syntax analysis, so the lexical-analysis process can be simpler if it separate. Also, removing the low-level details of lexical analysis from the syntax analyze makes the syntax analyzer both smaller and cleaner. 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 a good practice to isolate machine dependent parts of any software system.
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>
Write a BNF description of the relational operator of Java, including the two operators == and !=.
<relation_expr> →id = = id | id != id
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.
Select all the true statements about lexical analysers.
A lexical analyser serves as the FRONT end, not the back. It strikes the lexemes from a given input string and reduce. It ignores comments and whitespaces. It detects syntactic errors and tokens.
What is the difference between a linker and loader (when referring to running a process)
A linker links the code to any libraries that are needed and a loader loads the process into memory.
What is a simple list?
A list which membership of a given atom in a given list that does not include sublists.
What is loop invariant? Explain with an example.
A loop invariant is a condition that is necessarily true immediately before and immediately after each iteration of a loop. Example: int j = 9; for(int i=0; i<10; i++) j-; In this example it is true (for every iteration) that i + j == 9. A weaker invariant that is also true is that i >= 0 && i < 10 (because this is the termination condition) or that j <= 9 && j >= 0.
What is the differences between a type narrowing conversion and a type widening conversion? Give an example of each.
A narrowing conversion converts a value to a type that cannot store even approximations of all of the values of the original type. For example, converting a double to a float in Java is a narrowing conversion, because the range of double is much larger than that of float. In addition, narrowing conversion are not always safe - sometimes the magnitude of the converted value is changed in the process. For example, if the floating point value 1.3E25 is converted to an integer in a Java program, the result will be only distantly related to the original value. A widening conversion converts a value to a type that can include at least approximations of all the values of the original type.
What is the primary difference between a record and a tuple?
A record is a group of named elements, example: {"x": 10}, where the value of fields labelled x is 10. A tuple is an ordered group of elements, example: (17, 21)
List one parser type and describe how it makes a parse tree.
A recursive descent parser builds a parse tree top down by using the grammar to build a parse tree. The downside with recursive descent is that it requires the grammar to only have 1 choice and it can not be left recursive or the parser will get stuck in a loop.
What is difference between a sentence and a sentential form?
A sentence is a sentential form that has only terminal symbols. A sentence form is every string of symbols in the derivation.
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
Some programming languages are typeless. What are the advantages and disadvantages of having no types in a language?
Advantages: Allows users to write programs faster. Disadvantages: Can not control the data and variables, the compiler can not detect any errors leading the poorer reliability. Can also lead to bad programming habits.
Some programming languages are typeless. What are the obvious advantages and disadvantages of having no types in a language?
Advantages: Allows users to write programs faster. Disadvantages: Can not control the data and variables, the compiler can not detect any errors leading the poorer reliability. Can also lead to bad programming habits.
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 the advantages and disadvantages of dynamic type binding?
Advantages: flexibility and no definite types declared (PHP, JavaScript). Disadvantages: It is less reliable since you do not have type error detection.
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 aggregate constant?
Aggregate constant is a nonscalar constant which value never change or aren't changed during execution of the program.
What language introduced the case statement?
Algol W was the language that intoduced the case statement.
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.
Where are all Java methods defined?
All Java methods are defined in a class.
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.
Write an BNF description of precedence and associativity rules defined for the expressions in Problem 9.
Assume the only operands are the names a, b, c, d, and e. <expr> → <expr> or <e1> | <expr> xor <e1> | <e1> <e1> → <e1> and <e2> | <e2> <e2> → <e2> = <e3> | <e2> /= <e3> | <e2> < <e3> | <e2> <= <e3> | <e2> > <e3> | <e2> >= <e3> | <e3> <e3> → <e4> <e4> → <e4> + <e5> | <e4> - <e5> | <e4> & <e5> | <e4> mod <e5> | <e5> <e5> → <e5> * <e6> | <e5> / <e6> | not <e5> | <e6> <e6> → a | b | c | d | e | const | ( <expr> )
Describe the two levels of uses of operational semantics.
At the highest level, the final result of the program execution is of interest: Natural Operational Semantics. At the lowest level, the complete sequence of state changes (caused by execution of each instruction) is of interest: Natural Operational Semantics. Two different levels of uses of operational semantics: Natural operational semantics and Structural operational semantics
Modify Grammar 1, below to add a unary minus operator that has higher precedence than either + or *. Grammar 1: <assign> -> <id> = <expr> <id> -> A | B | C <expr> -> <expr> + < term> | <term> <term> -> <term> * <factor> | <factor> <factor> -> ( <expr> ) | <id>
At the last assignment add, | - <id> So the last line is <factor> -> (<expr>) | <id> | - <id>
What data types were parts of the original LISP?
Atoms and lists.
What is the device that is used to describe more of the structure of a programming language that can be described with a context-free grammar. __________
Attribute grammars
A _____ is a device used to describe more of the structure of a programming language than can be described with a context-free grammar.
Attribute grammars.
What do you decorate a parse tree with?
Attribute grammars.
What is the basic concept of declarative semantics?
Basic concept of declarative semantics is there is a simple way to determine the meaning of each statement, and it does not depend on how the statement might be used to solve a problem.
Which two grammar characteristics prevent the construction of a recursive-descent parser based on the grammar?
Both a and b are correct A: Left recursion B: The pairwise disjointness test
What is a curried function?
Curried function let new functions can be constructed from them by partial evaluation.
What design criterion was used extensively in ALGOL 68?
Design criterion was used extensively in ALGOL 68 is orthogonality.
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 unions?
Design issues for unions: 1. Should type checking be required? 2. Should unions be embedded in records?
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 is the purpose of a C++ destructor?
Destructors are often used as a debugging aid, in which case they simply display or print the values of some or all of the object's data members before those members are deallocated. The name of a destructor is the class's name, preceded by a tilde (~).
Why can't you compare the lines of code of the productivity of functional languages vs imperative languages?
Different lines of code may take up more processing power.
What is the use of Suppress pragma or directive in Ada?
Disabling certain run-time checks that are parts of the built-in exceptions.
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.
Give an example of hardware-detectable exceptions.
Division by zero
What is exception handling 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.
Describe the three extensions that are commonly included in the various versions of EBNF?
FROM TEXTBOOK: Three extensions are commonly included in the various versions of EBNF. The first of these denotes an optional part of an RHS, which is delimited by brackets. For example, a C if-else statement can be described as <if_stmt> → if (<expression>) <statement> [else <statement>] Without the use of the brackets, the syntactic description of this statement would require the following two rules: <if_stmt> → if (<expression>) <statement> | if (<expression>) <statement> else <statement> 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. For example, lists of identifiers separated by commas can be described by the following rule: <ident_list> → <identifier> {, <identifier>} This is a replacement of the recursion by a form of implied iteration; the part enclosed within braces can be iterated any number of times. 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, |. For example, <term> → <term> (* | / | %) <factor> In BNF, a description of this <term> would require the following three rules: <term> → <term> * <factor> | <term> / <factor> | <term> % <factor> FROM WEBSITE: - 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 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, |. MY ANSWER THAT GOT 2/3 POINTS: 1) Optional [ ] elements can be included or discarded 2) Repeating { } can be repeated indefinitely or left out all together 3) Grouping ( ) multiple items can be grouped together for the application of modifiers
A preprocessor is a program that processes a program immediately after the program is compiled.
False
A state diagram is a directed graph where the arcs are labeled with state names and the nodes are labeled with the input characters that cause the transitions among the states.
False
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.
From a textbook on FORTRAN, determine how exception handling is done in FORTRAN programs.
For example, a Fortran "Read" statement can intercept input errors and end-of-file conditions, both of which are detected by the input device hardware. In both cases, the Read statement can specify the label of some statement in the user program that deals with the condition. In the case of the end-of-file, it is clear that the condition is not always considered an error. In most cases, it is nothing more than a signal that one kind of processing is completed and another kind must begin. In spite of the obvious difference between end-of-file and events that are always errors, such as a failed input process, FORTRAN handles both situations with the same mechanism.
Which version of Fortran was the first to have character string handling?
Fortran 77 was the first Fortran that have character string handling.
Refer to a book on Haskell programming and discuss the features of Haskell.
Haskell features lazy evaluation, pattern matching, list comprehension, type classes, and type polymorphism.
Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship.
Implicit heap dynamic variables use dynamic type binding. Dynamic type binding bounds types to variables at runtime. Heap dynamic variables are bound to types at runtime when they are assigned a value.
Describe the approach for the detection of subscript range errors used in C and Java.
In C subscript ranges are not checked. Java compilers usually generate code to check the correctness of every subscript expression. If any exception generates, then an unchecked exception is thrown.
Describe the mechanism of dynamic dispatch with an example in Java. Is it possible to dynamically dispatch the data members?
In C++, a method must be defined as virtual to allow dynamic binding. In Java, all method calls are dynamically bound unless the called method has been defined as final, in which case it cannot be overridden and all bindings are static. Static binding is also used if the method is static or private, both of which disallow overriding.
What kind of Java object is a monitor?
In Java, a monitor can be implemented in a class designed as an abstract data type, with the shared data being the type. Accesses to objects of the class are controlled by adding the synchronized modifier to the access methods.
What is a C++ namespace, what is its purpose?
In general, a namespace is a container for a set of identifiers and allows the disambiguation of homonym identifiers residing in different namespaces. The purpose is to help programs manage the problem of global namespace.
Compare Java's packages with Ruby's modules.
In java encapsulation construct called package .Packages can contain more than one type definition, and the types in a package are partial friends of one another. In ruby a encapsulation construct called module. Modules typically define collections of methods and constants. So, modules are convenient for encapsulating libraries of related methods and constants, whose names are in a separate namespace so there are no name conflicts with other names in a program that uses the module. Modules are unlike classes in that they cannot be instantiated or subclassed and do not define variables.
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?
What are the design issues for functions?
- Are side effects allowed? - What types of return values are allowed?
What are the different forms of assert statement?
- Assert condition. - Assert condition : expression.
What are design issues for all iterative control statement?
- How is the iteration controlled? - Where should the control mechanism appear in the loop statement?
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?
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 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 is the difference between static binding and dynamic binding?
- static binding will select a function call based on the type of pointer at compile time It is similar to an array in C++ - dynamic binding will wait until runtime to select the version of the class of the object It is similar to a vector in C++. A little bit less efficient.
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 are lexical analysis design issues, program language design issues, concurrency design issues, and exception handling design issues...
....
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?
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 operands are evaluated right to left ?
12
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 operands are evaluated right to left?
12
Convert the BNF of Example 3.3 to EBNF.
<assign> → <id> = <expr> <id> → A | B | C <expr> → <expr> (+ | -) <expr> | (<expr>) | <id>
Compare the pointer and reference type variable in C++.
A C++ reference type variable is a constant pointer that is always implicitly dereferenced.
What is a binary semaphore? What is a counting semaphore?
A binary semaphore is a semaphore that requires only a binary-valued counter. A counting semaphore is a synchronization object that can have an arbitrarily large number of states.
What are the differences between an interpreter and a compiler? List the advantages of each one. // Would you run a program with a compiler or interpreter and why?
A compiler takes the source code of a program and converts it into machine code directly. This allows for the code to be run by the machine. A compiler usually runs much faster after the first time because you can run the pre-compiled code. A compiler also doesn't need the source code to function after it has been compiled. Use a compiler if you are going to export the program for other people who use it. An interpreter reads the source code line by line and executes the commands in order. Sometimes, the interpreter converts the source code into intermediate code so it can be executed quicker. Interpreters are usually quicker to debug/test.
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.
Give the differences between total correctness and partial correctness.
A distinction is made between total correctness, which additionally requires that the algorithm terminates. Partial correctness, which simply requires that if an answer is returned it will be correct.
What is a dynamic dispatch?
A dynamic dispatch is a kind of polymorphism provided bu the dynamic binding of messages to method definitions.
What is tail recursion? Why is it important to define functions that use recursion to specify repetition to be tail recursive?
A function is tail recursive if its recursive call is the last operation in the function. This means that the return value of the recursive call is the return value of the nonrecursive call to the function. It is important to specify repetition to be tail recursive because it is more efficient(increase the efficiency).
What is LISP?
A functional language.
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 the type of an F# heap-allocated mutatable variable?
A mutable heap-allocated variable is of type ref.
What is prefix operator?
A prefix operand means has some operators, which means they precede their operands.
What is one programming situation where multiple inheritance has a significant disadvantage over interfaces?
A situation when there are two classes derived from a common parent and those two derived class has one child.
What is the use of the evaluation environment table?
A table called the evaluation environment stores the names of all implicitly and explicitly declared identifiers in a program, along with their types. This is like a run-time symbol table.
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 is a user-defined iteration control?
A user defined iteration control is a type of looping structure that is primarily used for data structures. Instead of being controlled by a counter or boolean expression, it is controlled by the number of elements in a data structure. In order to achieve this the user-defined control uses a user-defined frunction called an iterator. This iterator is used to traverse through the data structure and retrieve the elements in whatever order the programmer defines. The for loop fo C based languages can simulate a user defined iteration statement because of it great flexibility. for (ptr=root; ptr==null; ptr=traverse(ptr)) { } Assuming that traverse is a runction that will set ptr to the next desired elment of a data structure, this for loop will begin with root and will continue going through the elements until ptr points to a null element. Many languages provide predefined iterators which are based on the data structure that they are meant to travers, such as Pearl. reset $list -> moves the iterator to the 1st element current($list) -> retrieves the current element of list next($list) -> moves the iterator to the next element in the data structure.
What is an uninstantiated variable?
A variable that has not been assigned a value.
What is the difference between a compiler warning and a compiler error?
A warning is a potential error. An error breaks the program. Warnings are better for readability.
Boolean data types are perhaps the simplest of all types. In which programming language were boolean data types introduced?
ALGOL 60
On what previous language was C's switch statement based?
ALGOL 68
What are the two methods used with Java Semaphore objects?
Acquired and release
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.
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.
What is the use of the Ada with clause?
Ada's with clause also called a context clause, allows for the utilization of packages. It provides visibility for defined names in external packages. It is like C++'s #include clause.
In what three common languages can monitors be implemented?
Ada, java, and C#.
What are the advantages and disadvantages of decimal data types?
Advantage: precisely storing decimal values. Disadvantages: 1. the range of values is restricted because no exponents are allowed. 2. Representation in memory is wasteful
What are advantages and disadvantages of implicit declarations?
Advantage: writeability. Disadvantages: reliability and readability.
__________ is the reason that the lexical analyzer and parser should be implemented separately.
All of the above: efficiency simplicity portability
A grammar is ____ if an only if it generates a sentential form that has two or more distinct parse trees
Ambiguous
What is an abstract method? What is an abstract class?
An abstract method is an implemented method which all of descendant class should have and it is included in Building. An abstract class is a class that includes at least one abstract method.
What is an access function for an array?
An access function for an array is formula calculating the address of any element.
When is an exception thrown or raised?
An exception is raised when its associated event occurs.
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.
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.
What are antecedents? Consequents?
Antecedents are right side of a clausal form proposition. Consequent is left side of a clausal form propositions.
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.
In which version were assertions added to Java?
Assertions were added to Java in version 1.4.
What associativity rules are used by APL?
Associativity rules are used by APL: all operators have equal precedence and all operators associate right to left.
Why is the destructor of C# is rarely used?
Because C# uses garbage collection for most of its heap objects.
What is one reason Java does not have friend functions or friend classes?
Because java has less need for explicit friend declarations.
Explain clearly why a race condition can create problems for a system.
Because two or more tasks are racing to use the shared resource and the behavior of the program depends on which task arrives first (and wins the race). The importance of competition synchronization should now be clear.
What are the advantages of data types?
Better readability / documentation. Error detection. Program Modularization
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 is a block?
Block is such a section of code.
What is boxing?
Boxing is primitive values in Java 5.0+ which is implicitly coerced when they are put in object context. This coercion converts the primitive value to an object of the wrapper class of the primitive value's type.
How are Java objects deallocated?
By implicitly calling a finalizemethod when the garbage collector is about to reclaim the storage occupied by the object.
What are arguments for and against four signed integer sizes in Java?
Bytes (1 byte), short(2 bytes), integer (4 bytes), long (8 bytes). As a result, depending on the domain of the variable required, data types are used.
Name two functional languages that support object-oriented programming.
C++ and Java
How are C++ heap-allocated objects deallocated?
C++ heap-allocated objects are deallocated using destructor.
Study and explain private and public modifiers in C++. How do those modifiers differ in C#?
C++ includes both classes and structs, which are nearly identical constructs. The only difference is that the default access modifier for class is private, whereas for structs it is public. C# also has structs, but they are very different from those of C++. In C#, structs are, in a sense, lightweight classes. They can have constructors, properties, methods, and data fields and can implement interfaces but do not support inheritance.
What is the fundamental difference between a C++ class and an Ada package?
C++ is have a few encapsulations. Ada packages are more generalize encapsulations that can define any number of types.
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
How are classes in Ruby made dynamic?
Classes in Ruby are dynamic in the sense that members can be added at any time. This is done by simply including additional class definitions that specify the new members.
What is coercion?
Coercion is when Lua performs automatic conversion of numbers to strings and vice versa where it is appropriate.
Define a Linker
Collects and combines all the different parts of the program then stores it in a executable file.
What type of synchronization occurs when two or more tasks must use some resource that cannot be used simultaneously?
Competition
A _______ takes programs, translates them into machine language and executes?
Compiler
Which produces faster program execution, a compiler or a pure interpreter?
Compiler produces faster program execution than pure interpreter.
What is Concurrent ML?
Concurrent ML is an extension to ML that includes a form of threads and a form of synchronous message passing to support concurrency.
What is a conjunction?
Conjunctions contain multiple terms that are separated by logical AND operations.
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.
Call semantics do all of the following except:
Create a database with the caller's address. WHAT IT DOES DO: save the execution status of the caller pass the parameters pass the return address to the called
What data types does Java support?
Data types that Java support are eight primitive data types (byte, short, int, long, float, double, boolean, char).
The lexical analyzer does what in all of the following types of applications except?
Define types, natural language processing, formal definition to compilers, attribute grammars, and decorates parse trees.
What organization was the most responsible for the early success of COBOL (in terms of extent of use)?
DoD was the organization that most responsible for the early success of COBOL (in terms of extent of use).
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.
What is short-circuit evaluation?
Evaluation in which the result is determined without evaluating all the operands and/or operators.
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.
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.
The error: Warning Implicit Declaration of Function // Why is it useful to have function prototypes (as in ANSI C)? She gives you a function and tells you it throws that warning and asks you why it throws that warning?
Example: when you implicitly declare the prototype function: int fac(int n); and then have the main() call int fac() the compiler knows the function will declare an int before the details of the function have been given to the program. Or if the prototype double sin(double x); is declared and is used in main with x being an int, the compiler will automatically convert x into an x when it is used for the sin function.
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.
A control statement provides the means of choosing between two or more paths of execution
False
Left factoring can solve all pairwise disjointness problems of grammar.
False
Most functional languages do not allow the user to create local scopes with let constructs.
False
True or False? Most functional languages do not allow the user to create local scopes with constructs.
False
True or false. Arcs are labeled with state names and the nodes are transitions in state diagrams.
False
Typeless language is not an actual term in Computer Science. MC question. DO NOT PICK THIS CHOICE
False
Typeless languages are languages you write in binary. MC question. DO NOT PICK THIS CHOICE
False
Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access?
Finding the correct activation record instance of a nonlocal variable using static links is relatively straightforward. When a reference is made to nonlocal variable, the activation record instance containing the variable can be found by searching the static chain until a static ancestor activation record instance is found that contains the variable.
If I have a main routine that sets x to be 5 and then I call a subroutine and set x equal 10 and then print x, what will print?
For Dynamic: 10 will be printed For Static: 5 will be printed
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.
Which version of Fortran was the first to have any sort of dynamic variables?
Fortran 90 was the first Fortran that have any sort of dynamic variables.
Under what environmental consideration was Fortran developed? Which is the first version of Fortran?
Fortran was developed under several environmental consideration: a. Computers had small memories and were slow and relatively unreliable b. The primary use of computers was for scientific computations C. There were no existing efficient and effective ways to program computers d. Because of the high cost of computers compared to the cost of programmes, speed of the generated object code was the primary goal of the first Fortran compilers First version of Fortran is Fortran 0.
What is a friend function? What is a friend class?
Friend function to allowed access to public, private, or protected data in that class. Friend class can access the "private" and "protected" members of the class in which it is declared as a friend.
Define functional side effect.
Functional side effect when a function changes a two-way parameter or a non-local variable.
What are the two parts of a compound term?
Functor and ordered list of parameters.
In the context of language support for concurrency, what is a guard?
Guard is a linguistic device that allows the guarded code to be executed only when a specified condition is true.
What is a heavyweight task? What is a lightweight task?
Heavy weight task executes in its own address space. Lightweight task all run in the same address space.
What are the forms of Horn clauses?
Horn clauses can be in only two forms : single atomic proposition on the left side or right side.
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.
If all data members of the variables are to be used at once then struct type variables are required, otherwise union type variables should be used.
How can you show a language's grammar is ambiguous?
If an expression/statement can be derived and found to have 2 or more distinct parse trees, it is an ambiguous language.
Explain the difference between Right Recursive and Left Recursive.
If the rule's left-hand side appears at the Beginning of its right-hand side, it is Left recursive. If its left-hand side appears at the End of its right-hand side, it is Right recursive.
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 previous activation?
If the variable is declared as static. Static modifier is a modifier that makes a variable history - sensitive.
What are the different types of programming languages?
Imperative, Functional, Logic, and Object-Oriented
Dynamic type binding is closely related to implicit heap dynamic variables. Explain this relationship.
Implicit heap dynamic variables are bound to a type at runtime when a value is assigned to a variable. Dynamic type binding is the binding of a type to a variable at runtime or changing the type of a variable during runtime. Implicit heap dynamic variables use dynamic type binding.
Define row major order and column major order.
In row major storage, a multidimensional array in linear memory is organized such that rows are stored one after the other. Column major order is a similar method of flattening arrays onto linear memory, but the columns are listed in sequence.
Explain how the dangling-pointer problem can be removed using the locks-and-keys approach.
In the locks-and-keys approach, pointer values are represented as ordered pairs (key, address), where the key is an integer value. Heap-dynamic variables are represented as the storage for the variable plus a header cell that stores an integer lock value. When a heap-dynamic variable is allocated, a lock value is created and placed both in the lock cell of the heap-dynamic variable and in the key cell of the pointer that is specified in the call to new.
The advantages of the two parts of the definition of abstract data type are improved readability, easier to manage and
Information hiding
What are the advantages of the two parts of the definition of abstract data type?
Information hiding, improved readability, and easier to manage.
Compare inheritance and nested classes in C++. Which of these supports an is-a relationship?
Inheritance is where one class (child class) inherits the members of another class (parent class). Nested class is a class declared entirely within the body of another class or interface. Inheritance does.
What is the advantage of inheritance?
Inheritance offers a solution to both the modification problem posed by abstract data type reuse and the program organization problem. If a new abstract data type can inherit the data and functionality of some existing type, and is also allowed to modify some of those entities and add new entities, reuse is greatly facilitated without requiring changes to the reused abstract data type.
What innovation of data structuring was introduced in ALGOL 68 but is often credited to Pascal?
Innovation of data structuring was introduced in ALGOL 68 but it is often credited to Pascal is user-defined data types.
What does the Java interrupt method do?
Interrupt becomes one way to communicate to a thread that it should stop.
Describe the pairwise disjointness test.
It is a test of non-left recursive grammar that indicates whether left recursion can be done. It requires the ability to compute a set based on the RHSs of a given nonterminal symbol in a grammar.
What is true about typeless languages?
It is faster and easier to code, but it is harder to check for errors when compiling. In reference to the allocations of memory for datatype, it will be the same because they are all being sorted the same way. They also must be dynamically bound.
Critically comment on the following statement: "Logic programs are nonprocedural".
It is true, because logical programs use lots of different processes based on its conditions. If a certain logical requirement is true, then a program will execute the corresponding process, instead of procedurally executing the statements.
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.
What does a syntax analyzer do?
It takes the tokens from the lexical analyzer and makes a parse tree.
What happens if the constructor is absent in Java and C++?
It will be made automatically by the built-up in.
What is a fully attributed parse tree?
It's a parse tree with all attribute values computed. Conceptually attribute values are computed after parse tree is constructed by compiler. It's not really the way it's done
On what are Python's list comprehensions based?
It's based on math sets and functions.
On what branch of mathematics is axiomatic semantics based?
It's based on mathematical logic to proving the correctness of computer programs. It is closely related to Hoare logic.
Why are C and C++ not strongly typed?
It's because C casts can override typing, C parameter type checking can be avoided, unions not type-checked.
What is the action of the Scheme function car?
It's returns the first number of a list or dotted pair, example: (car '(123 456 789 012)) is 123
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.
To what is a JSP document converted by a JSP processor?
JSP document converted by a JSP processor to a servlet.b
What important part of support for inheritance is missing in Java?
Java does not support the private and protected derivations of C++. One can surmise that the Java designers believed that subclasses should be subtypes, which they are not when private and protected derivations are supported. Thus, they did not include them.
What are the different options for object destruction in Java?
Java have garbage collector, although it still have some issues, the other alternatives would be to use the finalize method.
Who developed the Speedcoding system for the IBM 701?
John Backus developed the Speedcoding system for the IBM 701.
Define lexeme and token
Lexeme is the logical groupings that the lexical analyzer collects characters into and Token is the internal codes for categories of these groupings.
What are the primary tasks of a lexical analyzer?
Lexical analysis process includes skipping comments and white space outside lexemes, as they are not relevant to the meaning of the program. Also lexical analyzer inserts lexemes for user-defined names into the symbol table, which is used by later phases of the compiler. Finally, lexical analysis detect syntactic errors in tokens, such as ill-formed floating-point literals, and report such errors to the user. *It gathers the characters of the source program into lexical units. Those lexical units are converted to tokens.*
Select the true statements about lexical analyzers
Lexical analyzers extract lexemes from a given input string and produce the corresponding tokens. Lexical analyzers detect syntactic errors in tokens, such as ill-formed floating-point literals, and report such errors to the user.
Describe how a logic programming language is different from a general programming language.
Logical programming language uses a form of symbolic logic, the syntax of logic programming logic is remarkably different from that of the imperative and functional languages.
What is message protocol?
Message protocol is the entire collection of methods of an object.
What is a mixed-mode expression?
Mixed-mode expression is one that has operands of different types.
What mechanism did early programming languages provide to detect or attempt to deal with errors?
Most of computer hardware system are capable of detecting certain run-time error conditions, such as floating-point overflow. Early programming languages were designed and implemented in such a way that the user program could neither detect nor attempt to deal with such errors. In these languages, the occurrence of such an error simply causes the program to be terminated and control to be transferred to the operating system. The typical operating system reaction to a run-time error is to display a diagnostic message, which may be meaningful and therefore useful, or highly cryptic. After displaying the message, the program is terminated.
What is multicast delegate?
Multicast delegate is the all of the methods stored in a delegate instance are called in the order in which they were placed in the instance.
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.
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.
For what new line of computers was PL/I designed?
New line of computers was PL/I designed for IBM system/360.
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.
Does a functional language have states?
No. So you can have a if or a for statement.
Does Python have data types?
No. That's why you can have different types in an array like words and numbers.
If they are not terminal, they are called:
Non-terminal // non-determinant
What is a nonassociative operator?
Nonassociative operator is operator that has no defined behavior when used in sequence in an expression.
What is the big O complexity of most commercial compilers because of restrictions on the grammars?
O(n)
What is the big O complexity of parsing for any unambiguous grammar?
O(n^3)
Modify the following grammar to add a unary minus operator.
On the last line (assignment) change it to <factor> -> (<expr>) | <id> *| - <id>*
Where are the determinants on the EBNF rule? // Where are the terminals in the EBNF rule?
On the right side.
Give one capability that Java 5.0 provides which C# 2005 does not.
One capability that Java 5.0 provides that C# 2005 does not is wildcard classes
Explain one advantage of inheritance.
One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common code among several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual super class. This also tends to result in a better organization of code and smaller, simpler compilation units.
What mixed-mode assignments are allowed in Java?
Only widening assignment coercions are done.
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.
Define ordinal, enumeration, and subrange types.
Ordinal: easy to put into 1-1 assoc with pos integers. Enumeration: fixed (small) set of values. Subrange: a contiguous subsequence of ordinal type.
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.
Compare and contrast PHP's parameter passing with that of C#.
PHP's parameter passing is similar to that of C#, except that either the actual parameter or the formal parameter can specify pass-by-reference. Passby- reference is specified by preceding one or both of the parameters with an ampersand.
PL/I was designed to replace what two languages?
PL/I was designed to replace Fortran and COBOL.
<INDEX> -> a B | b B | a C
Pairwise Disjointedness
What doesn Plankul mean?
Plankul means program calculus.
In what year was Plankul designed? In what year was that design published?
Plankul was designed in 1945; That design was published in 1972.
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.
Point 1: a 1 b 2 c 2 d 2 Point 2: a 1 b 2 c 3 d 3 e 3 Point 3: same as Point 1 Point 4: a 1 b 1 c 1
What is a preprocessor?
Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins. It is used mainly in hybrid languages like Java.
What is the difference between private and limited private types in Ada?
Private types in Ada, it has built-in operations for assignment and comparisons for equality and inequality. Limited private types in Ada, are described in the private section of a package specification, as are non pointer private types. Limited private types are declared to be limited private in the visible part of the package specification.
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).
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 Prolog called a nonprocedural language?
Prolog known as non-procedural language because prolog compiler is told what programmers want to do, not how to do it.
What are two modes in which a proposition can be stated?
Propositions can be started 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.
Define a Loader
Puts the program in memory once the program is run by the user.
What is an example of a typeless language?
Python
Name two typeless languages.
Python and R
What are some of the arguments, pro and con, for Python's use of indentation to specify compound statements in control statements?
Python needs proper indentations in order for the code to work. One of reasons for indentation for any programming language - especially Python is that is makes the code easier to read. That also extends to reading other Python programs since it introduces a standard. One of the cons is that Python does not use curly brackets for the indentations which can make modules harder to contain.
What kind of machines often use registers to pass parameters?
RISC.
Define a Scope
Range of statements over which a variable is visible.
What does the abbreviation REPL stand for?
Read-evaluate-print-loop.
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.
Define Objects
Representations of data abstractions in programming languages.
How are iterators implemented in Ruby?
Ruby predefines several iterator methods, such as times and upto for counter-controlled loops, and each for simple iterations of arrays and hashes.
Convert the following EBNF to BNF: S → A{bA} A → a[b]A
S → A | A B B → b A | b A B A → a A | a b A
What are some examples of purely interpreted languages?
SNOBOL, Lisp, and APL
What is the work of a scheduler?
Scheduler manages the sharing of processors among the tasks.
Types of Synchronization
Semaphores, spinlocks, and barriers.
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.
Why do we implement the lexical analyzer and the parser separately?
Simplicity, portability, and efficiency.
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.
What are the drawbacks of user-defined generic classes in Java 5.0?
Some drawbacks of user-defined generic classes in Java 5.0 are: for one thing, they cannot store primitives. Second, the elements cannot be indexed. Elements must be added to user-defined generic collections with the add method.
What is a state transition diagram?
State diagram is a directed graph whose nodes are labeled with state names.
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.
Define strongly typed.
Strongly typed when every type error is always detected(compile or run time).
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.
What is a task descriptor?
Task descriptor is a data structure that stores all of the relevant information about the execution state of a task.
What did Bohm and Jocopini prove about flowcharts?
The Bohm-Jacopini proof describes how to construct a structured flow chart from an arbitrary chart, using the bits in an extra integer variable to keep track of information that the original program represents by the program location. This construction was based on Bohm's programming language P′′. The Bohm-Jacopini proof did not settle the question of whether to adopt structured programming for software development, partly because the construction was more likely to obscure a program than to improve it. On the contrary, it signalled the beginning of the debate. Edsger Dijkstra's famous letter, "Go To Statement Considered Harmful," followed in 1968. Subsequent proofs of the theorem addressed practical shortcomings of the Bohm-Jacopini proof with constructions that maintained or improved the clarity of the original program.
What does the Java sleep method do?
The Java sleep method blocks the the thread.
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.
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 concurrent program units of Ada called?
The concurrent program units of Ada called tasks.
What is ad hoc binding?
The environment of the call statement that passed the subprogram as an actual parameter is called ad hoc binding.
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 are initializers in Objective-C?
The initializers in Objective-C are constructors.
What are the inputs to an XSLT processor?
The inputs to an XSLT processor are an XML data document and an XSLT document (which is also in the form of an XML document).
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.
Discuss the disadvantages of dynamic type binding.
The main disadvantage of dynamic type binding is reliability since the compiler cannot provide error detection. In addition to that, cost is negatively impacted during execution.
Busy waiting is a method whereby a task waits for a given event by continuously checking for that event to occur. What is the main problem with this approach?
The main problem would be the CPU resources that area allocated to the waiting for the task, if it were to be suspended, the CPU can then be used for other purposes.
Outline the major developments in ALGOL 60.
The major developments in ALGOL 60: a. The concept of block structure was introduced. This allowed the programmer to localize parts of programs by introducing new data environments, or scopes. b. Two different means of passing parameters to subprograms were allowed: pass by value and pass by name. c. Procedures were allowed to be recursive. The ALGOL58 description was unclear on this issue. Note that although this recursion was new for the imperative languages, LISP had already provided recursive functions in 1959. d. Stack-dynamic arrays were allowed. A stack-dynamic array is one for which the subscript range or ranges are specified by variables, so that the size of the array is set at the time storage is allocated to the array, which happens when the declaration is reached during execution.
What is the message protocol of an object?
The message protocol of an objects are all the methods.
How is the functional operator pipeline (|>) used in F#?
The pipeline operator is a binary operator that sends the value of its left operand, which is an expression, t the last parameter of the function call, which is the right operand. It is used to chain together function calls while following the data being processed to each call.
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.
What is the root class in Objective-C?
The predefined root class named NS Object.
LISP began as a pure functional language but gradually acquired more and more imperative features. Why?
The reason was to increase their execution efficiency.
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 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).
What is the structure of an associative array?
The structure of an associative array is unordered collection of elements indexed by an equal number of keys.
What does it mean for a subprogram to be active?
The subprogram has been called and is executing, but has not yet terminated. It can have decorations for variables to hide variables with the same name of previous subprogram activities. Some variables with active subprograms can be hidden from the referencing.
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 is dynamic programming?
There are 2 types. Top down which uses memoization so it keeps up with values and does not need to calculate a solution again. Ex: Fibonacci is very quick with dynamic programming. The second type is bottom up with optimal substructure which is harder.
Are there any nonprocedural programming languages other than Prolog?
There are any nonprocedural programming languages other than Prolog: Lisp, Scheme, ML, Smalltalk, and Miranda.
What mixed-mode assignments are allowed in Ada?
There is no assignment coercion.
Speedcoding was invented to overcome two significant shortcomings of the computer hardware of the early 1950s. What were they?
They are Non-connotative names and absolute addressing.
What advantage do monitors have over semaphores?
This solution can provide competition synchronization without semaphores by transferring responsibility for synchronization to the run-time system.
"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.
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.
Describe three situations where a combined counting and logical looping statement is needed
Three situations in which a combined counting and logical control loops are: a. A list of values is to be added to a SUM, but the loop is to be exited if SUM exceeds some prescribed value. b. A list of values is to be read into an array, where the reading is to terminate when either a prescribed number of values have been read or some special value is found in the list. c. The values stored in a linked list are to be moved to an array, where values are to be moved until the end of the linked list is found or the array is filled, whichever comes first.
Write a comparative analysis of the throw clause and throws clause of Java.
Throw statement is used to retrieve the name of the class with the actual parameter, while the throws clause of Java specifies that exception class or any of its descendant exception classes can be thrown but no handled by the method.
What is the purpose of an Objective-C protocol?
To achievable either as an abstract multiply inherited base class in C++, or as an "interface".
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.
What are the 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.
What does the Java yield method do?
To make the thread is put immediately in the task-ready queue. Making it ready to run.
What is the purpose of an Objective-C category?
To permit the programmer to add methods to an existing class without the need to recompile that class or even have access to its source code.
Define a Compiler
Translates high-level languages to assembly language
A function is tail recursive if the last operation in the function is a recursive call to itself.
True
APL, SNOBOL, and LISP were purely interpreted languages.
True
True or false? The top symbol on the parse stack is always a state symbol that represents all of the information in the parse stack that is relevant to the parsing process.
True
What is the name of all C++ exception handlers?
Try clause
What are two common problems with pointers?
Two common problems with pointers are dangling pointer and lost heap-dynamic variable.
What two professional organizations together designed ALGOL 60?
Two professional organizations together design ALGOL 60 are ACM and GAMM.
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.
What is type inferencing, as used in ML?
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction.
In what language is most of UNIX written?
UNIX operating system is written almost entirely in C (ISO, 1999).
Define union, free union, and discriminated union.
Union is a type that may store different type values at different times during program execution. Free union is union that constructs in which there is no language support for type checking. Discriminated union is type checking of unions require that each union include a type indicator.
What are the pros and cons of using unique closing reserved words on compound statements?
Unique closing keywords on compound statements have the advantage of readability and the disadvantage of complicating the language by increasing the number of keywords.
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.
Make an educated guess as to the most common syntax error in C programs.
What make the most common syntax error in C programs: a. Lack of a semicolon after the command is finished. b. Lack of one bracket or both brackets or doesn't match brackets. c. Function prototype doesn't match. d. Variables are undeclared.
What is a deadlock and what causes it to happen?
When a process cannot continue as it requires resources that are being used that will never be freed up. OR THE OFFICIAL DEF: Permanent blocking of a set of processes that either compete for system resources or communicate with each other There are 4 necessary conditions for a deadlock to occur: mutual exclusion, non-preemptive, circular wait, and hold and weight 1.Exclusive access (mutual exclusion) 2.Wait while holding (hold-and-wait) 3.No preemption 4.Circular wait
Compare the way Smalltalk provides dynamic binding with that of C++.
While Smalltalk's dynamic type binding provides somewhat more programming flexibility than the hybrid C++ language, it is far less efficient in the execution.
What is the use of the Ada with clause?
With clause makes the names defined in external packages visible.
What does the following Scheme function do? (define ( y s lis) (cond (( null? lis) ' () ) ((equal? s (car lis)) lis) (else (y s (cdr lis))) ))
Y returns the given list with leading elements removed up to but not including the first occurrence of the first given paramete
Are the unions of Ada always type checked?
Yes, unconstrained unions run-time type checked.
Are they any predefined exceptions in Ada?
Yes.
Does dynamic programming speed up performance?
Yes.
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void main() { i nt 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 = 12 b. operands are evaluated right to left = 7
a. operands are evaluated left to right = 12 b. operands are evaluated right to left = 7
What are the practical uses of data types?
all of these are practical uses of data types: error detection assistance provided program modularization documentation
There are two distinct categories of subprograms - procedures and functions. Which of the following statements are true about subprograms?
all of these statements are true about subprograms: functions return values and procedures do not subprograms are collections of statements that define parameterized computations both can be viewed as approaches to extending the language
A subprogram is active
all of these statements are true: if its execution has begun but not yet terminated and can have declarations for variables that hide variables with the same names in previous subprogram activations and some variables in active subprograms can be hidden from the referencing environment
The problem with case sensitive names is
all of these statements are true: more an issue of writability than readability it requires the programmer to remember specific case usage its enforced by the compiler
Grammar that generates a sentential form for which there are two or more distinct parse trees is said to be:
ambiguous
What is a device that is used to describe more of the structure of a programming language than can be described with a context-free grammar.
attribute grammar
All Java methods are defined in a ______
class
What type of implementation method takes programs, translates them into machine language, then executes them directly on the computer?
compiler
The initializers in Objective-C are ________
constructors
The two fundamental kinds of abstraction in contemporary programming languages are process abstraction and ___________________.
data abstraction
It's helpful, both logically and concretely, to think of variables in terms of
descriptors
A _____________ _____________ can access the "private" and "protected" members of the class in which it is declared as a friend.
friend | class
A _______ _________ is allowed access to protected data in that class.
friend | function
Every derivation with an unambiguous grammar:
has a unique parse tree
Java classes allocated from the ________ and accessed through reference variables.
heap
Python uses indentation to specify compound statements. Give an example in support of this statement.
if x > y : x = y print "case 1? All statements equally indented are included in the compound statement.
A named constant
is a variable that is bound to a value only once
Which package in java contains all the event related classes.
java.awt.event package.
When a grammar rule has its LHS appearing at the beginning of its RHS, the rule is said to be
left recursive
The lexical analyzer collects characters into logical groupings and assigns internal codes to the groupings according to their structure. These logical groupings are named and and the internal codes for categories of these groupings are named
lexemes and tokens
What are the six things that characterize a variable?
name, scope, value, address, type, lifetime
In general, a c++ _____________ is a container for a set of identifiers and allows the disambiguation of homonym identifiers residing in different containers. The purpose is to help programs manage the problem of global container.
namespace
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.
Attribute grammars have been used in all of the following types of applications except:
to show that a loop invariant is true prior to the first iteration
Most computers now use a special type of notation to store negative numbers, that is known as
twos complement
How does a computer store negative number?
twos compliment
Assume the following JavaScript program was interpreted using dynamic-scoping rules. What value of x is displayed in function sub1? var x; function sub1() { document.write("x = " + x + "<br />"); } function sub2() { var x; x = 10; sub1(); } x = 5; sub2();
x = 10
Assume the following JavaScript program was interpreted using static-scoping rules. What value of x is displayed in function sub1? var x; function sub1() { document.write("x = " + x + "<br />"); } function sub2() { var x; x = 10; sub1(); } x = 5; sub2();
x = 5