I will use Free Pascal as it is free to download and use at: http://www.freepascal.org
Current version I am using is 2.6.0 and the commands I am using compiled under it.
I am going to make foolish assumptions that the user has installed it and read the documentation. That they are using a text editor and know how to edit text and save as a file.
Bare with me as I am relearning this all over again. I got started in Pascal in
1985 in High School and then later college.
The first program is a hello world program and looks like this:
If you note Pascal likes to make use of the semi-colon. The first line defines the program by name, in this case "HelloWorld" notice that Pascal naming conventions require an uppercase letter for the beginning of each word and no spaces between words. A space between Hello and World would result in an error.
The capital letters are there to make it easier to spot each word and keep track of it.
The semi-colon tells the Pascal compiler where the line stops. In this case:
The reserved word "program" defines the start of the program, after that the program is named, after the name is a semi-colon.
You will notice the reserved words begin and end, this marks the beginning and end of the main area of the program. You will notice that end uses a period instead of a semi-colon to tell the compiler where the program ends.
I should point out now, that reserved words are special words used by the compiler and cannot be used as names for functions, procedures, variables and the like which you will learn later on. You have already learned "program", "begin", "end" so far and the next one to learn is "writeln".
The procedure "writeln" writes a line of text to the console and then adds a carriage return and line feed or whatever your console terminal or screen as some call it uses to advance to the next line.
Notice we are using single quotes between the string we are printing out, in this case "Hello World" is 'Hello World' as opposed to other programming languages. The Semi-Colon tells the compiler to end at that line. We could have
put anything in that area like:
writeln('Welcome to Pascal!');
But most programming lessons begin with a hello world program.
I hope I have explained the Free Pascal programming format, and that the reader
is able to compile the program and run it to get the screen:
Printed out like so:
You will note that in this example I am using the Windows version of the Free Pascal 2.6.0 compiler, I used a command prompt, and I changed to the directory it was installed in and ran the 64 bit version ppcrossx64 program and saved my source code as hello.pas in that directory. It generated a hello.o and hello.exe file and when I typed hello it ran the hello.exe program.
Now some antivirus programs may flag this program as having a low reputation, because you just compiled it, and nobody was able to send them a review of it yet. There is no virus, but if you have Avast! you can safely run it in a sandbox if you like. The file prevalence/reputation is low is a possible message you will get. This is a new system some antivirus programs are using where the file is rated in their database and if there is no rating it will flag a warning like that. Just thought I'd let you know ahead of time. Just choose "Open in Sandbox" as we aren't really doing anything with this program besides printning text to the screen.
The hello.exe file is clean, and the hello.o file is an object file that was compiled by Free Pascal and then linked to an EXE file. If paranoid feel free to scan them, but they were created by the Free Pascal Compiler.
If there is more interest I can post another lesson on Free Pascal.
--- BBBS/Li6 v4.10 Dada-1
* Origin: Prism bbs (1:261/38)