Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pascalated ZX BASIC Demo
#1
To run online, click here: RUN ONLINE


Code:
' PROGRAM factorials
' Demo for the Pascalated language
' Language: Pascalated ZX BASIC (BORIEL) (compiled)
' Pascalated Sinclair BASIC (c) 1987 by ZarSoft
' Pascalated Boriel (c) 2023 by ZarSoft
' ZX BASIC compiler was created by Boriel

#include <input.bas>

'--- Pascalated Boriel ---
#define VAR       DIM
#define INTEGER   LONG
#define REAL      FLOAT
#define TYPE      AS
#define REPEAT    DO
#define UNTIL     LOOP UNTIL
#define PROCEDURE SUB
#define PROGRAM   REM

REM Variable declarations
REM VAR - Global variables
REM Uppercase are different from lowercase
VAR limit TYPE INTEGER : REM max argument to build the list

PROCEDURE Introduction
CLS
PRINT AT 13,0
PRINT "+-----------------+"
PRINT "| factorial list  |"
PRINT "+-----------------+"
PRINT " Demonstration for"
PRINT " Pascalated ZX BASIC (Boriel)"
PRINT " (c) 2023 by Zarsoft"
PRINT
PRINT
END PROCEDURE

PROCEDURE GetLimit
REPEAT
  PRINT "Max argument = ";
  limit = VAL( INPUT(9) ) : PRINT limit
  IF limit >= 12 THEN
    PRINT
    PRINT "Must be lower than 34."
    PRINT "Try again."
    PRINT
  ELSE IF limit < 0 THEN
    PRINT
    PRINT "Must be greater than 0."
    PRINT "Try again."
    PRINT
  ELSE
    PRINT
    PRINT "Valid input."
    PRINT
  END IF
UNTIL (limit >= 0) AND (limit <= 33)
END PROCEDURE

FUNCTION CalculateFactorial (argument TYPE INTEGER) TYPE REAL
VAR result TYPE REAL
LET result = 1
WHILE argument > 1
  LET result = result * argument
  LET argument = argument-1
END WHILE
RETURN result
END FUNCTION

PROCEDURE WriteFactorials
VAR w TYPE INTEGER
VAR argument TYPE INTEGER
VAR result TYPE REAL
PRINT
FOR w = limit TO 0 STEP -1
  LET argument = w
  PRINT "fact(";argument;") = ";
  result = CalculateFactorial(argument)
  PRINT result
NEXT w
END PROCEDURE

PROCEDURE MainPROCEDURE
Introduction
GetLimit
REPEAT
  WriteFactorials
  PRINT
  PRINT "Write 0 to terminate."
  GetLimit
UNTIL limit = 0
END PROCEDURE

PROGRAM factorials
MainPROCEDURE
PROGRAM END
Reply
#2
This is super interesting!
Is this tool online!?
Reply
#3
It's not a tool, it's a trick - you just need to put these lines at the beginning of the program:

'--- Pascalated Boriel ---
#define VAR DIM
#define INTEGER LONG
#define REAL FLOAT
#define TYPE AS
#define REPEAT DO
#define UNTIL LOOP UNTIL
#define PROCEDURE SUB
#define PROGRAM REM
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)