Escolar Documentos
Profissional Documentos
Cultura Documentos
Homework #1
Due Date: 04 Oct 2018 in class
Your Name: _Syed Muhammad Ali________
Your Email: ___aligillani257@gmail.com_____
1. What is the input to a compiler called? ____Source Code________
2. What is the output called? ___Obbject Code_______
3. What are the phases in a typical compiler?
____Lexical Analysis __
____Syntax Analysis__
____Semantic Analysis_
____Intermediate_ Code_Generation___
____Code Optimisation_____________
____Target_Code_Generation_____________
2. Lexical Analysis breaks the input into what? __Series_of_Tokens__
5. What kind of grammars are we concerned with?
____Lexical_Grammar_( Regular
Definition)_______
6. The symbol table generally has an entry for each ... what?
__Variable names, Function names, Objects, Classes,
Interfaces,etc____________
3. What phase is typechecking done in? ___Semantic Analysis_____
8. Is the code generated in the intermediate code generation phase target
Page 1
9. When the compiler detects an error in the source, should it halt after printing a
message?
___a simple compiler may stop all the activities
but message printer must defer it's diagnostics
until after complete lines ____
11. What is a lexeme?
_______________A lexeme is a sequence of
alphanumeric characters in a token. The term is used
in both the study of language and in the lexical
analysis of computer
program___________________________
4. What are blanks, tabs, and newlines called? _____Eliminate
comments and white spaces_________
13. Are comments passed to the parser? Why or why not?
_____________ the lexical analyzer takes care of
comments and doesn't even pass them to the parser.
The compiler usually does have a concept of line
numbers for error reporting,
______________________
14. For each token, the lexer passes 2 pieces of info to the parser. What are they?
________Scanning &
Evaluating____________________
15. For what types of token would additional information be needed?
____Utility token______________________
5. Some tokens (like “if”, “while”, “class”) are built into the language. What are these
tokens called? ______Lexer, Tokenizer & scanner___
17. Here is a regular expression describing identifier tokens:
Describe the tokens specified by this regular expression:
Digit { Letter }* Digit
____Constant,Identifier,Reserved
words,Operators,Misc Synbols___
___________________________________________
18. How does a “string table” differ from a “symbol Table”?
___String table hold null terminated character
sequences,commonly called string_________
___Symbol table is an important data structure
created and maintained by
compilers___________________________________
_____
Page 2
19. Why would we enter keywords into a string table?
____Because keyword represent the problem type.
_______________________________________
21. Can the same ID have more than one meaning in a program?
_____No_________
22. In a CFG, what does epsilon mean? Please do not say “nothing”.
_____Balanced Parentheses_________
6. What is the Greek letter for epsilon? ____{ 5th letter E ,}___
24. In a parse tree, the internal nodes correspond to what... Terminals or Nonterminals?
___NonTerminals___________
25. In a parse tree, the leaves correspond to what... Terminals or Nonterminals?
___Terminals___________
26. Here is a grammar
7. → A b
→ c
Draw a parse tree for the string “c b b b”
A
/ \
A b
/ \
A b
/ \
A b
/
c
Page 3
28. What is an ambiguous grammar?
___An ambiguous grammar is a CFG for which there
exists a string that can have more than one leftmost
derivation._______
29. Is it a good idea for programming languages to use ambiguous grammars?
_Yes______
8. The expression xyz means either (xy)z or x(yz). This is a question of operator...
what? _____Control Flow_________
31. The expression x+yz means either (x+y)z or x+(yz). This is a question
of operator... what? ___Boolean ___________
32. Is this grammar rule left or rightrecursive?
A → A b
______CFG rule________
33. What is the input to a parser (in the context of compiling)?
_____In the form tokens and bbulid tha data structure
in the form of parse tree.________________
9. What is the input to a parser generator? ___Grammar___________
35. What are the two major approaches to parsing?
__UpDown____________
__BottomUp____________
10. We can create a parser by constructing a routine for each nonterminal.
This approach is called... what?
______LL(1)______________
39. Compared to a parse tree, is an abstract syntax tree larger or smaller?
___Parse Tree is larger___________
Page 4