0% found this document useful (0 votes)
93 views34 pages

Basic Operation of Plato

This document provides an overview of the basic operation and elements of the Plato programming language. It discusses that a Plato program has a declaration section and an executable section. The declaration section defines variables and parameters, while the executable section contains statements that perform operations. The executable section can be thought of as having input, processing, and output blocks.

Uploaded by

Yoga Kj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
93 views34 pages

Basic Operation of Plato

This document provides an overview of the basic operation and elements of the Plato programming language. It discusses that a Plato program has a declaration section and an executable section. The declaration section defines variables and parameters, while the executable section contains statements that perform operations. The executable section can be thought of as having input, processing, and output blocks.

Uploaded by

Yoga Kj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 34

Basic Operation of Plato

• The program comprises two sections: declaration


and executable.
• The declaration section consists of statements that
define variables and parameters used in your
program. These immediately follow the program
statement (this just has the name of your program)
and come before all executable statements.
• The executable section consists of statements that
actually do something
e.g. the read statement reads in data from the
keyboard or a data file. The executable statement: y=
x**2 +4*x -12 computes the variable y from the
value of x.
• Finally, we have the end statement.
• We may also regard the executable section as
comprising three generic blocks: input, processing and
output.
• The input block is the read statement – this allows us
to input data into the program.
• The statement: y= x**2 +4*x -12 is the processing
block. Here we perform operations on (process) x to
get y.
• Finally, the write statements constitute the output
block – we need to view our results, in this case the
value of y.
What does this example program do?

• Well, it prints a couple of informative messages on the computer screen


(write) and waits for you to enter a real (floating point) number (read) e.g.
3.0 (note that if you enter 3 it is interpreted as 3.0). The statement: read(*,
*) x means read from the keyboard and the number will be interpreted
from its declaration i.e. real. This number is assigned to the variable x
• Then the statement: y= x**2 +4*x -12 computes the variable y – in this
case, y would be 9.00000. Finally, the values of x and y are written on the
screen (write).
• For illustration, this is done in free format and then by a user-defined
format. The first approach involving write(*,*) is convenient - this means
write to the screen in a default way - while the second approach using the
two statements write(*,10)x,y and 10 format allows greater control over
the written output. Note that the connecting statement number or label
(10) for the second approach.
Elements of FORTRAN: Basic Terms
Some of the FORTRAN basic terms and concepts are:

• A program consists of one or more program units.

• A program unit is a sequence of statements, terminated by an END.

• A statement consists of zero or more key words, symbolic names, literal constants,
statement labels, operators, and special characters.

• Each key word, symbolic name, literal constant, and operator consists of one or more
characters from the FORTRAN character set.

• A character constant can include any valid ASCII character.

• A statement label consists of 1 to 5 digits, with at least one nonzero .


Elements of FORTRAN: Character Set

• The character set consists of the following:


• Uppercase and lowercase letters, A - Z and a - z
• Numerals 0 - 9
• Special characters--The following list shows some special characters:
Elements of FORTRAN: Charater Set
• = Equals Assignment
• + Plus Adds
• - Minus Subtracts
• * Asterisk Multiply, alternate returns, comments, exponentiation, stdin, stdout, list-directed I/O
• / Slash Divide, delimit data, labeled commons, structures, end-of-record
• () Parenthesis Enclose expressions, complex constants, equivalence groups, formats, argument
lists, subscripts
• , Comma Separator for data, expressions, complex constants, equivalence groups, formats,
argument lists, subscripts
• . Period Decimal point, delimiter for logical constants and operators, record fields
• ‘ Apostrophe Quoted character literal
• ! Exclamation Comments
Elements of FORTRAN: Simbolic Names

• Symbolic names can be any number of characters long. The standard is 6.


• Symbolic names consist of letters, digits, the dollar sign ($), and the underscore character (_). $ and _ are
not standard.
• Symbolic names generally start with a letter--never with a digit or dollar sign ($). Names that start with an
underscore (_) are allowed, but may conflict with names in the Fortran and system libraries.
• Uppercase and lowercase are not significant; the compiler converts them all to lowercase.
Example: These names are equivalent:
SFCPRS = 1013.25
sfcprs = 1013.25
• The space character is not significant.
• Example: These names are equivalent:

IF(PRES.LT.SFCPRS) GO TO 1
IF (PRES .LT. SFCPRS) GO TO 1
Elements of FORTRAN: Symbolic Names

• Examples of symbolic names:


Valid Invalid
• X2 2X Starts with a digit
• DELTA_T _DELTA_T Starts with an _ (Reserved for the compiler)
• Y$DOT Y|DOT There is an invalid Character |

• In general, for any single program unit, different entities cannot have the same symbolic name.

• Throughout any program of more than one programming unit, no two of the following can have the same name:
Block data subprograms
Common blocks
Entry points
Function subprograms
Main program
Subroutines
Elements of FORTRAN: Programs and Statements

• Program
A program unit is a sequence of statements, terminated by an END statement. Every program unit is either a main
program or a subprogram. If a program is to be executable, it must have a main program.There are three types of
subprograms: subroutines, functions, and block data subprograms. The subroutines and functions are called procedures,
which are invoked from other procedures or from the main program. The block data subprograms are handled by the
loader.
• Statements
A statement consists of one or more key words, symbolic names, literal constants, and operators, with appropriate
punctuation. In FORTRAN, no keywords are reserved in all contexts. Most statements begin with a keyword; the
exceptions are the statement function and assignment statements.
• Executable or Nonexecutable Statements
Every statement is either executable or nonexecutable. In general, if a statement specifies an action to be taken at
runtime, it is executable. Otherwise, it is nonexecutable.The nonexecutable statements specify attributes, such as type
and size; determine arrangement or order; define initial data values; specify editing instructions; define statement
functions; classify program units; and define entry points. In general, nonexecutable statements are completed before
execution of the first executable statement.
Elements of FORTRAN: Fortran Statements

• ACCEPT* ASSIGN* Assignment* AUTOMATIC


• BACKSPACE* BLOCK DATA BYTE
• CALL* CHARACTER CLOSE* COMMON COMPLEX CONTINUE*
• DATA DECODE* DIMENSION DO* DO WHILE* DOUBLE COMPLEX DOUBLE PRECISION
• ELSE* ELSE IF* ENCODE* END* END DO* END FILE* END IF* END MAP END STRUCTURE END UNION ENTRY EQUIVALENCE EXTERNAL
• FORMAT FUNCTION
• GOTO* GOTO (Assigned)* GOTO (Unconditional)*
• IF (Arithmetic)* IF (Block)* IF (Logical)* IMPLICIT INCLUDE INQUIRE* INTEGER INTRINSIC
• LOGICAL
• MAP
• NAMELIST
• OPEN* OPTIONS
• PARAMETER PAUSE* POINTER PRINT* PRAGMA PROGRAM
• REAL RECORD RETURN* REWIND*
• SAVE Statement Function STATIC* STOP* STRUCTURE SUBROUTINE*
• TYPE UNION VIRTUAL VOLATILE WRITE*

The asterisk (*) in the table indicates an executable statement.


Elements of FORTRAN: Fixed Format
• The standard fixed format source lines are defined as follows:
• The first 72 columns of each line are scanned.
• The first five columns must be blank or contain a numeric label.
• Continuation lines are identified by a nonblank, nonzero in column 6.
• Short lines are padded to 72 characters.
• Long lines are truncated.

• Comments and Blank Lines:


• A line with a c, C, *, d, D, or! in column one is a comment line.The d, D, and! are nonstandard.
• If you put an exclamation mark (!) in any column of the statement field, except within character literals,
then everything after the ! on that line is a comment.
• A totally blank line is a comment line.
Data Types

• Rules for Data Typing


The name determines the type; that is, the name of a datum or
function determines its data type, explicitly or implicitly, according to
the following rules:
Data Types
• The first letter of the name determines the data type implicitly.
• The default implicit typing rule is that if the first letter of the name is
I, J, K, L, M, or N, then the data type is integer, otherwise it is real.
Example:

GOD is REAL
… unless you specify it as an integer!
CONSTANTS

• CHARACTER: ‘FILEN’
• INTEGER: 3, -9999, 1e10
• Must be in the range (-2147483648, 2147483647).
• REAL: 3.3, -9999., 1.5e8, 1e-3
• Must be in the range (1.175494E-38, 3.402823E+38)
• Real*8: 6D2, -25.3D-7
• Must be in the range (2.225074D-308, 1.797693D+308)
• Real*16: 6Q2, -25.3Q-7
• Must be in the range (3.362Q-4932, 1.20Q+4932)
• COMPLEX: (1,-2) or (1.3,0.4)
• LOGICAL: .TRUE. and .FALSE.
Variables & Arrays

• Variables: A variable is a symbolic name paired with a storage location. A


variable has a name, a value, and a type. Whatever datum is stored in the
location is the value of the variable.
• Arrays: An array is a named collection of elements of the same type. It is a
nonempty sequence of data and occupies a group of contiguous storage
locations. An array has a name, a set of elements, and a type. You can declare an
array in any of the following statements:
• DIMENSION statement
• COMMON statement
• Type statements: BYTE, CHARACTER, INTEGER, REAL, and so forth
Variables & Arrays

• Arrays: Examples:
• DIMENSION LEVEL(10), T(72,73)
• REAL CORR(-3:3)
• In this case, CORR has 7 elements, with CORR(0)
being the 4 th element.
Expressions

• An expression is a combination of one or more operands, zero or


more operators, and zero or more pairs of parentheses. There are
three kinds of expressions:
• An arithmetic expression evaluates to a single arithmetic value.
• A character expression evaluates to a single value of type character.
• A logical or relational expression evaluates to a single logical value.
Expressions

• Arythmetic operators:
• ** Exponentiation
• * Multiplication
• / Division
• + Addition or Unary Plus
• -Subtraction or Unary Minus
• Precedence from left to right: 1) **, 2) *, /, 3) +, -, except when parenthesis
are involved
Expressions
• Character operators:
• // Concatenation:
• a//b, where a, b are characters, or ‘file’//’name’
• Logical operators:
• X.AND.Y Conjunction: Both X & Y are true
• X.OR.Y Disjunction: Either X or Y or both are True.
• …
• Relational operators:
• .LT. Less than
• .LE. Less than or equal
• .EQ. Equal
• .NE. Not equal
• .GT. Greater than
• .GE. Greater than or equal
Expressions

• A constant expression is made up of explicit constants and parameters and the


FORTRAN operators. Each operand is either itself another constant expression, a
constant, a symbolic name of a constant, or one of the intrinsic functions called
with constant arguments.Examples: Constant expressions:

• PARAMETER (L=29002), (P=3.14159), (C='along the ')


• PARAMETER ( I=L*2, V=4.0*P/3.0, S=C//'riverrun' )
• PARAMETER ( M=MIN(I,L), IA=ICHAR('A') )
• PARAMETER ( Q=6.4Q6, D=2.3D9 )
• K = 66 * 80
• VOLUME = V*10**3
• DO I = 1, 20*3
Elements of FORTRAN Statement
• Constant
• Variable
• Formula
• Verb

You might also like