Monday, April 8, 2013

Answers of Concepts of Programming Languages Chapter 4


Review Questions
1.
2. -Simplicity : techniques for lexical analysis are less complex than syntax analysis
   -Efficiency : lexical analysis requires a significant portion of total compilation time, so it is not good enough to optimize the syntax analyzer
   -Portability : lexical analysis is platform dependent while syntax analyzer is platform independent
3. Lexeme : logical groupings consist of characters collected by lexical analyzer
   tokens : internal codes for categories of lexemes
4.
5. -Write a formal description of the token patterns of the language using a descriptive language related to regular expressions
   -Design a state transition diagram that describes the token patterns of the language and write a program that implements the program
   -Design a state transition diagram that describes the token patterns of the language and hand-construct a table-driven implementation of the state diagram
6. State transition diagram is a directed graph, whose nodes are labeled with state names.
7.
8. -checking the input program to determine whether it is syntactically correct
   -producing a complete parse tree
9. top-down : building tree from the root downward to the leaves
   bottom-up : builidng tree from the leaves to the root
10. it is too complicated and inefficient
11. it is too complicated and inefficient
12. it is in order to increase the speed of parsing

Problem Set
1.a. pass
  b. not pass
  c. pass

2.a. pass
  b. pass
  c. not pass

3. void expr()
   {
      printf("Enter expr\n");
 
 
     term();

     while(nextToken== ADD_OP || nextToken==MULT_OP)
     {
        lex();
        term();
     }

     printf("Exit expr\n");
   }

No comments:

Post a Comment