Modern Pascal Language Syntax

Modern Pascal follows the common structure of other Pascal dialects. Pascal is a procedural programming language, designed in 1968 and published in 1970 by Niklaus Wirth and named in honor of the French mathematician and philosopher Blaise Pascal. Pascal runs on a variety of platforms, such as Windows, Mac OS, and various versions of UNIX/Linux.

This tutorial will give you great understanding of Pascal to proceed with Modern Pascal and other related frameworks etc.

Audience

This tutorial is designed for Software Professionals who are willing to learn Pascal Programming Language in simple and easy steps. This tutorial will give you the understanding of Modern Pascal Programming concepts, and after completing this tutorial, you will be at an intermediate level of expertise from where you can take yourself to higher level of expertise.

Prerequisites

Before proceeding with this tutorial you should have an understanding of software basic concepts like: what is source code, a compiler, text editor and execution of programs, etc. If you already have understanding on any other computer programming language, then it will be an added advantage to proceed.

Overview

Pascal is a general-purpose, high-level language that was developed for teaching programming as a systematic discipline and to develop reliable and efficient programs. Pascal offers several data types and programming structures. It is easy to understand and maintain Pascal programs.

Pascal has grown in popularity in the teaching and academia arena for various reasons:

Features of the Pascal Language

Pascal has the following features:
How Pascal is different from other languages:
Before we study the language, let us look at the bare minimum Pascal structure so we can take it as a reference in the upcoming language tutorials.

Pascal Program Structure

A Pascal program basically consists of the following parts (many are optional):
Every Pascal program generally has a header section, a declaration and an execution part structure in that order. Following format shows the basic syntax for a Modern Pascal program:
program HelloWorld;
uses display;

(* Here the main program block starts *)
begin
   WriteLn('Hello, World!'); { comment about this command }
   Readkey;
end.

Source Code Parts...

Looking at the above program source code:
To get a better understanding we will detail each of the basic building blocks of the pascal programming language.

Type Declarations

Type declarations provide you with the ability to extend or expand the variable types known by Modern Pascal. For example, a collection of characters is called a string, however, if you wanted to limit it to 20 characters maximum you could introduce a new string type of String[20]. Type declarations are normally defined at the beginning of your code with a type keyword, followed by definitions of the variable types as follows:
type type_name1=existing_definition;  // allows you to "rename" a type for your better understanding
   type_name2=new_definition;         // allows you to add a new type definition to Modern Pascal
   type_name3=array_structure;        // allows you to simplify interaction with an array type
   type_name4=record_structure;       // allows you to introduce a type of multiple variables
   type_name6=class_structure;        // allows you to introduce a type with associated methods

Variables

Variables hold data which can be changed during the operation of your program. Variable definitions are normally defined at the beginning of your code with a var keyword, followed by the type of the variable as follows:
var variable1:variable_type;
   variable2:variable_type;
   variable3, variable4:variable_type;

Functions and Procedures

In Pascal, a Procedure is a set of instructions to be executed that do not return a value, and a Function is a procedure which returns a value. The definition of each follows:
Procedure Proc_Name(optional_parameters...);

Function Func_Name(optional_parameters...):Return_Value_Type;

Comments

Pascal is the only language which supports 4 different styles of comments. As we have discussed and shown on the Program Structure page, you can use (* ... *) for single or multiple lines of comment, you can use { ... } for single and multiple lines of comment too and // the double slash for comment the rest of the current line.
(* This is an example of a single line comment in this style *)

(* This is an example of using this style for multi-line
    comments as it will span multiple lines. *)

{This is an example of a single line comment in this style}

{This is an example of this style for multi-line
comments as it will span multiple lines.}

// Lastly, this is a single line comment - or
var a:Integer; // comment the rest of this line, or about this line.

/* Modern Pascal also supports C/Java/JavaScript style of comments
   which use the slash asterisk combination instead of parenthesis
   asterisk combination (like formal Pascal) */

Case Sensitivity

Pascal is not a case-sensitive language, which means you can write your variables, function and procedure in either case. Like A_Variable, a_variable and A_VARIABLE all have the same meaning in Pascal. It is a good writing habit though to be consistent as if the language was case-sensitive for working with certain tools and learning/using other programming languages which usually are case-sensitive.

Statements

Pascal programs and units are made of statements. Each statement specifies a task or job of the program. These jobs could be declarations, assignment, calculations, reading or writing data, comparisons, making logical decisions, transferring program flow control, etc. All statements end with a semicolon:
WriteLn('Hello, World!');
Ch:=Readkey;
if (Ch=#27) then WriteLn('Goodbye.');

Naming Convention

In Pascal, types, class names, constants, variables, function names and procedure names following a strict naming convention: The following are reserved characters and cannot be used except for their explicate functionality(s):