0% found this document useful (0 votes)
11 views5 pages

Review Questions

The document is a question bank on compiler theory, presenting a series of true/false questions regarding various aspects of compiler design and functionality. It covers topics such as the roles of front-end and back-end, parsing, lexical analysis, semantic analysis, and regular expressions. Each question requires the reader to evaluate statements and correct any false assertions.

Uploaded by

ahmedaymanx100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Review Questions

The document is a question bank on compiler theory, presenting a series of true/false questions regarding various aspects of compiler design and functionality. It covers topics such as the roles of front-end and back-end, parsing, lexical analysis, semantic analysis, and regular expressions. Each question requires the reader to evaluate statements and correct any false assertions.

Uploaded by

ahmedaymanx100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Compiler theoryquestion bank

Question (1)
State whether the following are true or false, correct the false answer.

a) The back end should check IR, created by the front end, for syntactic and semantic errors.
b) The Front end consists of a series of phases, with the end of these phases, the Source
program converted to the target machine’s instruction set.
c) The optimizer cannot make more than one pass over the IR.
d) Front end phases in compiler is machine dependent / language independent.
e) The scanner is the only pass in the compiler manipulates every character of the code.
f) The token of Keyword “IF” has type and attributes.
g) Keywords can be used as an identifier.
h) The regular expression (D|R)2 is equivalent to R|RR|RRR|RRRR.
i) Transition diagram may be has one start state and many accepting states.
j) The highest precedence of regular expressions basic operations is the Union |.
k) We can use regular expressions to express language syntax.
l) In context-free grammars, the goal symbol may be one of the terminal symbols.
m) LL(1)grammars are backtrack free.
n) Compiler is simply a computer program that translates software written in onelanguage into
another language.
o) The compiler has a front end to deal with the source language. It has a backend to deal with
the target language. It has an intermediate form to connectboth ends.
p) Each programming language statement must be translated intohundreds of machine
operations before it can execute.
q) Typical “source” languages might be C, C++, FORTRAN, or Java. The“target” language is
usually the instruction set of some processor.
r) Instruction set is the set of operations supported by a processor; the overalldesign of an
instruction set is often called an Instruction Set Architecture orISA.
s) A compilation is usually implemented as a sequence of transformations(SL; L1); (L1; L2); : :
: ; (Lk; TL), where SL is the Source Language and TLis the Target Language. Each language
Li is called an IntermediateLanguage.
t) Compilation Analysis: Discover the structure and primitives of the source program,
determining its meaning.
u) Compilation Synthesis: Create a target program equivalent to the source program.

1
v) A compiler is a large, complex software system.
w) The front end focuses on understanding the source-language program. The back end focuses
on mapping programs to the target machine
x) it can assume that the IR contains no syntactic or semantic errors
y) We can construct multiple back ends for a single front end to produce compilers that accept
the same language but target different machines. Similarly, we can envision front ends for
different languages producing the same IR and using a common back end.
z) The optimizer is an IR-to-IR transformer
aa) The back end consists of a series of passes, each of which takes
the IR program closer to the target machine’s instruction set.
bb) Source – to – source Compiler such as that many compilers produce C programs as their
output. Because compilers for C are available on most computers.
cc) Syntax Analyzer (Parser). Phase is considered as Machine Independent/Language
Dependent.
dd) Semantic Analyzer. Phase is considered as Machine Independent/Language Dependent
ee) Lexical Analyzer (Scanner). Phase is considered as Machine Independent/Language
Dependent
ff) Code Generator phase is considered as Machine Independent/Language Dependent
gg) the parser checks if the expression made by the tokens is syntactically correct or not
hh) Semantic Analysis checks if whether identifiers are declared before use or not
ii) The semantic analyzer produces an explained syntax tree as an output.

jj. Code Generation phase maps Intermediate code to the target machine language.
kk. The symbol table is also used for store identifiers attributes.
ll. Intermediate Language for an Optimizing Compiler (ILOC): ILOC has a standard set of
operations, there are registers and memory operations; loads and stores, transfer values
between memory and the registers.
mm. The scanner, or lexical analyzer, reads a stream of characters and produces a stream of
words.

2
nn. The scanner is the only pass in the compiler that manipulates every character of the input
program.
oo. The lexical analyzer breaks these syntaxes into a series of tokens
pp. Lexical analyzer generates an error if it finds an invalid token.
qq. Each token is a sub-string of the programthat is to be treated as a single unit
rr. Lexeme: A lexeme is a sequence ofcharacters in the source program that is matched by the
pattern for a token.
ss. Finite automaton is a formulation for recognizers that hasa finite set of states, alphabets,
transition functions, a start state, and one or more accepting states.
tt. The language consisting of the single word, new, can be described by a RE written as new.
uu. The language consisting of new or not can be written as new |not. Other REs are possible,
such as n(ew | ot).
vv. For the RE, x, we writethis as 𝒙∗, with the meaning “zero or more occurrences ofx”.
ww. Alternation. The alternation, or union, of two sets of strings, R and S, denoted 𝑅|𝑆, is
𝑥|𝑥∈𝑅𝑜𝑟∈ .
xx. Concatenation. The concatenation of two sets R and S, denoted RS, contains all strings
formed by prepending an element of R onto one from S.
yy. Closure. The Kleene closure of a set R, denoted 𝑅∗. This is just the concatenations of R with
itself, zero or more times.
zz. The notation 𝑅𝑖 denotes from one to 𝑖 occurrences of R, for example, 𝑅3 is just 𝑅|𝑅𝑅|𝑅𝑅𝑅.
aaa. The positive closure, denoted 𝑅+, is just 𝑅𝑅∗ and consists of one or more occurrences of R.
bbb. In regular expression presentation, To eliminate any ambiguity, parentheses have highest
precedence, followed by closure, concatenation, and alternation,
ccc. NFA can be transformed into DFA, which are easily and efficiently executable on normal
hardware.
ddd. FA that includes states such as 𝑠0 that have multiple transitions on a single character is called
a nondeterministic finiteautomaton (NFA).
eee. Nondeterministic FA, NFA, is an FA that allows transitions on the empty string, 𝜖, and
states that have multiple transitions on the same character.
fff. Deterministic FA, DFA, is an FA where the transition function is single-valued. DFAs do
not allow 𝜖-transitions. Each state has one edge. a FA with unique character transitions in
eachstate.
ggg. As a final refinement to the 𝑅𝐸𝐷𝐹𝐴 conversion, we can add an algorithm to minimize the
number of states in the DFA, this technique is called hopcraft’s algorithm.
hhh. The scanner generator must convert the DFA into executable code. This task is accomplished
by 3 techniques a table-drivenscanner, a direct-coded scanner, and a hand-coded
scanner.

3
iii. If the parser determines that the input stream is a valid program, it builds a concrete model of
the program for use by the later phases of compilation. If the input stream is not a valid
program, the parser reports the problem and appropriate diagnostic information to the user.
jjj. Parsing is finding a derivation in a grammar 𝐺 that produces a stream 𝑠 of words.
kkk. Parsing algorithms fall into two general categories. Top-downparsers, and Bottom-up
parsers.
lll. Context-free grammar, 𝐺, is a set of rules that describe how to form valid sentence in
language, 𝐿.
mmm. CFG is a superset of Regular Grammar
nnn. context-free grammar has four components.
ooo. Terminals are the basic symbols from which strings are formed
ppp. Each production consists of a nonterminal called the left side of the production, an arrow,
and a sequence of tokens and/or non- terminals, called the right side of the production.
qqq. One of the non-terminals is designated as the start symbol (S); from where the production
begins.
rrr. Derivation is a sequence of rewriting steps that begins with the grammar’s start symbol and
ends with a sentence in the language.
sss. The string is a collection of terminal or nonterminal symbols.
ttt. A parse tree or syntax tree is a graph that represents a sentence derivation.
uuu. Ambiguous grammar, 𝐺, is a grammar where some sentence in L(G) has more than one
rightmost (or leftmost) derivation and can produce multiple parse trees.
vvv. Array subscripts should be applied before standard arithmetic operations. This ensures, for
example, that 𝑎 + [𝑖] evaluates [𝑖] to a value before adding it to 𝑎.
www. The parse tree’s root is known; it represents the grammar’s start symbol. The leaves of the
parse tree are known;
xxx. Top-down parsers that begin with the root and grow the tree toward the leaves.
yyy. Bottom-up parsers that begin with the leaves and grow the tree toward the root
zzz. The lowest fringe of the parse tree contains only terminal symbols.
aaaa. generated LL(1) parsers are backtrack free
bbbb.If the parser always makes the right choice, topdown parsing is efficient. If it makes poor
choices, the cost of
parsing rises.
cccc. A rule in a CFG is left recursive if the first symbol on its right-hand
side is the symbol on its left-hand side or can derive that symbol. The
former case is called direct left recursion, while the latter case is
called indirect left recursion

4
dddd.If more than one grammar production rules has a common prefix
string, then the top-down parser cannot make a choice as to which of
the production it should take to parse the string in hand.
eeee. A backtrack-free grammar is also called a predictivegrammar.
ffff. FIRST Set: This set is created to know what terminal symbol is
derived in the first position by a non-terminal.
gggg.Syntax analyzers cannot determine if a token is valid.
hhhh.Syntax analyzers cannot determine if a token is declared before it is being used.
iiii. Syntax analyzer cannot determine if a token is initialized before it is being used
jjjj. cannot determine if an operation performed on a token type is valid or not

You might also like