Previous Next Contents Index Doc Set Home


Lexical Elements

1


This chapter describes the symbols and words of a Pascal program. It contains the following sections:

Character Set

page 1

Special Symbols

page 2

Reserved Words

page 3

Identifiers

page 4

Comments

page 6


Character Set

Pascal uses the standard seven-bit ASCII character set, and the compiler distinguishes between uppercase and lowercase characters. For example, the following seven words are distinct from the predefined type integer:

Integer

INTEGer

INteger

INTEGEr

INTeger

INTEGER

INTEger

If you change the case of characters used in a word, the compiler does not recognize the word and gives an error.

The Pascal keywords and built-in procedure and function names are all in lowercase.

To map all keywords and identifiers to lowercase when you compile your program, use the following pc options:

-L

Maps all uppercase letters in keywords and identifiers to lowercase.

-s

Performs the same action as -L and also produces warning diagnostics for nonstandard constructs and extensions.

See the Pascal 4.2 User's Guide for a complete description of pc and its options.


Special Symbols

Pascal recognizes the following standard Pascal symbols and the nonstandard special symbols listed in Table 1-1.

+ - * / = < > [ ] . , :=
: ; ( ) <> <= >= .. ^

Table  1-1 Nonstandard Special Symbols  

Symbol
Description
Example

~

Bitwise not operator

~ 4

&

Bitwise and operator

4 & 3

|

Bitwise or operator

4 | 3

!

Bitwise or operator

4 ! 3

#

Specifies an integer value in a base other than base 10.

p := 2#10111; { base 2 }
f := 8#76543; { base 8 }

Includes a file in the program.

#include "globals.h"
#include "math_p.h"

Indicates a preprocessor command

#ifdef DEBUGGING
writeln('Total :',i,sum);
#endif

%

Indicates a cppas compiler directive

%var one, two
%enable two


Reserved Words

Pascal reserves the standard words in Table 1-2. You cannot redefine a reserved word to represent another item.

Table  1-2 Standard Reserved Words

Pascal Standard Reserved Words

and

file

mod

repeat

array

for

nil

set

begin

forward

not

then

case

function

of

to

const

goto

or

type

div

if

packed

until

do

in

procedure

var

downto

label

program

while

else

main

record

with

Pascal also reserves the nonstandard words in Table 1-3. These words are not treated as reserved words when you compile your program with any of the -s, -s0, -s1, -V0 or -V1 options.

Table  1-3 Nonstandard Reserved Words

Pascal Nonstandard Reserved Words

define

private

extern

public

external

static

module

univ

otherwise


Identifiers

In Pascal, you can include a dollar sign ($) and underscore (_) in an identifier name. The $ and _ can occur in any position of the identifier name. However, you should avoid using these characters in the first position because they may conflict with system names.

Pascal predeclares the standard identifiers in Table 1-4 and the nonstandard identifiers in Table 1-5.

Table  1-4 Predeclared Standard Identifiers

Pascal Predeclared Standard Identifiers

abs

false

page

sin

arctan

get

pred

sqr

boolean

input

put

sqrt

char

integer

read

succ

chr

ln

readln

text

cos

maxint

real

true

dispose

new

reset

trunc

eof

odd

rewrite

write

eoln

ord

round

writeln

exp

output

Table  1-5 Predeclared Nonstandard Identifiers

Pascal Predeclared Nonstandard Identifiers

FALSE

exit

lor

seek

TRUE

expo

lshft

shortreal

addr

filesize

lsl

single

alfa

firstof

lsr

sizeof

append

flush

max

stlimit

argc

getenv

maxchar

stradd

argv

getfile

message

string

arshft

halt

min

substr

asl

in_range

minchar

sysclock

asr

index

minint

tab

assert

integer16

next

tell

bell

integer32

null

time

card

intset

open

trace

clock

land

pack

trim

close

lastof

random

univ_ptr

concat

length

remove

unpack

date

linelimit

return

varying

discard

lnot

rshft

wallclock

double

longreal

seed

xor

You can redefine a predeclared identifier to represent another item. For example, you could redefine the predefined identifier next, a statement that causes the program to skip to the next iteration of the current loop, as a variable.

Once you redefine an identifier, you cannot use it as originally defined in the program, as shown in the following example:

The Pascal program, pred_iden.p, redefines the predeclared identifier next as an integer variable.

program predefined_identifier;

var
    i: integer;
    next: integer;

begin
    for i := 1 to 10 do begin
      if i > 5 then begin
          next
      end
    end
end. { predefined_identifier }

This program does not compile because next is declared as a variable, but used in its original definition as a statement.

hostname% pc pred_iden.p
Mon Feb 20 15:13:17 1995  pred_iden.p:
          10            next
E 18470-----------------^---  Replaced variable id with a 
procedure id
In program predefined_identifier:
E 18250 next improperly used on line 10


Comments

In Pascal, you can specify a comment in either braces, quotation marks, a parenthesis/asterisk pair, or a slash/asterisk pair:

{  This is a comment. }
(* This is a comment. *)
"  This is a comment. "
/* This is a comment. */
The symbols used to delimit a comment must match. For example, a comment that starts with { must end with }, and a comment that starts with (* must end with *).

You can nest comments in Pascal, that is, include one type of comment delimiter inside another:

{ This is a valid (* comment within a comment. *) }
(* This is a valid " comment within a comment. " *)
You cannot nest the same kind of comments. The following comments result in a compile-time error:

{  This is not a valid { comment within a comment. } }
(* This is not a valid (* comment within a comment. *) *)
"  This is not a valid " comment within a comment. " "
/* This is not a valid /* comment within a comment. */ */

Previous Next Contents Index Doc Set Home