Exam Flashcards

1
Q

What is a compiler?

A
  • A computer program translates one language to another (Source Program to Target Program).
  • A compiler is a complex program From 10,000 to 1,000,000 lines of codes.
  • Compilers are used in many forms of computing (Command interpreters, interface programs).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why Compiler ?

A

Writing machine language-numeric codes is time consuming and tedious.

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

What are the defects of assembly language ?

A

– Not easy to write.

– Difficult to read and understand.

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

What is an Interpreter ?

A
  • Execute the source program immediately rather than generating object code.
  • Speed of execution is slower than compiled code by a factor of 10 or more.
  • Share many of their operations with compilers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some examples of interpreters ?

A

BASIC, LISP, used often in educational or development situations.

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

What is an Assemblers ?

A
  • A translator for the assembly language of a particular computer.
  • Assembly language is a symbolic form of one machine language.
  • A compiler may generate assembly language as its target language and an assembler finished the translation into object code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Linker ?

A
  • Collect separate object files into a directly executable file.
  • Connect an object program to the code for standard library functions and to resource supplied by OS.
  • Becoming one of the principle activities of a compiler, depends on OS and processor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Loader ?

A
  • Resolve all re-locatable address relative to a given base.
  • Make executable code more flexible.
  • Often as part of the operating environment, rarely as an actual separate program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Preprocessor ?

A
  • Delete comments, include other files, and perform macro substitutions.
  • Required by a language (as in C) or can be later add-ons that provide additional facilities.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an Editor ?

A
  • Compiler have been bundled together with editor and other programs into an interactive development environment (IDE).
  • Oriented toward the format or structure of the programming language, called structure based.
  • May include some operations of a compiler, informing some errors.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a debugger ?

A
  • Used to determine execution error in a compiled program.
  • Keep tracks of most or all of the source code information.
  • Halt execution at pre-specified locations called breakpoints.
  • Must be supplied with appropriate symbolic information by the compiler.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a profile ?

A
  • Collect statistics on the behavior of an object program during execution.
    – Called Times for each procedures.
    – Percentage of execution time Used to improve the execution speed of the program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the six phases of a compiler ?

A
– Scanner.
– Parser.
– Semantic Analyzer.
– Source code optimizer.
– Code generator.
– Target Code Optimizer.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the three auxiliary components of a compiler ?

A

– Literal table.
– Symbol table.
– Error Handler.

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

What does a scanner do ?

A
  • Lexical analysis: it collects sequences of characters into meaningful units called tokens.
  • Other operations: it may enter literals into the literal table.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does a parser do ?

A
  • Syntax analysis: it determines the structure of the program.
  • The results of syntax analysis are a parse tree or a syntax tree.
17
Q

What does a semantic analyzer do ?

A
  • The semantics of a program are its “meaning”, as opposed to its syntax, or structure, that determines some of its running time behaviors prior to execution.
  • Static semantics: declarations and type checking.
  • Attributes: The extra pieces of information computed by semantic analyzer.
18
Q

What does a source code optimizer do ?

A
  • The earliest point of most optimization steps is just after semantic analysis.
  • The code improvement depends only on the source code, and as a separate phase.
  • Individual compilers exhibit a wide variation in optimization kinds as well as placement.
    – Constant folding performed directly on annotated tree.
    – Using intermediate code: three-address code, p-code.
19
Q

What does a code generator do ?

A
  • It takes the intermediate code or IR and generates code for target machine.
  • The properties of the target machine become the major factor:
    – Using instructions and representation of data.
    – Code sequence in a hypothetical assembly language.
20
Q

What does a target code optimizer do ?

A
  • It improves the target code generated by the code generator:
    – Address modes choosing.
    – Instructions replacing.
    – As well as redundant eliminating.
21
Q

What are tokens ?

A

– A scanner collects characters into a token, as a value of an enumerated data type for tokens.
– May also preserve the string of characters or other derived information, such as name of identifier, value of a number token.
– A single global variable or an array of tokens.

22
Q

What are syntax trees ?

A

– A standard pointer-based structure generated by parser.
– Each node represents information collect by parser or later, which maybe dynamically allocated or stored in symbol table.
– The node requires different attributes depending on kind of language structure, which may be represented as variable record.

23
Q

What is a symbol table ?

A

– Keeps information associated with identifiers: function, variable, constants, and data types.
– Interacts with almost every phase of compiler.
– Access operation need to be constant-time.
– One or several hash tables are often used.

24
Q

What is a lateral table ?

A

– Stores constants and strings, reducing size of program.

– Quick insertion and lookup are essential.

25
Q

What are the types of normal forms ?

A
  • Chomsky Normal Form (CNF).

- Greibach Normal Form (GNF).

26
Q

What are the restriction for normal form ?

A
  • non recursive start symbol.
  • elimination of lambda rules.
  • elimination of chain rules.
  • useless symbols.
27
Q

describe chomsky normal form

A
  • all the productions must derive either two non-terminals or a single terminal.
  • CNF restricts the number of symbols on the right side of a production to be two.
  • The two symbols must be non-terminals or a single
    terminal.
  • A context free grammar is said to be in chomsky normal form (CNF) if all its productions are of the form A → BC or A → a
    where A, B, C are non-terminals and a is a terminal.
28
Q

Describe greibach normal form

A

A context free grammar G= (V,Σ,P,S) is in greidbach normal form if each rule has one of the following forms:

  • A → aA1A2…..An
  • A → a
  • S → λ