EXERCISES

Several of the following exercises are to be done on a computer system. A Linux system is recommended. You should have gcc and Java Development Kit (JDK) installed.

  1. The function traverse_parse_tree() in Section 8.1.1 traverses the parse tree in pre-order. Modify it to traverse in in-order and post-order.
  2. In Section 8.2.1 on generating RPN, we saw that certain local values were to be stored in the functions for the Non-Terminals and we used the return-stack for the purpose. This decision was really a hack. It may work in demo programs, but in real-life code, which will be required to handle source programs of arbitrary size, the return-stack will get heavily loaded and may put a limit on the size of the programs which can be translated. The tree-node structure used has a number of util pointers available. Investigate how to use these pointers to associate required information with each node in the tree.
  3. Find out how to obtain the intermediate byte code for a Perl program.
  4. Use javap to obtain human-readable Bytecodes for the following Java program and explain the output as far as you can.
    public class Hello{
      public static void main (String[]args){
       System.out.println (“Hello, World!”);
      }
    }
    
    You will have to compile the program first with the Java compiler javac.
  5. Use javap to obtain human-readable Bytecodes for the following Java program and explain the output.
    public class HelloThread extends Thread{
      public int i = 0;
      public void run(){
        i++;
        System.out.println (“Hello from a thread! “+i);
      }
      public static void main (String args[]){
        (new HelloThread()).start();
        (new HelloThread()).start();
      }
    }
    
  6. Use gcc to obtain its Intermediate representation outputs for the following sample C program:
    int fund (int i){
      return i * (i + i);
    }
    int main(){
      int j = 5, k;
      k = fund (j);
    }
    

Comment on your results.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.237.123