GoConqr has a new look! Let us know what you think.

Flashcards

Compilers Lectures 1-6 Questions (not thorough)

Alexandros Parpas English 17 cards

What is the difference between compilers and interpreters?

Cards in this deck (17)

  1. 1Give examples of some kind of checks that semantic analysis does.All identifiers declared before use?
    I Are all types correctly declared?
    I Do the inheritance relationships make sense?
    Are classes and variables defined only once?
    Methods defined only once?
    Are private methods and members only used within the defining class?
    Stupid operations like 3 ∗ true or ”hello”/7?.
  2. 2What are types?Types are a rough classification of programs that rule out certain errors. In languages such as Java, programs are annotated with types. (weak form of two version programming).
    In other words, the programer specifies twice what the program should do, once by the actual code, and a second time through the types. For example, to values of type string, we can apply operations such as println, but we cannot multiply two strings.
  3. 3What are the main differences between type checking and type inference?In type checking, we verify that the programmer written type annotations are consistent with the program code.
    In type-inference we analyse the program code to see if it is possible to find types that we could assign to a program to make it type-check.
  4. 4What is a compiler?A compiler is a program that translates programs from one programming language to programs in another programming language. That translation preserves meaning.
    Typically, the input language is more high-level than the output language.
  5. 5When do all the compiler phases happen?In the past, they all happened at compile time. Now, some happen at run-time in JIT (Just in time) compilers. This has profound influences on choice of algorithms and performance.
  6. 6Explain briefly what is lexical analysis and parsingLexical analysis is where the input string is converted into a list of tokens.
    Parsing is where the AST is constructed from a token list.
  7. 7Why is lexical analysis useful?Saves memory (not particularly relevant now, but very
    important in the past).
    Abstracts from irrelevant detail (e.g. syntax of keywords,
    whitespace).
    Makes the next phase (parsing) much easier.
    (Advanced: makes grammar defining program syntax
    easier.)
  8. 8Explain briefly the intermediate code generation phase.There are many different CPUs with different machine
    languages. Often the machine language changes subtly from
    CPU version to CPU version. It would be annoying if we had to
    rewrite large parts of the compiler. Fortunately, most machine
    languages are rather similar. This helps us to abstract almost
    the whole compiler from the details of the target language. The
    way we do this is by using in essence two compilers.
  9. 9Explain briefly what an optimiser is.Translating a program often introduces various inefficiencies,
    make the program e.g. run slow, or use a lot of memories, or
    use a lot of power (important for mobile phones). Optimisers try
    to remove these inefficiencies, by replacing the inefficient
    program with a more efficient version (without changing the
    meaning of the program).
  10. 10What is the difference between compilers and interpreters?What is the difference between compilers and interpreters?
  11. 11The purposes of the lexing and parsing phase are twofold. What are they?- Convert the input from strings to an abstract syntax tree
    - Check syntactic correctness
  12. 12What are the two main benefits of lexing?-It simplifies the next stage, parsing
    -It abstracts the rest of the compilers from the syntactic detail of the source language.
  13. 13List some of the basic constituents of programs.Keywords (IF, ELSE, WHILE, ...)
    I Identifiers (x, i, username, ...)
    I Integers (0, 1, 17, -3, ...)
    I Floating point numbers (2.0, 3.1415, -16.993, ...)
    I Binary operators (+, *, &&, ||, =, ==, !=, :=, ...)
    I Unary operator (-, *, ., ->, ... )
    I Left bracket
    I Right bracket
  14. 14How does the lexer know that the “for” in “formulaLength” isn’t a keyword?By looking ahead
  15. 15How far does the lexer have to look ahead (in Java-like languages) before it can decide whether for... is the keyword for or the beginning of an identifier?Modern programming languages: typically 1 character
    Some old languages can require unbounded lookahead
  16. 16What is an alphabet? What is a string over an alphabet?A set of characters.
    A string over an alphabet is a finite sequence of element from the alphabet.
  17. 17Since regular expressions are a special case of CFGs, could we not do both, lexing and parsing, using only CFGs?In principle yes, but lexing based on REs (and FSAs) is simpler
    and faster!

Information

Description
Flashcards on Compilers Lectures 1-6 Questions (not thorough), created by Alexandros Parpas on 06/01/2015.
Views
9
Rating

More on Stages of Compilation

Feedback

What is it about?

What do you think of the new look?

How do you like it?