Friday, July 31, 2009

Complier questions?

LANGUAGE TRANSLATION FUNDAMENTALS


1. Define a compiler and an interpreter. Draw flow diagrams showing the major components of each.


INPUT SCANNING, OR LEXICAL ANALYSIS


2. How does a table-driven scanner work? Describe the major phases in this process.


3. For each of the following regular expressions, list two strings in the language:


a. (a*(b|c)+)


b. (abc(d)*)


c. ((ab) + (cd))+


d. (a)+(b)*(c)+(a)*(b)+(c)*


e. ((a(bc)+)|((de)+f))


4. Draw a finite state machine for each of the following situations:


a. odd parity checker (an odd number of bits in a string of 0's and 1's).


b to recognize the words: ADD, AARDVARK, and ADAM.


c to recognize C floating point numbers (with Expotentiation).


d to recognize a 10-digit telephone number (with hyphens).


e. to recognize the C comment construct: _/* ... */_


5. Consider the following regular expression: (a|b)+(ab)*


a. Construct a NFA from this regular expression


b. Construct the DFA from the NFA





6. In LEX, if two patterns in the input specification match the same string, what will happen?





GRAMMARS, OR LANGUAGE DEFINITIONS


7. Given the following grammar:


%token ID


%token CONSTANT


%start expr


%%


primary_expr


: ID


| ‘-‘ ID


| CONSTANT


| ‘(‘ expr ‘)’


;


mult_expr


: primary_expr


| mult_expr ‘*’ primary_expr


| mult_expr ‘/’ primary_expr


;


add_expr


: mult_expr


| add_expr ‘+’ mult_expr


| add_expr ‘-‘ mult_expr


;


expr


: add_expr


| ID ‘=’ primary_expr


;


a. Show the leftmost derivation of the input string: (ID - ID) / (-ID).


b. Draw the parse tree for a bottom-up parse.


c. Show the rightmost derivation of the input string: (ID - ID) / (-ID)


d. Draw the parse tree for a top-down parse.


8. What causes a grammar to be ambiguous?


INPUT PARSING, OR SYNTAX ANALYSIS


9. Compute the first sets for the grammar in question 7.


10. What is the major difference between a LR(1) parser and a LALR(1) parser?


11. Discuss some of the problems encountered if a LR(1) type parser is used for interactive applications. How can this be remedied by a LL(1) style parser?





SEMANTIC PROCESSING, OR TRANSLATION


12. Describe what type of information is propagated down through the parse tree during a syntax directed translation.


13. Discuss the advantages and disadvantages of generating abstract syntax trees in lieu of direct interpreted code when translating compilers for high-level computer languages.


14. What is a synthesized attribute?





TRANSLATION FUNDAMENTALS


15. Describe what information would be placed in the symbol table for each identifier in the following C program:


int E [50];


int F;


void FUNC (int *A, int B, int C[])


{


int W, X;


...


}


int MAIN (void)


{


FUNC (E, F, E);


...


}


16. Discuss the advantages and disadvantages of one global hash table versus one table per scope being compiled.


17. How are local variables allocated when a procedure or function is called in modern procedural computer languages?


18. In heap allocation schemes, what is the best-fit method? What is the first-fit method?


19. What construct in traditional YACC facilitates the creation of multiple types for the symbol table?


20. How can the type equivalence test of two identical type declarations be implemented by only a pointer comparison?


21. Convert the following expression to quadruples.


(a + b) / (d - e)

Complier questions?
Sorry man, I already did my homework and don't have time to do yours.


No comments:

Post a Comment