cisc 471 first exam review game questions. overview 1 draw the standard phases of a compiler for...

16
CISC 471 First Exam Review Game Questions

Upload: james-powell

Post on 12-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

CISC 471 First Exam Review Game Questions

Page 2: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Overview 1

• Draw the standard phases of a compiler for compiling a high level language to machine code, showing the input and output forms for each phase.

Page 3: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Overview 2

• State 2 advantages of using an interpreter instead of a compiler for implementing a language.

• State 2 advantages of using a compiler instead of an interpreter for implementing a language.

Page 4: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Overview 3

• What are the roles of a:– Preprocessor– Assembler– Linker ?

Page 5: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Lexical Analysis 1

• Demonstrate that you understand the difference between a token and a lexeme, through an example.

• Give an example of a language feature that makes scanning nontrivial.

Page 6: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Lexical Analysis 2

• Give a regular expression that represents exactly the set of decimal numbers that contain at least one digit representing the whole number part, no sign, and if there is a decimal point, then at least one digit to the right of the decimal point. Also, 0. is illegal.

Page 7: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Lexical Analysis 3

• Show the partitioning of the input string below given the following flex spec rule set:

a*bbba+caabab | cInput: abaabbaabaaaabbbccaabbaaba

Page 8: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

CFG 1

Show an equivalent Context free grammar for the regular expression:

S -> (A | B)* BA|CA -> DA | wB -> w | xC -> CD | DD -> y

Page 9: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

CFG 2

• Show that E -> E + E | w is an ambiguous grammar.

• How would you rewrite the grammar to remove the ambiguity if + is left associative?

Page 10: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

CFG 3

• Show a leftmost derivation for the string (a,a) with the grammar:

S-> (L) | aL-> L,S | S

Explain the difference between an abstract syntax tree and a concrete syntax tree and justify why most compilers use abstract syntax trees.

Page 11: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Parsing 1

Explain and show an example of two properties of grammars that cause problems for topdown parsers, and require rewrites or special rules in the yacc file.

Name the two different ways that are used to build top-down parsers.

Page 12: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Parsing 2

Write the recursive descent routine for the following nonterminal:

D -> D , id | id | ε

Page 13: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Parsing 3

Explain the actions of an LR bottom up parser for:

ShiftReduce

Explain how the parser determines the state to put back on top of the stack after a Reduce.

Page 14: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Semantic Analysis 1

• Give 3 different examples of errors that are caught by semantic analysis and cannot be caught by the first two phases.

• Explain the difference between inherited and synthesized attributes.

Page 15: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Semantic Analysis 2

Show the attributed tree for -101 with the rules:

Page 16: CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing

Semantic Analysis 3

• Why is it a nice property to have an attribute grammar that has only synthesized attributes?

• Why is a circular attribute grammar a bad property?