Homework 1
This commit is contained in:
		
					parent
					
						
							
								49bca7f856
							
						
					
				
			
			
				commit
				
					
						12f678a924
					
				
			
		
					 43 changed files with 3703 additions and 0 deletions
				
			
		
							
								
								
									
										21
									
								
								javali_tests/HW1_nop90/Division.javali
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										21
									
								
								javali_tests/HW1_nop90/Division.javali
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
class Main {
 | 
			
		||||
    void main() {
 | 
			
		||||
        int a, b, c, d, e;
 | 
			
		||||
 | 
			
		||||
        a = 10;
 | 
			
		||||
        b = -1;
 | 
			
		||||
        c = 0;
 | 
			
		||||
        d = 100;
 | 
			
		||||
        e = 2;
 | 
			
		||||
 | 
			
		||||
        write(a / b); writeln();
 | 
			
		||||
        write(d / e); writeln();
 | 
			
		||||
        write(c / d); writeln();
 | 
			
		||||
        write(b / a + c); writeln();
 | 
			
		||||
        write(d / e * a / b * c); writeln();
 | 
			
		||||
        write(d / e * a / b); writeln();
 | 
			
		||||
        write(d / e + a / b); writeln();
 | 
			
		||||
        write(d / e * a * b * c); writeln();
 | 
			
		||||
        write(d / e * a - b + c); writeln();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								javali_tests/HW1_nop90/EightVariablesWrite.javali
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								javali_tests/HW1_nop90/EightVariablesWrite.javali
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
/* Test expression evaluation with 8 variables */
 | 
			
		||||
class Main {
 | 
			
		||||
	void main() {
 | 
			
		||||
		int r1, r2, r3;
 | 
			
		||||
		int i0,  i1,  i2,  i3,  i4,  i5, i6, i7;
 | 
			
		||||
		
 | 
			
		||||
		i0 = 0;
 | 
			
		||||
		i1 = 1;
 | 
			
		||||
		i2 = 2;
 | 
			
		||||
		i3 = 3;
 | 
			
		||||
		i4 = 4;
 | 
			
		||||
		i5 = 5;
 | 
			
		||||
		i6 = 6;
 | 
			
		||||
		i7 = 7;
 | 
			
		||||
		
 | 
			
		||||
		write(i0 + (i1 + ( i2 + ( i3 + ( i4 + (i5 + (i6 + i7))))))); writeln();
 | 
			
		||||
		write(((((((i0 + i1) + i2) +  i3) +  i4) +  i5) + i6) + i7); writeln();
 | 
			
		||||
		write(((i0 + i1) + (i2 + i3)) + ((i4 + i5) + (i6 + i7))); writeln();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								javali_tests/HW1_nop90/Multiplication.javali
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										31
									
								
								javali_tests/HW1_nop90/Multiplication.javali
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,31 @@
 | 
			
		|||
class Main {
 | 
			
		||||
   void main() {
 | 
			
		||||
      int r1;
 | 
			
		||||
      int i0,  i1;
 | 
			
		||||
      int x,y,z;
 | 
			
		||||
		
 | 
			
		||||
      i0 = 5;
 | 
			
		||||
      i1 = 2;
 | 
			
		||||
		
 | 
			
		||||
      r1 = i1 * 3;
 | 
			
		||||
      write(r1); writeln();
 | 
			
		||||
 | 
			
		||||
      r1 = i0 * i1;
 | 
			
		||||
      write(r1); writeln();
 | 
			
		||||
	
 | 
			
		||||
      r1 = r1 * i0 * i1 * 3;
 | 
			
		||||
      write(r1); writeln();
 | 
			
		||||
      
 | 
			
		||||
      y = 5;
 | 
			
		||||
      z = 10;
 | 
			
		||||
      x = (-y * z);
 | 
			
		||||
      write(x); writeln();
 | 
			
		||||
      
 | 
			
		||||
      y = 0;
 | 
			
		||||
      z = - 10;
 | 
			
		||||
      x = (y * z);
 | 
			
		||||
      write(x); writeln();
 | 
			
		||||
      write(y * z); writeln();
 | 
			
		||||
      write(0 * -10); writeln();
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								javali_tests/HW1_nop90/Overflow.javali
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										25
									
								
								javali_tests/HW1_nop90/Overflow.javali
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
/* Test what happens for Integers that are to big for 32bits 
 | 
			
		||||
2147483647 (=0x7FFFFFFF) is the biggest integer in 32bits (IntMAX)
 | 
			
		||||
*/
 | 
			
		||||
class Main {
 | 
			
		||||
	void main() {
 | 
			
		||||
		int x,y,z;
 | 
			
		||||
		x = 2147483647;
 | 
			
		||||
		write( x ); writeln();
 | 
			
		||||
		/* add 1 to IntMax and output it */
 | 
			
		||||
		write( x + 1); writeln();
 | 
			
		||||
		
 | 
			
		||||
		/* read an int bigger than IntMAX */
 | 
			
		||||
        x = read();
 | 
			
		||||
		write(x); writeln();
 | 
			
		||||
		
 | 
			
		||||
		/* performe some operation that should generate an int overflow */
 | 
			
		||||
		x = 2147483640;
 | 
			
		||||
		y = 60000;
 | 
			
		||||
		write( x + y); writeln();
 | 
			
		||||
		z = 20000000;
 | 
			
		||||
		write( y * z); writeln();
 | 
			
		||||
		write( (y * z) ); writeln();
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								javali_tests/HW1_nop90/Overflow.javali.in
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										1
									
								
								javali_tests/HW1_nop90/Overflow.javali.in
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
2147483647
 | 
			
		||||
							
								
								
									
										26
									
								
								javali_tests/HW1_nop90/ReadWrite.javali
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								javali_tests/HW1_nop90/ReadWrite.javali
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
/* Test read/write native functions */
 | 
			
		||||
class Main {
 | 
			
		||||
	void main() {
 | 
			
		||||
		int r1, r2, readvar, a1;
 | 
			
		||||
		
 | 
			
		||||
		r1 = 6;
 | 
			
		||||
		/* r2 = 22 */
 | 
			
		||||
		r2 = read();
 | 
			
		||||
		
 | 
			
		||||
		write(r1); writeln(); // 6
 | 
			
		||||
		
 | 
			
		||||
		/* test expressions inside write() */
 | 
			
		||||
		write(r1 - 3); writeln(); // 3
 | 
			
		||||
		write(r1 - 6); writeln(); // 0
 | 
			
		||||
		write(r1 - 7); writeln(); // -1
 | 
			
		||||
		/* should output 111 */
 | 
			
		||||
        readvar = read(); // 1
 | 
			
		||||
		write( (r1 + (r2 * 5)) + readvar); // 117
 | 
			
		||||
		write(- r1); // -6
 | 
			
		||||
		writeln();
 | 
			
		||||
		/* should output 15 */
 | 
			
		||||
        a1 = read(); // -15
 | 
			
		||||
		write(- a1); // 15
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								javali_tests/HW1_nop90/ReadWrite.javali.in
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								javali_tests/HW1_nop90/ReadWrite.javali.in
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
     22
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    1
 | 
			
		||||
 | 
			
		||||
-15
 | 
			
		||||
							
								
								
									
										15
									
								
								javali_tests/HW1_nop90/UnaryOperators.javali
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								javali_tests/HW1_nop90/UnaryOperators.javali
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
class Main {
 | 
			
		||||
    void main() {
 | 
			
		||||
        int a, b;
 | 
			
		||||
 | 
			
		||||
        a = 1;
 | 
			
		||||
        b = 2;
 | 
			
		||||
 | 
			
		||||
        write(+a); writeln();
 | 
			
		||||
        write(-a); writeln();
 | 
			
		||||
        write(+a --b); writeln();
 | 
			
		||||
        write(-a--b); writeln();
 | 
			
		||||
        write(-----a-----5--b); writeln();
 | 
			
		||||
        write(-----a*---------b);writeln();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								javali_tests/HW1_nop90/noParentheses.javali
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										24
									
								
								javali_tests/HW1_nop90/noParentheses.javali
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
/* test	what happens if there are no parentheses */
 | 
			
		||||
 | 
			
		||||
class Main {
 | 
			
		||||
   void main() {
 | 
			
		||||
      int x;
 | 
			
		||||
      int y;
 | 
			
		||||
      int z;
 | 
			
		||||
 | 
			
		||||
      x = 5;
 | 
			
		||||
      y = 10;
 | 
			
		||||
      z = 100;
 | 
			
		||||
      
 | 
			
		||||
      write( x + y + z); writeln();
 | 
			
		||||
      /*  */
 | 
			
		||||
      write( - x + y - z); writeln();
 | 
			
		||||
      
 | 
			
		||||
      /* should output 205 */
 | 
			
		||||
      write( x + 2 * z); writeln();
 | 
			
		||||
 | 
			
		||||
      write( x + 2 * z / x + 1); writeln();
 | 
			
		||||
      write(+x); writeln();
 | 
			
		||||
      
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue