Sunteți pe pagina 1din 5

CS-401 Compiler Construction

Homework #1
Due Date: 04 Oct 2018 in class

Your Name: Javed Khan


Your Email: javedkhan0000089@gmail.coms

1. What is the input to a compiler called?


ANS: source code

2. What is the output called?


ANS: Object code, or sometimes object module, is what a computer compiler produces

3. What are the phases in a typical compiler?


ANS: The compilation process is a sequence of various phases
 Lexical Analysis
 Syntax Analysis
 Semantic Analysis
 Intermediate Code Generation
 Code Optimization
 Code Generation
 Symbol Table

4. Lexical Analysis breaks the input into what?


ANS: Lexical Analysis mainly segments the input stream of characters into tokens.
Simply grouping the characters into pieces and categorize them.

5. What kind of grammars are we concerned with?


ANS: Syntax Free Grammar.

6. The symbol table generally has an entry for each ... what?
ANS: symbol table is a data structure used by a language translator such as
a compiler or interpreter, where each identifier (a.k.a. symbol) in a program's source code is
associated with information relating to its declaration or appearance in the source. Symbol table
stores the information related about the symbol.
7. What phase is type-checking done in?
ANS: Symantic Analyzer is the Phase where we check the type casting.

8. Is the code generated in the intermediate code generation phase target-machine-


specific or target-machine-independent?
ANS: Target-Machine Independent
9. When the compiler detects an error in the source, should it halt after printing a
message?
ANS: All syntax errors and some of the semantic errors (the static semantic errors) are detected
by the compiler, which generates a message indicating the type of error and the position in the
Java source file where the error occurred.
Other semantic errors and the logical errors cannot be detected by the compiler, and hence they
are detected only when the program is executed.

11. What is a lexeme?


ANS: A lexeme is a sequence of characters in the source program that matches a pattern
for the tokens and identified by the lexical analyzer.

12. What are blanks, tabs, and newlines called?


ANS: White Spaces.
13. Are comments passed to the parser? Why or why not?
ANS: The Comments are the line or the paragraph between the following
Two operators “//, /* */”. According to the “Long Matching Rule” the Comments are not
scan and Ignored.

14. For each token, the lexer passes 2 pieces of info to the parser. What are they?

____________________________
15. For what types of token would additional information be needed?
ANS: Some Tokens are the additional information like
Add (a, b);
It is a function and the information about the a, b are store but the information about
Add (); not store so it is some additional information and store in the symbol table.

16. Some tokens (like “if”, “while”, “class”) are built into the language. What
are these
tokens called?
ANS: Keywords are a set of words which are used for special purposes while writing a
program. Few examples are: for, while, switch, break, goto, and etc.

17. How does a “string table” differ from a “symbol Table”?


ANS: String table sections hold null-terminated character sequences,
commonly called strings. The object file uses these strings to represent symbol
and section names.
Symbol Table is an important data structure created and maintained by the compiler in order
to keep track of semantics of variable i.e. it stores information about scope and binding
information about names, information about instances of various entities such as variable and
function names, classes, objects, etc.
18: Why would we enter keywords into a string table?
ANS: The Keywords are the Strings and in the String table sections hold null-
terminated character sequences, commonly called strings

21. Can the same ID have more than one meaning in a program?
ANS: The Same Id Have the One Meaning Not More than one Meaning.

22. In a CFG, what does epsilon mean? Please do not say “nothing”.
ANS: Epsilon (ε) is a way to make a zero length sequence visible it is not a grammer
symbol
23. What is the Greek letter for epsilon?
ANS:Epsilon (uppercase Ε, lowercase ε or lunate ϵ; Greek: έψιλον) is the fifth letter of the Greek
alphabet, corresponding phonetically to a mid front unrounded vowel /e/.

24. In a parse tree, the internal nodes correspond to what... Terminals or Non-
terminals?
ANS: The Internal Nodes are Non-Terminal.

25. In a parse tree, the leaves correspond to what... Terminals or Non-terminals?


ANS: The leaves Nodes are Terminal Symbols.

26. Here is a grammar


A
→ Ab
b→ c
Draw a parse tree for the string “c b b b”

ANS: It is not Possible to create a Terminal With a Terminal.

A → A is possible But b → c is not possible

28. What is an ambiguous grammar?


ANS: ambiguous grammar is a context-free grammar for which there exists a string that can
have more than one leftmost derivation or parse tree.

29. Is it a good idea for programming languages to use ambiguous grammars?


ANS: No it is not a good idea for programming Languages to use ambiguous grammar.

30. The expression x-y-z means either (x-y)-z or x-(y-z). This is a question of
operator...
What?
ANS: Yes it is the Question of the Operator.

31. The expression x+y-z means either (x+y)-z or x+(y-z). This is a question of
operator... what?
ANS: Yes it is the Question of the Operator.
32. Is this grammar rule left- or right-recursive?
A→Ab

ANS: It is Not left recursive or right recursive Because in left Recursive we used
“+, *” and in the Right Recursive we used the”=” more than one.
33. What is the input to a parser (in the context of compiling)?
ANS: A parser take the input in the form of sequence of tokens and usually builds a data
structure in the form of parse tree.

34. What is the input to a parser generator?


ANS: The usual input is a formal specification of the grammar the parser has to recognize, plus
code implementing the actions the parser has to take when recognizing the various parts of its
input.

35. What are the two major approaches to parsing?


ANS: These are two parsing approaches:
1. Top Down Parsing (LL1 Parsing )
2. Bottom Up Parsing (LL0 Parsing)

37. We can create a parser by constructing a routine for each non-terminal. This
approach is called... what?
ANs: Top Down Recursive Decent Parsing.

39. Compared to a parse tree, is an abstract syntax tree larger or smaller?

ANS: Abstract syntax tree larger is larger than the parse tree.

S-ar putea să vă placă și