Up Next
Go up to 6 Labs
Go forward to 6.2 Triangles

6.1 Compiling

Language translation is of great importance in Computer Science. It also presents a number of stumbling blocks in getting started in program development. Some not very theoretical problems. Like how to do it. I will list some of the road blocks that you may need to deal with. There is a lot to be said for IDEs (Integrated Development Environments). They combine the text editor, compiler, and linker into a single program. This may also include a debugging program and a "make" facility as well. The Borland Pascal 6.0 includes all of this. For a look at various types of errors See: Nance & Naps Chapter 4 page 111.

Edit, compile, link, and save a short program that prints out:

hello, world

Mark your output with:

Place the lab in the instructor hand in box in BUS R6E, the "terminal room".

For Pascal the program is as follows:

{ Program to print "hello, world"                  }
{ L Taber   September 4, 1997   PCC                }
{ Converted to Pascal                              }
{ Kernighan & Richie "The C Programming Language"  }
{ Copyright 1978  page 6                           }
program hello(input, output);

  begin
     writeln('hello, world');
  end.

On my system, to run the FPK Pascal compiler, the file is named hello.pp, I enter

ppc386 hello
To run the program:
hello

On my system, to run the FSF Gnu Pascal compiler (gpc), the file is named hello.p, I enter

gpc -o hello hello.p
To run the program:
hello

For "C" the program is as follows:

/* Program to print "hello, world"                  */
/* L Taber   October 13, 1992   PCC                 */
/* Kernighan & Richie "The C Programming Language"  */
/* Copyright 1978  page 6                           */

#include <stdio.h>

main()
{
printf("hello, world\n");
}

On my system, to run the FSF Gnu "C" compiler (gcc), I enter

gcc -o hello hello.c
To run the program:
hello

For FORTRAN the program is as follows:

!    Program to print "hello, world"                  
!    L Taber   September 4, 1997   PCC                 
!    Converted to FORTRAN                
!    Kernighan & Richie "The C Programming Language"  
!    Copyright 1978  page 6                           
        PRINT *,'hello, world'
        STOP
        END

On my system, to run the FSF GNU Fortran compiler, the file is named hello.for, I enter

g77 -o hello hello.for
To run the program:
hello

The simplest, but not suitable for this class is perl. The program is (in hello.p) as follows:

#!/usr/bin/perl
# The K&R hello world program
print( "hello, world\n");
To run the program:
./hello.p
perl is an interpreted language. No compile step is necessary. Last, is Java. This is a product of Sun. The tag line is "Write once, run anywhere". A GREAT idea (if it works). The Java program is as follows (the file name was hello.java):
/* Program to print "hello, world"                  */
/* L Taber   September 4, 1997   PCC                */
/* Converted to Java                                */
/* Kernighan & Richie "The C Programming Language"  */
/* Copyright 1978  page 6                           */
class Helloworld 
{
public static void main(String args[])
  {
  System.out.println("hello, world");
  }
} 
To compile the program:
javac hello.java
To run the program with the java byte code interpreter you need to give the class name. The Java compiler should have produced a file with the name Helloworld.class. For example:
java Helloworld

Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site

Up Next