Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language GPSS

Date:05/04/10
Author:Allen J. Kapusta
URL:n/a
Comments:0
Info:http://www.webgpss.com/, http://www.minutemansoftware.com/, http://www.wolverinesoftware.com/
Score: (4.50 in 2 votes)
	SIMULATE 1
*
* GPSS program to print lyrics of '99 bottles of beer'
* Written by Allen J. Kapusta
* WebGPSS version (The versions of GPSS have different syntax although the use
* of the blocks is similar). WebGPSS is a commercial product but a demo
* version is available.
* Uses a 'final' transaction to end the simulation
* Limitations on the PRINT statements result in extra newlines and
* decimal digits.
*
	GENERATE ,,,99,2	; Beer bottles
* The 'bottle' transactions start at priority 2 to build the 'wall' queue,
* then drop to priority 1 to allow all bottles to enter the queue before 
* the 'bar' facility is occupied.
	ARRIVE	WALL
*                             Add bottle to 'wall' queue			
	PRIORITY 1
*                             Allow other bottles to enter queue
	SEIZE	BAR
*                             Bottle is being poured
	PRINT	' ',Q$WALL
*                             Number of bottles, including this one
	IF	Q$WALL=1,BLOCKA
*                             Singular or plural?
	PRINT	' bottles of beer on the wall, ',Q$WALL
	PRINT	' bottles of beer.'
	GOTO	BLOCKB
BLOCKA	PRINT	' bottle of beer on the wall, ',Q$WALL
	PRINT	' bottle of beer.'
BLOCKB	DEPART	WALL
*                             Remove from 'wall' queue
	PRINT	'Take one down and pass it around,'
	IF	Q$WALL<2,BLOCKC
*                             Plural or other?
	PRINT	' ',Q$WALL
*                             Number of bottles, excluding this one
	PRINT	' bottles of beer on the wall.'
	GOTO	BLOCKE
BLOCKC	IF	Q$WALL=0,BLOCKD
*                             One or zero?
	PRINT	' 1 bottle of beer on the wall.'
	GOTO BLOCKE
BLOCKD	PRINT	' no more bottles of beer on the wall.'
BLOCKE	PRINT	' '
	ADVANCE 10,5
*                             Wait for bottle to empty
	RELEASE BAR
*                             Allow next bottle to be poured
	TERMINATE
*                             Bottle transaction complete
*
	GENERATE ,,1,1,0
*                             Final transaction
	WAITIF	BAR=U
*                             Wait until no more bottles
	PRINT	'No more bottles of beer on the wall,'
	PRINT	' no more bottles of beer.'
	PRINT	'Go to the store and buy some more,'
	PRINT	' no more bottles of beer on the wall.'
	TERMINATE 1
*                             Simulation complete
*
	START	1
*                             Run simulation until 1 "final" transaction ends
END

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: