The Department of Computer Science & Engineering
cse@buffalo

CSE 305
Programming Languages
Lecture Notes
Stuart C. Shapiro
Spring, 2005


The Program Level

It is interesting to compare programming languages on the characteristics of:

For Fortran, C, C++, and Java, the top-level structure, aside from some compiler directives such as import and #define, is the definition of program/subprogram modules.

C, C++, Fortran, and Java are all compiled languages. You must compile the program and executed the compiled version (even if, as for Java, it is not actually machine code). When you run the compiled program:

For Perl, the top-level structure of a program is a sequence of executable statements and subroutine definitions. When the program is run, the statements are executed. If you run the Perl interpreter by invoking perl with no command line options or arguments, the program is taken from standard input, and run when eof is reached.

For bash, the top-level structure of a program is a sequence of statements, called "commands", which include function definitions. When the program is run, the statements are executed. If you run the interpreter with no command line options or arguments, you enter an interactive read-eval-print loop, in which each statement you enter is immediately executed.

For Python, the top-level structure of a program is a sequence of executable expressions and statements, which include function and class definitions. When the program is run, the statements and expressions are evaluated in order. If you run the interpreter with no command line options or arguments, you enter an interactive read-eval-print loop, in which each statement you enter is immediately executed, and each expression you enter is immediately evaluated and its value is printed.

For Prolog, the top-level structure is the definition of subprogram modules, which Prolog calls "procedures", and are, in fact, relations. Each procedure/relation is defined by a sequence of clauses. Each clause must be one of the following:

To run a Prolog program (with minimal command-line options), you run the Prolog interpreter, which puts you in an interactive read/eval/print loop, where the input must be a The Prolog interpreter prints instances of the relation(s) you ask about.

For Common Lisp, the top-level structure of a program is a sequence of executable expressions, which include function and class definitions. When the program is run, the expressions are evaluated, and their values are printed. If you run the interpreter with no command line options or arguments, you enter an interactive read-eval-print loop, in which each expression you enter is immediately evaluated, and its value is printed.

This can all be summarized by the following table:
Language Top-Level Structure When Run Program When Run w/o Program
Fortran Module definitions Execute PROGRAM N/A
C Module definitions Execute main N/A
C++ Module definitions Execute main N/A
Java Module definitions Execute main N/A
Perl Module definitions and Statements Execute statements Enter program, then run it
bash Statements Execute statements Interactively execute statements
Python Statements and expressions Execute statements and evaluate expressions Interactively execute statements and evaluate expressions
Prolog Module definitions N/A Interactively evaluate queries
Common Lisp Expressions N/A Interactively evaluate expressions

First Previous

Copyright © 2005 by Stuart C. Shapiro. All rights reserved.

Stuart C. Shapiro <shapiro@cse.buffalo.edu>