Lesson 2 -- Keywords


Our Sample Macro

Here is the sample macro we are working with in this chapter:

  PROGRAM test;
    BEGIN
      wrterr ('Hello World!');
      pause (5.0);
    END test.

Identifiers

An identifier is a word used to reference a variable, procedure, or function, or parameters for those procedures or functions. You can create your own identifiers, and DCAL has some that are pre-defined. Valid identifiers begin with a letter and can then contain letters, numbers or underscores. Identifiers can be up to 20 characters long.

Valid identifiers include:

  Identifier_name

  a2345

  variable_one

Invalid identifiers would be:

  2345A {starts with a number}

  _variable_one {starts with an underscore}

  total_of_1&2 {contains invalid character}

  abcdefghijklmnopqrstuvwxyz {identifier name is too long}

All of this sounds more complicated than it really is. Lets say you create a variable to hold a value. This value represents the width of a window. Rather than naming this variable something like 'X' or 'I' you would use an identifier such as 'Window_Width' This will make your code much more readable and easy to follow. The same idea holds true for procedures and functions.

We will discuss Variables, Procedures, Functions, and Parameters much more as we progress. For now it is simply enough to remember the rules for valid identifier names.

Keywords

Keywords are words that have a specific purpose in DCAL. They are not Identifiers but rather words reserved by DCAL for specific purposes. These are the heart and soul of the language and direct the compiler how to work with your source code.

The list of keywords is:

and

array

begin

by

const

do

else

elsif

end

external

false

for

function

if

in

include

message

mod

module

not

of

off

on

or

out

procedure

program

public

record

repeat

return

string

then

to

true

type

until

var

while

These keywords cannot be used by you for any of your identifiers. What this means is that if you try to create a variable or procedure named 'array' you will get compiler errors.

All of these words have very special uses that will become more clear to you as you learn more.

In our example we should now see three keywords. PROGRAM, BEGIN and END are all keywords. Lets look at what each does in our example.

The first line begins with PROGRAM. As you learned in the last section the macro begins with a header that determines whether the code is a PROGRAM or a MODULE. In our example the code is a PROGRAM. If this piece of code was one of many modules in your program it could have started with the MODULE keyword. However, since it is the only code for this macro it must start with the PROGRAM keyword. All keywords tell the compiler important information. The PROGRAM keyword tells the compiler that this is either the first or only code module that we will be compiling.

The next keyword in our listing is BEGIN. This does exactly what you may think. It tells the compiler that this is where to begin. Statements following the BEGIN keyword are executed in the order they are listed. As you will learn later you can change the order the statements are executed.

The final keyword in the listing is END. As you might expect this tells the compiler this is where the program ends. The END keyword can be used in many different places in your code. It will always be used to terminate a sequence of operations. All source code listings whether they are PROGRAMs or MODULEs must end with the keyword END. If the listing is a PROGRAM the END keyword will be followed by the name of the macro (in our case Test) and a period. The syntax is different for use in MODULES but we will cover that later.

Program Statements

Up to this point, we have covered all the standard portions of our code listing. The remaining lines are the parts that will differ from macro to macro. This is where the actual work of the program will be done. All programs must contain the Header, and the Begin and End keywords. They must also contain some Program Statements if they are to do any real work. In our example the lines:

  wrterr ('Hello World!');
  pause (5.0);

are the Program Statements. These statements can be very simple and brief, as in our example, or much more elaborate. These statements are executed in the order they are listed unless you use other methods to control your program flow. We will cover program flow in future lessons.

The first line of the statements is a typical procedure call statement. What this line does is call the WRTERR procedure and tell it to display the 'Hello World!' string on the screen. WRTERR is a procedure that is built in to DCAL. Since it is built in you can use it without knowing how it works or exactly how it does what it does. You can also call your own Procedures in your statements. However if you want to call your own procedures you will need to define them in your code so that the compiler knows about them.

PAUSE is another built in Procedure. It simply pauses the macro operation for a length of time.

Your DCAL manual is filled with built in Procedures and Functions. As you learn more you will become comfortable with these built in routines. In order to create more than the simplest macros you will need to become acquainted with many different types of built in procedures as well as create your own.

< Previous   |   Continue >

Table of Contents



Thank you for printing this page. Please feel free to contact us for further assistance. You can call our sales department at +1 (800) 394-2231, Monday through Friday from 8:00 a.m. to 5:00 p.m. Eastern time or send an e-mail message to info@datacad.com.