We are still actively working on the spam issue.
Difference between revisions of "Pascal"
m (logo) |
(→Examples) |
||
Line 33: | Line 33: | ||
begin | begin | ||
Writeln('Hello World!') | Writeln('Hello World!') | ||
+ | end. | ||
+ | </pre> | ||
+ | |||
+ | === Bottles of Beer === | ||
+ | <pre> | ||
+ | program BottlesOfBeer; | ||
+ | |||
+ | function Count(Bottles: Integer): string; | ||
+ | begin | ||
+ | case Bottles of | ||
+ | 0: Count := 'No more bottles'; | ||
+ | 1: Count := '1 bottle'; | ||
+ | else | ||
+ | WriteStr(Count, Bottles, ' bottles') | ||
+ | end | ||
+ | end; | ||
+ | |||
+ | var | ||
+ | Bottles: Integer; | ||
+ | begin | ||
+ | for Bottles := 99 downto 1 do | ||
+ | begin | ||
+ | Writeln(Count(Bottles), ' of beer on the wall'); | ||
+ | Writeln(Count(Bottles), ' of beer'); | ||
+ | Writeln('Take one down, pass it around'); | ||
+ | Writeln(Count(Bottles - 1), ' of beer on the wall'); | ||
+ | Writeln | ||
+ | end | ||
end. | end. | ||
</pre> | </pre> |
Revision as of 19:47, 9 February 2014
Pascal is a highly-structured, strongly-typed programming language.
Pascal was originally designed by Dr. Niklaus Wirth, and was first published in 1970. It began as an extension to ALGOL, a programming language which Dr. Wirth had also helped to design. The language is named after the famous 17th-century French mathematician and philosopher Blaise Pascal.
In the 1970's and 80's, Pascal became very popular, particularly in the academic field. However, its popularity started to wane when many universities and businesses began using the newly created UNIX operating system, which was programmed in the C language. Many university classes and other users switched from Pascal to C to take advantage of the new system. Another major user of Pascal, Apple, would also eventually switch to C and Objective-C.
The Pascal language has been extended many times by different groups. Borland Turbo Pascal is among the better known extensions, featuring one of the fastest compilers for PCs at the time. Turbo Pascal also popularized the usage of object oriented programming in the Pascal language.
Contents
Modern implementations
Delphi
Embarcadero Delphi is a proprietary IDE which uses a dialect of Object Pascal, a much more developed object oriented dialect than that used in Borland Turbo Pascal.
Free Pascal
Free Pascal is a free and open source implementation which supports a wide variety of platforms. It features its own Object Pascal dialect similar to that of Delphi, as well as Delphi, Turbo, and Mac Pascal compatibility. The project also develops two IDEs: the text-based FreeVision IDE, and the Delphi-like Lazarus IDE.
GNU Pascal
GNU Pascal is another free and open source Pascal implementation, maintained as part of the GNU project and built upon GCC. It focuses more on supporting the ISO Pascal standards, with several features from ISO Standard and Extended Pascal which other modern Pascal dialects like Free Pascal and Delphi do not support.
The Dev-Pascal IDE supports the GNU Pascal dialect.
Installation
Free Pascal is probably the easiest to install and use, with or without the Lazarus IDE. You can find an easy installer for most platforms at the Free Pascal SourceForge page. You can also install it through your GNU/Linux or BSD package manager.
After the compiler is installed, you can type fpc myprogram.pas
in your terminal to compile the source file myprogram.pas
. By default, the resulting binary would be called myprogram
(or myprogram.exe
on Windows). Then you can run the program by typing ./myprogram
(or simply myprogram.exe
on Windows).
Examples
Hello World
program Hello; begin Writeln('Hello World!') end.
Bottles of Beer
program BottlesOfBeer; function Count(Bottles: Integer): string; begin case Bottles of 0: Count := 'No more bottles'; 1: Count := '1 bottle'; else WriteStr(Count, Bottles, ' bottles') end end; var Bottles: Integer; begin for Bottles := 99 downto 1 do begin Writeln(Count(Bottles), ' of beer on the wall'); Writeln(Count(Bottles), ' of beer'); Writeln('Take one down, pass it around'); Writeln(Count(Bottles - 1), ' of beer on the wall'); Writeln end end.