Assignment 3

  1. Explain why the following if statement results in syntax error in C, Java, and C#?
    
       if (x==1) y = 2 else y = 3;
    

  2. Give a CFG for each of the following languages.
  3. Give a context-free grammar for each of the following languages over S={a,b}:

     

    a) {aibj  | i,j≥0}

    b) {aibjak | i+j=k,k>=0}

  4. Show the parse tree of the following Java program:
    
    import java.util.Scanner;
    
    class Ex {
    	public static void main(String[] args){
    		Scanner keyboard = new Scanner(System.in);
    		System.out.println("enter a number");
    		double x  = keyboard.nextDouble();
    		System.out.println("x^2+2x+1 = " + x*x+2*x+1);
    	}
    }