Midterm (GPT) Flashcards

1
Q

What is systems software?

A

It is a type of software that manages and operates computer hardware.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a compiler? An interpreter? What is the difference?

A

A compiler translates high-level code into machine code, while an interpreter executes high-level code directly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an assembler?

A

It is a type of software that converts assembly language into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does a linker do? What does a loader do?

A

A linker combines object files into an executable file, while a loader loads an executable file into memory for execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does a compiler do (overall)?

A

It translates high-level code into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What role does a VM play in systems software?

A

A VM provides a layer of abstraction between hardware and software, allowing software to run on different hardware architectures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an object file? What is its format?

A

An object file contains compiled code and data in a format that can be linked to create an executable file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the ISA?

A

It is the instruction set architecture that defines the set of instructions that a processor can execute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When does the program counter get incremented in a VM’s cycle?

A

The program counter is incremented after each instruction is executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does a jump instruction do in terms of how it affects the PC?

A

A jump instruction changes the value of the program counter to a new address, causing the VM to execute instructions at that address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the details (e.g., opcodes) for the Tiny VM?

A

Not specified in the text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can one tell if an ISA has enough instructions?

A

It depends on the needs of the software that will be executed on the processor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why does an ISA need a HLT (halt) instruction?

A

It provides a way for a program to exit cleanly and return control to the operating system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens if there is no halt instruction in a program?

A

The program may continue to execute indefinitely or crash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How would an if-then-else statement in a high-level language get translated into machine code (in terms of jump instructions)?

A

It would be translated into conditional jump instructions based on the condition being tested.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would a while loop be translated into machine instructions (in terms of what jump instructions and needed)?

A

It would be translated into a conditional jump instruction at the end of the loop, which jumps back to the beginning of the loop if the condition is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the memory hierarchy? Why is it important?

A

It is the hierarchy of different types of memory, such as cache, RAM, and disk, with faster and smaller memory at the top and slower and larger memory at the bottom. It is important for optimizing the performance and efficiency of computer systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the advantages of assembly language over machine code?

A

Assembly language is easier to read and write than machine code. Assembly language allows for the use of symbolic labels, making it easier to understand what specific instructions do. Assembly language can also use comments to help clarify the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Why are subroutines important?

A

Subroutines allow for code reuse and can make programs more efficient by reducing the amount of duplicated code. Subroutines also help to make code more modular and easier to understand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What capabilities does a programming language need from a VM to support subroutines?

A

A programming language needs the ability to define and call subroutines, as well as the ability to pass arguments to and return values from subroutines. The VM must also provide a way to manage the memory and stack for each subroutine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What features in a VM help support subroutines?

A

A VM needs to support a stack to store information for each subroutine call, as well as a way to store and retrieve values from memory. The VM should also support a call instruction and a return instruction to jump to and from subroutines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is static scoping? Why is it useful?

A

Static scoping is a way of determining the scope of a variable at compile time. It is useful because it allows a programmer to reason about the behavior of their program before it is executed and to prevent bugs caused by name clashes or incorrect variable scoping.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is dynamic scoping?

A

Dynamic scoping is a way of determining the scope of a variable at runtime, based on the current execution context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

When is dynamic scoping useful?

A

Dynamic scoping is useful when a program needs to access variables that are not in its immediate scope, but in a parent or ancestor scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the difference between a static property and a dynamic property (in general terms)?

A

A static property is one that is determined at compile time and does not change during program execution. A dynamic property is one that is determined at runtime and can change during program execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is block structure in a programming language?

A

Block structure is a way of organizing code into blocks, which can have their own scopes and variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What are the advantages of block structure?

A

Block structure allows for more modular and organized code. It also helps prevent naming conflicts by limiting the scope of variables to their specific blocks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Why should a language support recursion?

A

Recursion is a powerful programming technique that allows functions or procedures to call themselves. It is useful for solving problems that have a recursive nature, such as tree traversal or searching algorithms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Why is it useful to have recursion to write a context-free parser?

A

Recursion is useful for parsing context-free grammars because it allows the parser to handle nested constructs without having to explicitly define each possible combination of constructs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What data structure in a VM or computer is necessary for supporting recursive procedures?

A

A stack is necessary for supporting recursive procedures because it allows the program to keep track of the current execution context and to return to previous contexts when a function or procedure call is completed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is an AR?

A

An AR (Activation Record) is a data structure used by the VM to store information about a procedure or function call, including the return address, local variables, and arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What information is stored in an AR?

A

An AR typically stores the return address, local variables, arguments, and any other necessary information for a specific function or procedure call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

How is an AR (and the information stored in it) used to implement procedure calls? Returns from procedures?

A

The activation record (AR) contains all the necessary information to implement procedure calls and returns from procedures. The AR is pushed onto the stack when a procedure is called and popped off when the procedure returns.

34
Q

How should a VM (or compiler) address local variables (that are inside procedures)?

A

A VM or compiler can address local variables inside procedures by using a stack-based approach or by using a register-based approach.

35
Q

What information is needed to address local variables in surrounding scopes?

A

To address local variables in surrounding scopes, a VM or compiler needs to know the level of nesting of the scopes and the static links of the procedures.

36
Q

What is a static link and how is it used to address local variables?

A

A static link is a pointer to the activation record of the nearest enclosing scope. It is used to access local variables in surrounding scopes.

37
Q

What is a lexical address? How is it used to address local variables?

A

A lexical address is a combination of a static link and an offset that points to a specific local variable. It is used to address local variables in surrounding scopes.

38
Q

How can a compiler determine which static link to pass to a procedure in a call instruction?

A

The compiler can determine which static link to pass to a procedure in a call instruction by analyzing the static nesting depth of the procedure being called and the procedure that is making the call.

39
Q

What are the main jobs of a compiler?

A

The main jobs of a compiler are to analyze the source code, generate intermediate code, optimize the intermediate code, and generate machine code.

40
Q

What are the main goals of a compiler?

A

The main goals of a compiler are to produce correct and efficient machine code, while also providing useful error messages and diagnostics.

41
Q

What is done in the “front end” of a compiler?

A

The front end of a compiler is responsible for analyzing the source code, performing lexical analysis, parsing, semantic analysis, and generating intermediate code.

42
Q

What is done in the “back end” of a compiler?

A

The back end of a compiler is responsible for generating machine code from the intermediate code, performing optimization, and generating object code or executable code.

43
Q

What are the advantages of a compiler over an interpreter?

A

The advantages of a compiler over an interpreter are faster execution, better optimization, and the ability to produce standalone executables that do not require an interpreter.

44
Q

What are the advantages of an interpreter over a compiler?

A

The advantages of an interpreter over a compiler are faster development time, the ability to provide better error messages, and the ability to execute code on multiple platforms without recompilation.

45
Q

Is it possible to combine a compiler and an interpreter?

A

Yes, it is possible to combine a compiler and an interpreter in a hybrid approach called a just-in-time (JIT) compiler. The JIT compiler compiles parts of the code on the fly and executes them immediately using an interpreter for the rest of the code.

46
Q

What is a token? How are tokens used in a compiler?

A

A token is a sequence of characters that represent a unit of meaning in a program. Tokens are used in a compiler to analyze the program’s syntax and generate a parse tree.

47
Q

What information is stored (or remembered) for each token?

A

Each token is associated with a token type and additional information, such as its lexeme (the sequence of characters it represents) and its position in the source code.

48
Q

What is a reserved word? What role do they play?

A

A reserved word is a word that has a predefined meaning in a programming language and cannot be used as an identifier. Reserved words play a critical role in parsing and syntax analysis.

49
Q

What is the difference between reserved words and key words?

A

Reserved words and key words are often used interchangeably, but some languages make a distinction. In such languages, reserved words have a predefined meaning and cannot be used as identifiers, while key words are words that are used as part of the language’s syntax but can also be used as identifiers.

50
Q

What are the advantages and disadvantages of using token objects over global variables holding the same information?

A

Using token objects makes it easier to pass token information between compiler phases and to store additional information about the token. However, this approach can also be more memory-intensive and slower than using global variables.

51
Q

What is a regular expression?

A

A regular expression is a pattern that defines a set of strings. Regular expressions are commonly used in lexical analysis to recognize and match tokens.

52
Q

How are comments and whitespace handled in a lexical analyzer?

A

Comments and whitespace are typically ignored by a lexical analyzer. They are used to improve the readability of the source code and do not affect the meaning of the program.

53
Q

How is a language defined using a grammar?

A

A grammar specifies the syntax of a language.

54
Q

What is the relationship between a language and a grammar?

A

A grammar defines the syntax of a language.

55
Q

What kind of grammar is typically used for lexical analysis?

A

Regular grammars are typically used for lexical analysis.

56
Q

What kind of grammar is typically used for parsing?

A

Context-free grammars are typically used for parsing.

57
Q

What is a grammar?

A

A grammar is a set of rules for generating valid sentences in a language.

58
Q

What is BNF notation?

A

BNF (Backus-Naur Form) is a notation used to define a context-free grammar.

59
Q

What does `::=’ mean in BNF notation?

A

`::=’ means “is defined as” in BNF notation.

60
Q

What does `

A

’ mean in BNF notation?

61
Q

How does one indicate 0-or-more repetitions of a symbol in EBNF notation?

A

One can indicate 0-or-more repetitions of a symbol by placing it in curly braces in EBNF notation.

62
Q

How are nonterminal symbols written in BNF notation?

A

Nonterminal symbols are written in lowercase in BNF notation.

63
Q

How are terminal symbols written in BNF notation?

A

Terminal symbols are written in uppercase in BNF notation.

64
Q

Do BNF grammars allow recursion in their rules?

A

Yes, BNF grammars allow recursion in their rules.

65
Q

How can a grammar be used to recognize legal programs?

A

A grammar can be used to check if a program follows the syntax rules of the language.

66
Q

How can a grammar be used to generate programs?

A

A grammar can be used to generate legal programs in the language.

67
Q

What does it mean when a compiler says it was “expecting” a certain kind of symbol?

A

It means that the compiler encountered a token that it did not expect based on the syntax rules of the language.

68
Q

In a parser, what causes an error message that says that the parser was expecting a certain kind of symbol?

A

The parser was unable to match the next token in the input with any of the rules in the grammar.

69
Q

What is an AST?

A

An AST (Abstract Syntax Tree) is a tree-like data structure that represents the structure of a program’s syntax while abstracting away details that are irrelevant to its meaning.

70
Q

What role does an AST play in a compiler?

A

An AST is used by a compiler to translate a program into machine code.

71
Q

How does an AST differ from a parse tree?

A

A parse tree contains all the syntactic details of a program, while an AST omits redundant details and focuses on the program’s meaning.

72
Q

What is a symbol table?

A

A data structure used by compilers to store information about the variables, functions, and other identifiers in a program.

73
Q

What role does the symbol table play in a compiler?

A

The symbol table plays a crucial role in a compiler as it is used to keep track of the names and properties of the various symbols used in the program.

74
Q

What kind of information should be remembered for each declaration? Why?

A

For each declaration, the symbol table should remember the name of the symbol, its data type, its scope, and its location in memory. This information is needed by the compiler for various tasks, such as type checking, code generation, and optimization.

75
Q

What is an attribute? What kind of information is stored in attributes?

A

An attribute is a property or characteristic associated with a symbol in a symbol table. Attributes can include information such as the symbol’s data type, its scope, its location in memory, and its value (if it is a constant).

76
Q

What kind of errors are caught in declaration checking? What is an example of each kind in PL/0?

A

Declaration checking catches errors such as redeclaration of a symbol, undeclared symbols, and type mismatches. An example of a redeclaration error in PL/0 is when a variable is declared twice in the same block.

77
Q

What is a scope?

A

A scope is a region of the program where a symbol is visible and can be referenced by its name.

78
Q

What is the scope of a declaration in C?

A

In C, the scope of a declaration depends on where it is made. A variable declared inside a function has local scope and is only visible within that function. A variable declared outside of any function has global scope and is visible throughout the entire program.

79
Q

What is a “forward declaration”? How are they used in C?

A

A forward declaration is a declaration of a variable, function, or data type that is made before it is defined. Forward declarations are used in C to resolve circular dependencies between functions or to allow a function to use a data type before it is fully defined.

80
Q

Does each scope have its own symbol table?

A

Yes, each scope has its own symbol table. This allows the compiler to keep track of the symbols that are visible and accessible within each scope.