The Department of Computer Science & Engineering |
STUART C. SHAPIRO: CSE
305
|
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.
PROGRAM
,
SUBROUTINE
s, and FUNCTION
s.
PROGRAM
module.
main
.
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:
<head> :- <body> .
<head> .
:- <body> .
<body> .
user
.
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 |