The Picky Programming Language v2

Picky is a programming language intended for a first course on computer programming. It is more similar to a bicycle with two side-wheels than it is to a motor-bike. You won't probably use it unless you are using it for your first steps in programming.

The compiler generates byte-code, interpreted by an abstract machine for portability. The language is utterly picky, hence its name, by design.


This is an example program:

program Word;

consts:
	Maxword = 30;

types:
	Tindchar = int 1..Maxword;
	Tchars = array[Tindchar] of char;
	Tword = record{
		chars: Tchars;
		nchars: int;
	};

function isblank(c: char): bool
{
	return c == ' ' or c == Tab or c == Eol;
}

function nc(w: Tword): int
{
	return w.nchars;
}

procedure skipblanks(ref end: bool)
	c: char;
{
	do{
		peek(c);
		if(c == ' ' or c == '	'){
			read(c);
		}else if(c == Eol){
			readeol();
		}
	}while(not eof() and isblank(c));
	end = eof();
}

procedure readword(ref w: Tword)
	c: char;
{
	w.nchars = 0;
	do{
		read(c);
		w.nchars = w.nchars + 1;
		w.chars[w.nchars] = c;
		peek(c);
	}while(not eof() and not isblank(c));
		
}

procedure writeword(w: Tword)
	i: int;
{
	write("'");
	for(i = 1, i <= w.nchars){
		write(w.chars[i]);
	}
	write("'");
}

procedure initword(ref w: Tword)
	i: int;
{
	w.nchars = 0;
	for(i = 1, i <= Maxword){
		w.chars[i] = 'X';
	}
}

procedure main()
	done: bool;
	w: Tword;
	max: Tword;
{
	initword(w);
	initword(max);
	do{
		skipblanks(done);
		if(not done){
			readword(w);
			if(nc(w) > nc(max)){
				max = w;
			}
		}
	}while(not eof());
	writeword(max);
	write(" with len ");
	writeln(nc(max));
}

This is an example graphical program (bouncing ball):

program ball;

/*
 * Graphical example program. Clasical bouncing ball in a rectangle.
 */

types:
	TypeVect = record {
		x: int;
		y: int;
	};

	TypeBall = record {
		pos: TypeVect;
		speed: TypeVect;
	};

consts:
	TQuantum = 50; /* milliseconds */
	SpeedScale = 50; /* divisor for milliseconds */
	SizeX = 5000;
	SizeY = 5000;
	SpeedX = -20;
	SpeedY = 43;
	BallRad = 100;
	Ball = TypeBall(TypeVect(BallRad, BallRad), TypeVect(SpeedX, SpeedY));

function sumvect(v1: TypeVect, v2: TypeVect): TypeVect
	s: TypeVect;
{
	s.x = v1.x+v2.x;
	s.y = v1.y+v2.y;
	return s;
}

function scalevect(v: TypeVect, l: int): TypeVect
	s: TypeVect;
{
	s.x = v.x*l;
	s.y = v.y*l;
	return s;
}

procedure reflect(ref b: TypeBall)
{
	if(b.pos.x < 0){
		b.pos.x = 0;
		b.speed.x = -b.speed.x;
	}else	if(b.pos.x > SizeX){
		b.pos.x = SizeX;
		b.speed.x = -b.speed.x;
	}
	if(b.pos.y < 0){
		b.pos.y = 0;
		b.speed.y = -b.speed.y;
	}else	if(b.pos.y > SizeY){
		b.pos.y = SizeY;
		b.speed.y = -b.speed.y;
	}
}

procedure update(ref b: TypeBall)
{
	b.pos = sumvect(b.pos, scalevect(b.speed, TQuantum/SpeedScale));
	reflect(b);
}

procedure drawball(g: file, ref b: TypeBall)
	x: int;
	y: int;
{
	gfillcol(g, Green, Opaque);
	gpencol(g, Red, Opaque);
	gpenwidth(g, 1);
	x = b.pos.x;
	y = b.pos.y;
	
	gellipse(g, x, y, BallRad, BallRad, 0.0);
}

procedure main()
	b: TypeBall;
	g: file;
	k: char;
{
	b = Ball;
	gopen(g, "ball");
	do{
		update(b);
		gclear(g);
		drawball(g, b);
		fflush(g);
		gkeypress(g, k);
		sleep(TQuantum);
	}while(not feof(g) and k != 'q');
	gclose(g);
}