Tuesday, February 18, 2014

More macro Phun

Many believe syntax of C + + is weird, a bit unintuitive, ugly, cryptic and obfuscated. Some are pointing out the Pascal syntax as an opposite parallel.
Let’s note that the Pascal language was initially developed by N. Wirth as an educational language. This language demonstrates such conceptual peculiarities, like strict typing and availability of means of structured (procedural) programming. And, by N. Wirth, this language should facilitate forming of a good style of algorithmic thinking, and, thus, programming. In particular, the author tried to make its syntax intuitively clear even at the first acquaintance with the discipline “Programming”.
During long time Pascal was fairly considered one of the best programming languages for education purposes. Unfortunately, the versions of programming environments, which were used to teach the language (Turbo Pascal, Borland Pascal), have become outdated.
New programming systems, which are based on Pascal, for example, Delphi, are too expensive and industrially, not educationally, oriented. Particularly, the programming environment is poorly suitable to teach basic programming and algorithmization due to its complexity. Well..you can use C++ to write in whatever language you like.Well not exactly, but pretty much. Here's an example of a fun proggie I wrote.
It demonstrates nested procedures, which aren't present in the actual Pascal.



#include "Pascal.h"

Program Project1
begin

var
Integer(U) = 7;
Single(x) = Single(U / 1.51);
String(str) = "cool";
 
WriteLn(str);
WriteLn("Input a symbol : ");
Read(U); 

if U > 5 then 
begin 
 WriteLn("Pascal rulez !!");
 Exit(0); 
end 
else
 begin
   WriteLn("C rockz!");
 end;
 
 for U = 0 to U < 10 do  
 begin
    WriteLn("C++ powns all ");
    Inc(U,1); 
 end;
 
 procedure NestedProc 
 begin
   var 
   String(s); //4astna  promenliva
 
    Begin
        s = "Hello from a nested proc ";
        WriteLn(s);
    End; 

  end NestedProc; 

 NestedProc.exec();
 
 Exit(0);
 
end


Here's how the header Pascal.h looks like.
using namespace std;
#include 
#include 
#define Integer int
#define Single float
#define Pointer void*
#define begin {
#define end }
#define end; }
#define WriteLn(str) printf(str)
#define Program int main(int argc, char *argv[])
#define Project1 
#define if if(
#define then )
#define Exit return
#define Result(x) return x
#define Integer(x) int x
#define do ;)
#define for for(
#define Inc(x,y) x += y
#define to ;
#define Read(x) scanf("%u",&x)
#define String(name) char* name
#define Pointer(p) void* p
#define procedure struct
#define Begin void exec(){
#define End };                                   
#define var   
#define Addr(x) &x
#define deAddr(x) *x
                                  
                                       

No comments:

Post a Comment