Exam Questions and CORRECT Answers
What does the compiler take as input and produce as output? - CORRECT ANSWER -
Source program text - the source language, and outputs program target for the machine - the
target language
What is the difference between a compiler and an interpreter? - CORRECT ANSWER -A
compiler takes source language and outputs target language, which is then executed accepting
input and producing output. Interpreters don't produce a target program as a translation, and
instead appear to directly take execute the operations specified in the source program on inputs
supplied by the user
What is LLVM? - CORRECT ANSWER - set of libraries containing the clang compiler,
and C/C++/Objective-C compilers. Introduced to allow reuse of the parser, for example, from a
static compiler. Implements statically and runtime compiled languages.
LLVM allows you to provide a front and back-end and the LLVM optimiser takes your AST and
produces LLVM intermediate representation.
Give a flowchart of a language-processing system - CORRECT ANSWER - source
program -> PREPROCESSOR -> modified source code -> COMPILER -> target assembly
program -> ASSEMBLER -> relocatable machine code -> LINKER/LOADER -> target machine
code
Describe the four stages of the Slang front end. What is the difference between the Parsed AST
and Internal AST? What does static.ml do? - CORRECT ANSWER - We input the slang
file, which is then parsed using LEX and YACC. We then get a parsed AST Past.expr and do
static analysis, checking types, context-sensitive rules and resolve overloaded operators. Then we
remove syntactic sugar, file loc info and types. Then we get an intermediate AST (Act.expr).
Parsed AST has expr as Boolean of loc * bool for example.
Locations are used for errors.
, Static ML checks type correctness and rewrites expressions to resolve equality, only let fun is
returned. Errors return line where error discovered, not source
Interal AST has no locations, types no let or EQ
How do we find the line number? - CORRECT ANSWER - Have a location for lexing
position, which gives location in the file where we found the element in the AST
What do the middle and backends of the front-end do? - CORRECT ANSWER - Generate
many intermediate languages, whilst persevering semantics, but eliminating aspects of the gap
like syntactic sugar etc.
What is a formal grammar? - CORRECT ANSWER - A set of production rules for strings
in a formal language. Grammar doesn't define meaning, only the syntactic construction of
strings.
What is a context-free grammar? - CORRECT ANSWER - the left-hand side of each
production rule consists of only a single nonterminal symbol
What is a syntax analyser? - CORRECT ANSWER - This is parsing. Based on push down
automation and context-free grammars. It produces an Abstract Syntax Tree
What does the lexical analyser do? - CORRECT ANSWER - Based on finite automation
and regular expressions, it takes stream of chars from source program, groups characters into
lexemes. For each lexeme, token of for <token-name, attribute-value>. token-name used during
syntax analysis, attribute-value points to entry in symbol table
What two phases does compilation involve? - CORRECT ANSWER - Analysis: impose
grammatical structure, creates intermediate representation of program. Detects syntax and
semantics errors and feedback to user. Collects info about program and stores it in symbol table,
which is passed to synthesis stage.