Jump to content
IGNORED

I almost missed National "Drink Beer Day" but...


TheBF

Recommended Posts

I found out late in the day that yesterday was national beer drink day.

 

https://www.daysoftheyear.com/days/drink-beer-day/

 

Thankfully I had just enough time to enjoy a very dark ale from Ireland while watching TV.

 

In honour of this auspicious day, I thought I would take the opportunity to show how you can create your own language in Forth. (Of course I had to tie that in)

 

Here is a program written in my new language called BREWER

: BEERS ( n -- )   \ Usage:  99 BEERS
      POPONE
      DRINK
         HOWMANY BOTTLES OF BEER ON THE WALL ,
         HOWMANY BOTTLES OF BEER ,
         TAKE ONE DOWN PASS IT AROUND ,
         ONELESS BOTTLES OF BEER ON THE WALL .
      ANOTHER 
      HANGOVER ;

And on the off chance that anyone cares... here is the source code for the language. :-)

 

 

 

\ 99 bottles of beer.  Create a beer language and write the program

DECIMAL
: CASE    ( -- 0 )  0  ; IMMEDIATE
: OF      ( -- )   POSTPONE OVER   POSTPONE =   POSTPONE IF  POSTPONE DROP  ; IMMEDIATE
: ENDOF   ( -- )   POSTPONE ELSE ; IMMEDIATE
: ENDCASE ( -- )   POSTPONE DROP   BEGIN ?DUP WHILE  POSTPONE THEN   REPEAT ; IMMEDIATE

: BOTTLES ( n -- )
        DUP
        CASE
         1 OF    ." One more bottle " DROP ENDOF
         0 OF    ." NO MORE bottles " DROP ENDOF
                 . ." bottles "    \ DEFAULT CASE
        ENDCASE ;

: ,   [CHAR] , EMIT  SPACE 100 MS CR ;
: .   [CHAR] . EMIT  300 MS  CR CR CR ;

: HANGOVER    ." :-("  CR QUIT ;

: OF       ." of "   ;
: BEER     ." beer " ;
: ON       ." on "   ;
: THE      ." the "  ;
: WALL     ." wall" ;
: TAKE     ." take " ;
: ONE      ." one "  ;
: DOWN     ." down, " ;
: PASS     ." pass " ;
: IT       ." it "   ;
: AROUND   ." around" ;

: POPONE    1 SWAP CR ;
: DRINK     POSTPONE DO ; IMMEDIATE
: ANOTHER   POSTPONE -1  POSTPONE +LOOP ; IMMEDIATE
: HOWMANY   S" I " EVALUATE ; IMMEDIATE
: ONELESS   S" I 1- " EVALUATE ; IMMEDIATE

 

 

 

Please drink responsibly

 

 

 

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...