diff --git a/assets/disk0/tbas/doc/bibliography.tex b/assets/disk0/tbas/doc/bibliography.tex deleted file mode 100644 index abf8798..0000000 --- a/assets/disk0/tbas/doc/bibliography.tex +++ /dev/null @@ -1,4 +0,0 @@ -\begin{itemlist} -\item Hagemans, Rob. 2020. ``PC-BASIC Documentation.'' Updated 2020-09-26 19:20:45. \url{https://robhagemans.github.io/pcbasic/doc/2.0/}. -\item Ahl, David H and North, Steve. 1978. \emph{BASIC Computer Games}. Microcomputer Edition. New York: Workman Pub. -\end{itemlist} diff --git a/assets/disk0/tbas/doc/commands.tex b/assets/disk0/tbas/doc/commands.tex deleted file mode 100644 index c9e92af..0000000 --- a/assets/disk0/tbas/doc/commands.tex +++ /dev/null @@ -1,34 +0,0 @@ -This chapter describes commands accepted by the \tbas\ editor. - -\section{The Editor} - -When you first launch the \tbas, all you can see is some generic welcome text and two letters: \code{Ok}. Sure, you can just start type away your programs and type \code{run} to execute them, there's more things you can do with. - -\subsection{LOAD} - \codeline{\textbf{LOAD} FILENAME}\par - Loads BASIC program by the file name. Default working directory for \tbas\ is \code{/home/basic}.\footnote{This is a directory within the emulated disk. On the host machine, this directory is typically \code{PWD/assets/diskN/home/basic}, where \code{PWD} is working directory for the \thismachine, \code{diskN} is a number of the disk.} - -\subsection{LIST} - \codeline{\textbf{LIST} [LINE\_NUMBER]} - \codeline{\textbf{LIST} [LINE\_FROM LINE\_TO]}\par - Displays BASIC program that currently has been typed. When no arguments were given, shows entire program; when single line number was given, displays that line; when range of line numbers were given, displays those lines. - -\subsection{NEW} - \codeline{\textbf{NEW}}\par - Immediately deletes the program that currently has been typed. - -\subsection{RENUM} - \codeline{\textbf{SAVE} FILENAME}\par - Re-numbers program line starting from 10 and incrementing by 10s. Jump targets will be re-numbered accordingly. Nonexisting jump targets will be replaced with \code{undefined}.\footnote{This behaviour is simply Javascript's null-value leaking into the BASIC. This is nonstandard behaviour and other \tbas\ implementations may act differently.} - -\subsection{RUN} - \codeline{\textbf{RUN}}\par - Executes BASIC program that currently has been typed. Execution can be arbitrarily terminated with Ctrl-C key combination (except in \code{INPUT} mode). - -\subsection{SAVE} - \codeline{\textbf{SAVE} FILENAME}\par - Saves BASIC program that currently has been typed. Existing files are overwritten \emph{silently}. - -\subsection{SYSTEM} - \codeline{\textbf{SYSTEM}}\par - Exits \tbas. diff --git a/assets/disk0/tbas/doc/concepts.tex b/assets/disk0/tbas/doc/concepts.tex deleted file mode 100644 index c965127..0000000 --- a/assets/disk0/tbas/doc/concepts.tex +++ /dev/null @@ -1,38 +0,0 @@ -\quad -\chapterprecishere{``Caution! Under no circumstances confuse the adjective \emph{basic} with the noun \emph{BASIC}, except under confusing circumstances!''\par\raggedleft --- \textup{\tbas\ Reference Manual, \theedition}\footnote{Original quotation: Donald R. Woods, James M. Lyon, \emph{The INTERCAL Programming Language Reference Manual}}} - -This chapter describes the basic concepts of the \tbas\ language. - - -\section{Values and Types} -\label{valuesandtypes} - -BASIC is a \emph{Dynamically Typed Language}, which means variables do not know which group they should barge in; only values of the variable do. In fact, there is no type definition in the language: \emph{we do want our variables to feel awkward.} - -There are six basic types: \emph{number}, \emph{boolean}, \emph{string}, \emph{array}, \emph{generator} and \emph{function}. - -\emph{Number} represents real (double-precision floating-point or actually, \emph{rational}) numbers. Operations on numbers follow the same rules of the underlying virtual machine\footnote{if you are not a computer person, disregard}, and such machines must follow the IEEE 754 standard\footnote{ditto.}. - -\emph{Boolean} is type of the value that is either \codebf{TRUE} or \codebf{FALSE}. Number \codebf{0} and \codebf{FALSE} make the condition \emph{false}. When used in numeric context, \codebf{FALSE} will be interpreted as 0 and \codebf{TRUE} as 1. - -\emph{String} represents immutable\footnote{Cannot be altered directly} sequences of bytes. - -\emph{Array} represents a collection of numbers in one or more dimensions. - -\emph{Generator} represents a value that automatically counts up/down whenever they have been called in FOR--NEXT loop. - -\emph{Functions} are, well\ldots\ functions\footnote{This is not a closure; there is no way you can define a local- or anonymous variable in BASIC.}, especially user-defined ones. Functions are \emph{type} because some built-in functions will actually take \emph{functions} as arguments. - -\section{Control Flow} - -A program is executed starting with its lowest line number. Statements on a line are executed from left to right. When all Statements are finished execution, next lowest line number will be executed. Control flow functions can modify this normal flow. - -You can dive into other lines in the middle of the program with \code{GOTO}. The program flow will continue normally at the new line \emph{and it will never know ya just did that}. - -If you want less insane jumping, \code{GOSUB} is used to jump to a subroutine. Subroutine is a little section of a code that serves as a tiny program inside of a program. \code{GOSUB} will remember from which statement in the line you have came from, and will return your program flow to that line when \code{RETURN} statement is encountered. (of course, if \code{RETURN} is used without \code{GOSUB}, program will raise some error) Do note that while you can reserve some portion of a program line as a \code{subroutine}, \tbas\ will not provide local variables and whatnot as all variables in BASIC are global, and you can just \code{GOTO} out of a subroutine to anywhere you desire and wreak havoc \emph{if you really wanted to}. - -The \code{ON} statement provides alternative branching construct. You can enter multiple line numbers and let your variable (or mathematical expression) to choose which index of line numbers to \code{GOTO}- or \code{GOSUB} into. - -The \code{IF-THEN-ELSE} lets you to conditionally select which of the two branches to execute. - -The \code{FOR-NEXT} lets you to loop a portion of a program while automatically counting your chosen variable up or down. diff --git a/assets/disk0/tbas/doc/functions.tex b/assets/disk0/tbas/doc/functions.tex deleted file mode 100644 index b847e7b..0000000 --- a/assets/disk0/tbas/doc/functions.tex +++ /dev/null @@ -1,267 +0,0 @@ -\label{functions} - -Functions are a form of expression that may taks input arguments surrounded by parentheses. Most of the traditional BASIC \emph{statements} that does not return a value are \emph{functions} in \tbas , and like those, while \tbas\ functions can be called without parentheses, it is highly \emph{discouraged} because of the ambiguities in syntax. \textbf{Always use parentheses on function call!} - -\section{Mathematical} - - \subsection{ABS} - \codeline{Y \textbf{= ABS(}X\textbf{)}}\par - Returns absolute value of \code{X}. - \subsection{ACO} - \codeline{Y \textbf{= ACO(}X\textbf{)}}\par - Returns inverse cosine of \code{X}. - \subsection{ASN} - \codeline{Y \textbf{= ASN(}X\textbf{)}}\par - Returns inverse sine of \code{X}. - \subsection{ATN} - \codeline{Y \textbf{= ATN(}X\textbf{)}}\par - Returns inverse tangent of \code{X}. - \subsection{CBR} - \codeline{Y \textbf{= CBR(}X\textbf{)}}\par - Returns cubic root of \code{X}. - \subsection{CEIL} - \codeline{Y \textbf{= CEIL(}X\textbf{)}}\par - Returns integer value of \code{X}, truncated towards positive infinity. - \subsection{COS} - \codeline{Y \textbf{= COS(}X\textbf{)}}\par - Returns cosine of \code{X}. - \subsection{COSH} - \codeline{Y \textbf{= COSH(}X\textbf{)}}\par - Returns hyperbolic cosine of \code{X}. - \subsection{EXP} - \codeline{Y \textbf{= EXP(}X\textbf{)}}\par - Returns exponential of \code{X}, i.e. $e^X$. - \subsection{FIX} - \codeline{Y \textbf{= FIX(}X\textbf{)}}\par - Returns integer value of \code{X}, truncated towards zero. - \subsection{FLOOR, INT} - \codeline{Y \textbf{= FLOOR(}X\textbf{)}} - \codeline{Y \textbf{= INT(}X\textbf{)}}\par - Returns integer value of \code{X}, truncated towards negative infinity. - \subsection{LEN} - \codeline{Y \textbf{= LEN(}X\textbf{)}}\par - Returns length of \code{X}. \code{X} can be either a string or an array. - \subsection{LOG} - \codeline{Y \textbf{= LOG(}X\textbf{)}}\par - Returns natural logarithm of \code{X}. - \subsection{ROUND} - \codeline{Y \textbf{= ROUND(}X\textbf{)}}\par - Returns closest integer value of \code{X}, rounding towards positive infinity. - \subsection{RND} - \codeline{Y \textbf{= RND(}X\textbf{)}}\par - Returns a random number within the range of $[0..1)$. If \code{X} is zero, previous random number will be returned; otherwise new random number will be returned. - \subsection{SIN} - \codeline{Y \textbf{= SIN(}X\textbf{)}}\par - Returns sine of \code{X}. - \subsection{SINH} - \codeline{Y \textbf{= SINH(}X\textbf{)}}\par - Returns hyperbolic sine of \code{X}. - \subsection{SGN} - \codeline{Y \textbf{= SGN(}X\textbf{)}}\par - Returns sign of \code{X}: 1 for positive, -1 for negative, 0 otherwise. - \subsection{SQR} - \codeline{Y \textbf{= SQR(}X\textbf{)}}\par - Returns square root of \code{X}. - \subsection{TAN} - \codeline{Y \textbf{= TAN(}X\textbf{)}}\par - Returns tangent of \code{X}. - \subsection{TANH} - \codeline{Y \textbf{= TANH(}X\textbf{)}}\par - Returns hyperbolic tangent of \code{X}. - -\section{Input} - - \subsection{CIN} - \codeline{S \textbf{= CIN()}}\par - Waits for the user input and returns it. - \subsection{DATA} - \codeline{\textbf{DATA} CONST0 [\textbf{,} CONST1]\ldots}\par - Adds data that can be read by \code{READ} function. \code{DATA} declarations need not be reacheable in the program flow. - \subsection{DGET} - \codeline{S \textbf{= DGET()}}\par - Fetches a data declared from \code{DATA} statements and returns it, incrementing the \code{DATA} position. - \subsection{DIM} - \codeline{Y \textbf{= DIM(}X\textbf{)}}\par - Returns array with size of \code{X}, all filled with zero. - \subsection{GETKEYSDOWN} - \codeline{K \textbf{= GETKEYSDOWN()}}\par - Stores array that contains keycode of keys held down into the given variable.\par - Actual keycode and the array length depends on the machine: in \thismachine , array length will be fixed to 8. For the list of available keycodes, see \ref{implementation}. - \subsection{INPUT} - \codeline{\textbf{INPUT} VARIABLE}\par - Prints out \code{? } to the console and waits for user input. Input can be any length and terminated with return key. The input will be stored to given variable.\par - This behaviour is to keep the compatibility with the traditional BASIC. For function-like usage, use \code{CIN} instead. - \subsection{READ} - \codeline{\textbf{READ} VARIABLE}\par - Assigns data declared from \code{DATA} statements to given variable. Reading starts at the current \code{DATA} position, and the data position will be incremented by one. The position is reset to the zero by the \code{RUN} command.\par - This behaviour is to keep the compatibility with the traditional BASIC. For function-like usage, use \code{DGET} instead. - -\section{Output} - - \subsection{EMIT} - \codeline{\textbf{EMIT(} EXPR [\{\textbf{,}|\textbf{;}\} EXPR]\ldots\ \textbf{)}}\par - Prints out characters corresponding to given number on the code page being used.\par - \code{EXPR} is numeric expression. - \subsection{PRINT} - \codeline{\textbf{PRINT(} EXPR [\{\textbf{,}|\textbf{;}\} EXPR]\ldots\ \textbf{)}}\par - Prints out given string expressions.\par - \code{EXPR} is a string, numeric expression, or array.\par - \code{PRINT} is one of the few function that differentiates two style of argument separator: \codebf{;} will simply concatenate two expressions (unlike traditional BASIC, numbers will not have surrounding spaces), \codebf{,} tabulates the expressions. - -\section{Program Manipulation} - - \subsection{CLEAR} - \codeline{\textbf{CLEAR}}\par - Clears all declared variables. - \subsection{END} - \codeline{\textbf{END}}\par - Stops program execution and returns control to the user. - \subsection{FOR} - \codeline{\textbf{FOR} LOOPVAR \textbf{=} START \textbf{TO} STOP [\textbf{STEP} STEP]} - \codeline{\textbf{FOR} LOOPVAR \textbf{=} GENERATOR}\par - Starts a FOR--NEXT loop.\par - Initially, \code{LOOPVAR} is set to \code{START} then statements between the \code{FOR} statement and corresponding \code{NEXT} statements are executed and \code{LOOPVAR} is incremented by \code{STEP}, or by 1 if \code{STEP} is not specified. The program flow will continue to loop around until \code{LOOPVAR} is outside the range of \code{START}--\code{STOP}. The value of the \code{LOOPVAR} is equal to \code{STOP}$+$\code{STEP} when the looping finishes. - \subsection{FOREACH} - \codeline{\textbf{FOREACH} LOOPVAR \textbf{IN} ARRAY}\par - Same as \code{FOR} but fetches \code{LOOPVAR} from given \code{ARRAY}. - \subsection{GOSUB} - \codeline{\textbf{GOSUB} LINENUM}\par - Jumps to a subroutine at \code{LINENUM}. The next \code{RETURN} statements makes program flow to jump back to the statement after the \code{GOSUB}.\par - \code{LINENUM} can be either a numeric expression or a Label. - \subsection{GOTO} - \codeline{\textbf{GOTO} LINENUM}\par - Jumps to \code{LINENUM}.\par - \code{LINENUM} can be either a numeric expression or a Label. - \subsection{LABEL} - \codeline{\textbf{LABEL} NAME}\par - Puts a name onto the line numeber the statement is located. Jumping to the \code{NAME} - \subsubsection*{Notes} - \begin{itemlist} - \item \code{NAME} must be a valid variable name. - \end{itemlist} - \subsection{NEXT} - \codeline{\textbf{NEXT}}\par - Iterates FOR--NEXT loop and increments the loop variable from the most recent \code{FOR} statement and jumps to that statement. - \subsection{RESTORE} - \codeline{\textbf{RESTORE}}\par - Resets the \code{DATA} pointer. - \subsection{RETURN} - \codeline{\textbf{RETURN}}\par - Returns from the \code{GOSUB} statement. - -\section{String Manipulation} - - \subsection{CHR} - \codeline{CHAR \textbf{= CHR(}X\textbf{)}}\par - Returns the character with code point of \code{X}. Code point is a numeric expression in the range of $[0-255]$. - \subsection{LEFT} - \codeline{SUBSTR \textbf{= LEFT(} STR \textbf{,} NUM\_CHARS \textbf{)}}\par - Returns the leftmost \code{NUM\_CHARS} characters of \code{STR}. - \subsection{MID} - \codeline{SUBSTR \textbf{= MID(} STR \textbf{,} POSITION \textbf{,} LENGTH \textbf{)}}\par - Returns a substring of \code{STR} starting at \code{POSITION} with specified \code{LENGTH}.\par - When \code{OPTIONBASE 1} is specified, the position starts from 1; otherwise it will start from 0. - \subsection{RIGHT} - \codeline{SUBSTR \textbf{= RIGHT(} STR \textbf{,} NUM\_CHARS \textbf{)}}\par - Returns the rightmost \code{NUM\_CHARS} characters of \code{STR}. - \subsection{SPC} - \codeline{STR \textbf{= SPC(} STR \textbf{,} NUM\_CHARS \textbf{)}}\par - Returns a string of \code{NUM\_CHARS} spaces. - -\section{Array Manipulation} - - \subsection{HEAD} - \codeline{K \textbf{= HEAD(}X\textbf{)}}\par - Returns the head element of the array \code{X}. - \subsection{INIT} - \codeline{K \textbf{= INIT(}X\textbf{)}}\par - Constructs the new array from array \code{X} that has its last element removed. - \subsection{LAST} - \codeline{K \textbf{= LAST(}X\textbf{)}}\par - Returns the last element of the array \code{X}. - \subsection{TAIL} - \codeline{K \textbf{= TAIL(}X\textbf{)}}\par - Constructs the new array from array \code{X} that has its head element removed. - -\section{Graphics} - - \subsection{PLOT} - \codeline{\textbf{PLOT(} X\_POS \textbf{,} Y\_POS \textbf{,} COLOUR \textbf{)}}\par - Plots a pixel to the framebuffer of the display, at XY-position of \code{X\_POS} and \code{Y\_POS}, with colour of \code{COLOUR}.\par - Top-left corner of the pixel will be 1 if \code{OPTIONBASE 1} is specified; otherwise it will be 0. - -\section{Meta} - - \subsection{OPTIONBASE} - \codeline{\textbf{OPTIONBASE} \{\textbf{0}|\textbf{1}\}}\par - Specifies at which number the array/string/pixel indices begin. - \subsection{OPTIONDEBUG} - \codeline{\textbf{OPTIONDEBUG} \{\textbf{0}|\textbf{1}\}}\par - Specifies whether or not the debugging messages should be printed out. The messages will be printed out to the \emph{serial debugging console}, or to the stdout. - \subsection{OPTIONTRACE} - \codeline{\textbf{OPTIONTRACE} \{\textbf{0}|\textbf{1}\}}\par - Specifies whether or not the line numbers should be printed out. The messages will be printed out to the \emph{serial debugging console}, or to the stdout. - \subsection{TYPEOF} - \codeline{X \textbf{= TYPEOF(} VALUE \textbf{)}}\par - Returns a type of given value.\par - \begin{longtable}{*{2}{m{\textwidth}}}\hline - \endfirsthead - \endhead - - \endfoot - \hline - \endlastfoot - \centering - \begin{tabulary}{\textwidth}{rl} - BASIC Type & Returned Value \\ - \hline - Number & \ttfamily{num} \\ - Boolean & \ttfamily{bool} \\ - String & \ttfamily{str} \\ - \end{tabulary} - \begin{tabulary}{\textwidth}{rl} - BASIC Type & Returned Value \\ - \hline - Array & \ttfamily{array} \\ - Generator & \ttfamily{generator} \\ - User Function & \ttfamily{usrdefun} - \end{tabulary} - \end{longtable} - -\section{System} - - \subsection{PEEK} - \codeline{BYTE \textbf{= PEEK(} MEM\_ADDR \textbf{)}}\par - Returns whatever the value stored in the \code{MEM\_ADDR} of the Scratchpad Memory.\par - Address mirroring, illegal access, etc. are entirely up to the virtual machine which the BASIC interpreter is running on. - \subsection{POKE} - \codeline{\textbf{POKE(} MEM\_ADDR \textbf{,} BYTE \textbf{)}}\par - Puts a \code{BYTE} into the \code{MEM\_ADDR} of the Scratchpad Memory. - -\section{Higher-order Function} - - \subsection{DO} - \codeline{\textbf{DO(} EXPR0 [\textbf{;} EXPR1]\ldots\ \textbf{)}}\par - Executes \code{EXPRn}s sequentially. - \subsection{FILTER} - \codeline{NEWLIST \textbf{= FILTER(} FUNCTION \textbf{,} ITERABLE \textbf{)}}\par - Returns an array of values from the \code{ITERABLE} that passes the given function. i.e. values that makes \code{FUNCTION(VALUE\_FROM\_ITERABLE)} true. - \subsubsection*{Parameters} - \begin{itemlist} - \item \code{FUNCTION} is a user-defined function with single parameter. - \item \code{ITERABLE} is either an array or a generator. - \end{itemlist} - \subsection{FOLD} - \codeline{NEWVALUE \textbf{= FOLD(} FUNCTION \textbf{,} INIT\_VALUE \textbf{,} ITERABLE \textbf{)}}\par - Iteratively applies given function with accumulator and the value from the \code{ITERABLE}, returning the final accumulator. Accumulator will be set to \code{INIT\_VALUE} before iterating over the iterable. In the first execution, the accumulator will be set to \code{ACC=FUNCTION(ACC,ITERABLE(0))}, and the execution will continue to remaining values within the iterable until all values are consumed. The \code{ITERABLE} will not be modified after the execution. - \subsubsection*{Parameters} - \begin{itemlist} - \item \code{FUNCTION} is a user-defined function with two parameters: first parameter being accumulator and second being a value. - \end{itemlist} - \subsection{MAP} - \codeline{NEWLIST \textbf{= MAP(} FUNCTION \textbf{,} ITERABLE \textbf{)}}\par - Applies given function onto the every element in the iterable, and returns an array that contains such items. i.e. returns tranformation of \code{ITERABLE} of which the transformation is \code{FUNCTION}. The \code{ITERABLE} will not be modified after the execution. - \subsubsection*{Parameters} - \begin{itemlist} - \item \code{FUNCTION} is a user-defined function with single parameter. - \end{itemlist} diff --git a/assets/disk0/tbas/doc/implementation.tex b/assets/disk0/tbas/doc/implementation.tex deleted file mode 100644 index cf31785..0000000 --- a/assets/disk0/tbas/doc/implementation.tex +++ /dev/null @@ -1,123 +0,0 @@ -\label{implementation} - -This chapter explains implementation details of \tbas\ running on \thismachine. - -\section{Keycodes} - -This is a table of keycodes recognised by the LibGDX, a framework that \thismachine\ runs on. - -\begin{longtable}{*{2}{m{\textwidth}}}\hline -\endfirsthead -\endhead - -\endfoot -\hline -\endlastfoot -\centering -\begin{tabulary}{\textwidth}{rl} -Key & Code \\ -\hline -\ttfamily{1} & 8 \\ -\ttfamily{2} & 9 \\ -\ttfamily{3} & 10 \\ -\ttfamily{4} & 11 \\ -\ttfamily{5} & 12 \\ -\ttfamily{6} & 13 \\ -\ttfamily{7} & 14 \\ -\ttfamily{8} & 15 \\ -\ttfamily{9} & 16 \\ -\ttfamily{0} & 17 \\ -$\hookleftarrow$ & 66 \\ -\condensedfont{BkSp} & 67 \\ -\condensedfont{Tab} & 61 \\ -\ttfamily{`} & 68 \\ -\ttfamily{'} & 75 \\ -\ttfamily{;} & 43 \\ -\ttfamily{,} & 55 \\ -\ttfamily{.} & 56 \\ -\ttfamily{/} & 76 \\ -\ttfamily{[}\hspace*{0.083em} & 71 \\ -\ttfamily{]}\hspace*{-0.083em} & 72 \\ -\ttfamily{-} & 69 \\ -\end{tabulary} -\begin{tabulary}{\textwidth}{rl} -Key & Code \\ -\hline -\ttfamily{+} & 70 \\ -\ttfamily{A} & 29 \\ -\ttfamily{B} & 30 \\ -\ttfamily{C} & 31 \\ -\ttfamily{D} & 32\\ -\ttfamily{E} & 33 \\ -\ttfamily{F} & 34 \\ -\ttfamily{G} & 35 \\ -\ttfamily{H} & 36 \\ -\ttfamily{I} & 37 \\ -\ttfamily{J} & 38 \\ -\ttfamily{K} & 39 \\ -\ttfamily{L} & 40 \\ -\ttfamily{M} & 41 \\ -\ttfamily{N} & 42 \\ -\ttfamily{O} & 43 \\ -\ttfamily{P} & 44 \\ -\ttfamily{Q} & 45 \\ -\ttfamily{R} & 46 \\ -\ttfamily{S} & 47 \\ -\ttfamily{T} & 48 \\ -\ttfamily{U} & 49 \\ -\end{tabulary} -\begin{tabulary}{\textwidth}{rl} -Key & Code \\ -\hline -\ttfamily{V} & 50 \\ -\ttfamily{W} & 51 \\ -\ttfamily{X} & 52 \\ -\ttfamily{Y} & 53 \\ -\ttfamily{Z} & 54 \\ -\condensedfont{LCtrl} & 57 \\ -\condensedfont{RCtrl} & 58 \\ -\condensedfont{LShift} & 59 \\ -\condensedfont{RShift} & 60 \\ -\condensedfont{LAlt} & 129 \\ -\condensedfont{RAlt} & 130 \\ -$\uparrow$ & 19 \\ -$\downarrow$ & 20 \\ -$\leftarrow$ & 21 \\ -$\rightarrow$ & 22 \\ -\condensedfont{Ins} & 133 \\ -\condensedfont{Del} & 112 \\ -\condensedfont{PgUp} & 92 \\ -\condensedfont{PgDn} & 93 \\ -\condensedfont{Home} & 3 \\ -\condensedfont{End} & 132 \\ -F1 & 244 \\ -\end{tabulary} -\begin{tabulary}{\textwidth}{rl} -Key & Code \\ -\hline -F2 & 245 \\ -F3 & 246 \\ -F4 & 247 \\ -F5 & 248 \\ -F6 & 249 \\ -F7 & 250 \\ -F8 & 251 \\ -F9 & 252 \\ -F10 & 253 \\ -F11 & 254 \\ -\condensedfont{Num} \ttfamily{0} & 144 \\ -\condensedfont{Num} \ttfamily{1} & 145 \\ -\condensedfont{Num} \ttfamily{2} & 146 \\ -\condensedfont{Num} \ttfamily{3} & 147 \\ -\condensedfont{Num} \ttfamily{4} & 148 \\ -\condensedfont{Num} \ttfamily{5} & 149 \\ -\condensedfont{Num} \ttfamily{6} & 150 \\ -\condensedfont{Num} \ttfamily{7} & 151 \\ -\condensedfont{Num} \ttfamily{8} & 152 \\ -\condensedfont{Num} \ttfamily{9} & 153 \\ -\condensedfont{NumLk} & 78 \\ -\ttfamily{*} & 17 \\ -\end{tabulary} -\end{longtable} - -Keys not listed on the table may not be available depending on the system, for example, F12 may not be recognised. diff --git a/assets/disk0/tbas/doc/intro.tex b/assets/disk0/tbas/doc/intro.tex deleted file mode 100644 index b1851d9..0000000 --- a/assets/disk0/tbas/doc/intro.tex +++ /dev/null @@ -1,7 +0,0 @@ -\tbas\ is a BASIC dialect and its interpreter. \tbas\ emulates most of the common BASIC syntax while also adding more advanced and up-to-date concepts gracefully, such as user-defined function that can \emph{actually} recurse, arbitrary list construction using CONS-operator and some of the features in the realm of functional programming from \code{MAP} and \code{FOLD} to \code{CURRY}-ing a function. - -This is the documentation for \tbas\ \tbasver. - -\vfill - -\small\emph{Henceforward this documentation will use more friendly and sometimes vulgar language because that's more fun to write!} diff --git a/assets/disk0/tbas/doc/langguide.tex b/assets/disk0/tbas/doc/langguide.tex deleted file mode 100644 index e876c6d..0000000 --- a/assets/disk0/tbas/doc/langguide.tex +++ /dev/null @@ -1,208 +0,0 @@ -\quad -\chapterprecishere{``Begin at the beginning'', the King said gravely, ``and go on till you come to the end: then stop.''\par\raggedleft --- \textup{Lewis Carroll, } Alice in Wonderland} - -We'll begin at the beginning; how beginning? This: - -\begin{lstlisting} -10 PRINT 2+2 -run -4 -Ok -\end{lstlisting} - -Oh \emph{boy} we just did a computation! It printed out \code{4} which is a correct answer for $2+2$ and it didn't crash! - -\section[GOTO]{GOTO here and there} - -\code{GOTO} is used a lot in BASIC, and so does in \tbas. \code{GOTO} is a simplest method of diverging a program flow: execute only the part of the program conditionally and perform a loop. - -Following program attempts to calculate a square root of the input value, showing how \code{GOTO} can be used in such manner. - -\begin{lstlisting} -10 X=1337 -20 Y=0.5*X -30 Z=Y -40 Y=Y-((Y^2)-X)/(2*Y) -50 IF NOT(Z==Y) THEN GOTO 30 : REM 'NOT(Z==Y)' can be rewritten to 'Z<>Y' -100 PRINT "Square root of ";X;" is approximately ";Y -\end{lstlisting} - -Here, \code{GOTO} in line 50 is used to perform a loop, which keeps looping until \code{Z} and \code{Y} becomes equal. This is a newtonian method of approximating a square root. - -\section[Subroutine with GOSUB]{What If We Wanted to Go Back?} - -But \code{GOTO} only jumps, you can't jump \emph{back}. Well, not with that attitute; you \emph{can} go back with \code{GOSUB} and \code{RETURN} statement. - -This program will draw a triangle, where the actual drawing part is on line 100--160, and only get jumped into it when needed. - -\begin{lstlisting} -10 GOTO 1000 -100 REM subroutine to draw a segment. Size is stored to 'Q' -110 PRINT SPC(20-Q); -120 Q1=1 : REM loop counter for this subroutine -130 PRINT "*"; -140 Q1=Q1+1 -150 IF Q1<=Q*2-1 THEN GOTO 130 -160 PRINT : RETURN : REM this line will take us back from the jump -1000 Q=1 : REM this is our loop counter -1010 GOSUB 100 -1020 Q=Q+1 -1030 IF Q<=20 THEN GOTO 1010 -\end{lstlisting} - -\section[FOR--NEXT Loop]{FOR ever loop NEXT} - -As we've just seen, you can make loops using \code{GOTO}s here and there, but they \emph{totally suck}, too much spaghetti crashes your cerebral cortex faster than \emph{Crash Bandicoot 2}. Fortunately, there's a better way to go about that: the FOR--NEXT loop! - -\begin{lstlisting} -10 GOTO 1000 -100 REM subroutine to draw a segment. Size is stored to 'Q' -110 PRINT SPC(20-Q); -120 FOR Q1=1 TO Q*2-1 -130 PRINT "*"; -140 NEXT : PRINT -150 RETURN -1000 FOR Q=1 TO 20 -1010 GOSUB 100 -1020 NEXT -\end{lstlisting} - -When executed, this program print out \emph{exactly the same} triangle, but code is much more straightforward thanks to the \code{FOR} statement. - -\section[Get User INPUT]{Isn't It Nice To Have a Computer That Will Question You?} - -What fun is the program if it won't talk with you? You can make that happen with \code{INPUT} statement. - -\begin{lstlisting} -10 PRINT "WHAT IS YOUR NAME"; -20 INPUT NAME -30 PRINT "HELLO, ";NAME -\end{lstlisting} - -This short program will ask your name, and then it will greet you by the name you told to the computer. - -\section[Function]{Function} - -Consider the following code: - -\begin{lstlisting} -10 DEFUN POW2(N)=2^N -20 DEFUN DCOS(N)=COS(PI*N/180) -30 FOR X=0 TO 8 -40 PRINT X,POW2(X) -50 NEXT -60 PRINT "----------------" -70 FOREACH A=0!45!90!135!180!NIL -80 PRINT A,DCOS(A) -90 NEXT -\end{lstlisting} - -Here, we have defined two functions to use in the program: \code{POW2} and \code{DCOS}. Also observe that functions are defined using variable \code{N}s, but we use them with \code{X} in line 40 and with \code{A} in line 80: yes, functions can have their local name so you don't have to carefully choose which variable name to use in your subroutine. - -Except a function can't have statements that spans two- or more BASIC lines; but there are ways to get around that, including \code{DO} statement and \emph{functional currying}\newcounter{curryingappearance}\setcounter{curryingappearance}{\value{page}} - -This sample program also shows \code{FOREACH} statement, which is same as \code{FOR} but works with arrays. - -\section[Recursion]{BRB: Bad Recursion BRB: Bad Recursion BRB: Bad Recursion BRB: Bad RecursionBRB: Bad Recursion BRBRangeError: Maximum call stack size exceeded} - -But don't get over-excited, as it's super-trivial to create unintentional infinite loop: - -\begin{lstlisting} -10 DEFUN FAC(N)=N*FAC(N-1) -20 FOR K=1 TO 6 -30 PRINT FAC(K) -40 NEXT -\end{lstlisting} - -(if you tried this and computer becomes unresponsive, hit Ctrl-C to terminate the execution) - -This failed attempt is to create a function that calculates a factorial of \code{N}. It didn't work because there is no \emph{halting condition}: didn't tell computer to when to escape from the loop. - -$n \times 1$ is always $n$, and $0!$ is $1$, so it would be nice to break out of the loop when \code{N} reaches $0$; here is the modified program: - -\begin{lstlisting} -10 DEFUN FAC(N)=IF N==0 THEN 1 ELSE N*FAC(N-1) -20 FOR K=1 TO 10 -30 PRINT FAC(K) -40 NEXT -\end{lstlisting} - -Since \code{IF-THEN-ELSE} can be chained to make third or more conditions --- \code{IF-THEN-ELSE IF-THEN} or something --- we can write a recursive Fibonacci function: - -\begin{lstlisting} -10 DEFUN FIB(N)=IF N==0 THEN 0 ELSE IF N==1 THEN 1 ELSE FIB(N-1)+FIB(N-2) -20 FOR K=1 TO 10 -30 PRINT FIB(K);" "; -40 NEXT -\end{lstlisting} - -\section[Higher-order Function]{The Functions of the High Order} - -Higher-order functions are functions that either takes another function as an argument, or returns a function. This sample program shows how higher-order functions can be constructed. - -\begin{lstlisting} -10 DEFUN APPLY(F,X)=F(X) -20 DEFUN FUN(X)=X^2 -30 K=APPLY(FUN,42) -40 PRINT K -\end{lstlisting} - -Here, \code{APPLY} takes a function \code{F} and value \code{X}, \emph{applies} a function \code{F} onto the value \code{X} and returns the value. Since \code{APPLY} takes a function, it's higher-order function. - -\section[MAPping]{Map} - -\code{MAP} is a higher-order function that takes a function (called \emph{transformation}) and an array to construct a new array that contains old array transformed with given \emph{transformation}. - -Or, think about the old \code{FAC} program before: it merely printed out the value of $1!$, $2!$ \ldots\ $10!$. What if we wanted to build an array that contains such values? - -\begin{lstlisting} -10 DEFUN FAC(N)=IF N==0 THEN 1 ELSE N*FAC(N-1) -20 K=MAP(FAC, 1 TO 10) -30 PRINT K -\end{lstlisting} - -Here, \code{K} holds the values of $1!$, $2!$ \ldots\ $10!$. Right now we're just printing out the array, but being an array, you can make actual use of it. - -\section[Currying]{Haskell Curry Wants to Know Your Location} -\label{currying101} - -\newcounter{curryingselfref} -\setcounter{curryingselfref}{\value{page} - \value{curryingappearance}} - -\cnttoenglish{\value{curryingselfref}}{page} ago there was a mentioning about something called \emph{functional currying}. So what the fsck is currying? Consider the following code: - -\begin{lstlisting} -10 DEFUN F(K,T)=ABS(T)==K -20 CF=F~<32 -30 PRINT CF(24) : REM will print 'false' -40 PRINT CF(-32) : REM will print 'true' -\end{lstlisting} - -% NOTE: you can't use \basiccurry within \code{} -Here, \code{CF} is a curried function of \code{F}; built-in operator \code{$\sim\!<$} applies \code{32} to the first parameter of the function \code{F}, which dynamically returns a \emph{function} of \code{CF(T) = ABS(T) == 32}. The fact that Curry Operator returns a \emph{function} opens many possibilities, for example, you can create loads of sibling functions without making loads of duplicate codes. - -\section[Wrapping-Up]{The Grand Unification} - -Using all the knowledge we have learned, it should be trivial\footnote{/s} to write a Quicksort function in \tbas, like this: - -\begin{lstlisting} -10 DEFUN LESS(P,X)=X
=P -12 DEFUN QSORT(XS)=IF LEN(XS)<1 THEN NIL ELSE - QSORT(FILTER(LESS~
IF LEN(XS)<1 THEN NIL ELSE -%% QSORT(FILTER([K]~>KK>=HEAD XS,TAIL XS)) -%% \end{lstlisting} diff --git a/assets/disk0/tbas/doc/langref.tex b/assets/disk0/tbas/doc/langref.tex deleted file mode 100644 index a2b205c..0000000 --- a/assets/disk0/tbas/doc/langref.tex +++ /dev/null @@ -1,272 +0,0 @@ -\newcommand{\intrange}{\hl{[$0..2^{53}-1$]}} - -This chapter describes the \tbas\ language. - -\section{Metasyntax} - -In the descriptions of BASIC syntax, these conventions apply. - -\begin{itemlist} -\item \codebf{VERBATIM} --- Type exactly as shown -\item \code{IDENTIFIER} --- Replace \emph{identifier} with appropriate metavariable -\item \code{[a]} --- Words within square brackets are optional -\item \code{\{a|b\}} --- Choose either \code{a} or \code{b} -\item \code{[a|b]} --- Optional version of the above -\item \code{a\ldots} --- The preceding entity can be repeated -\end{itemlist} - -\section{Definitions} - -A \emph{Program Line} consists of a line number followed by a \emph{Statements}. Program Lines are terminated by a line break or by the end-of-the-file. - -A \emph{Line Number} is an integer within the range of \intrange. - -A \emph{Statement} is special form of code which has special meaning. A program line can be composed of 1 or more statements, separated by colons. For the details of statements available in \tbas , see \ref{statements}. - -\codeline{STATEMENT [: STATEMENT]\ldots} - -An \emph{Expression} is rather normal program lines, e.g. mathematical equations and function calles. The expression takes one of the following forms. For the details of functions available in \tbas , see \ref{functions}. - -\codeline{VARIABLE\_OR\_FUNCTION}\\ -\codeline{( EXPRESSION )}\\ -\codeline{\textbf{IF} EXPRESSION \textbf{THEN} EXPRESSION [\textbf{ELSE} EXPRESSION]}\\ -\codeline{FUNCTION \textbf{(} [EXPRESSION \{\textbf{,}|\textbf{;}\} [\{\textbf{,}|\textbf{;}\}]] \textbf{)}}\\ -\codeline{FUNCTION [EXPRESSION \{\textbf{,}|\textbf{;}\} [\{\textbf{,}|\textbf{;}\}]]}\\ -\codeline{EXPRESSION BINARY\_OPERATOR EXPRESSION}\\ -\codeline{UNARY\_OPERATOR EXPRESSION} - -An \emph{Array} takes following form: - -\codeline{ARRAY\_NAME \textbf{(} EXPRESSION [\textbf{,} EXPRESSION]\ldots\ \textbf{)}} - -\section{Literals} -\subsection{String Literals} - -String literals take the following form: - -\codeline{\textbf{"} [CHARACTERS] \textbf{"}} - -where \code{CHARACTERS} is a 1- or more repetition of ASCII-printable letters.\footnote{In other words, \code{0x20..0x7E}} - -To print out graphical letters outside of ASCII-printable, use string concatenation with \code{CHR} function, or use \code{EMIT} function. - -\subsection{Numeric Literals} - -Numeric literals take one of the following forms: - -\codeline{[\textbf{+}|\textbf{-}][\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots\ [\textbf{.}][\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots}\\ -\codeline{\textbf{0}\{\textbf{x}|\textbf{X}\}[\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots}\\ -\codeline{\textbf{0}\{\textbf{b}|\textbf{B}\}[\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots} - -Hexadecimal and binary literals are always interpreted as \emph{unsigned} integers. They must range between \intrange. - -\subsection{Variables} - -Variable names must start with a letter and all characters of the name must be letters \code{A-Z}, figures \code{0-9}. Variable names must not be identical to reserved words, but may \emph{contain} one. Variable names are case-insensitive. - -Unlike conventional BASIC dialects (especially GW-BASIC), name pool of variables are shared between all the types. For example, if you have a numeric variable \code{A}, and define an array named \code{A} later in the program, the new array will overwrite your numeric \code{A}. - -Furthermore, \emph{sigils} are not used in the \tbas\ and attempting to use one will raise syntax-error or undefined behaviour. - -\subsection{Types} - -Types of data recognised by \tbas\ are distinguished by some arcane magic of Javascript auto-casing mumbo-jumbo - -\begin{tabulary}{\textwidth}{rCL} -Type & Range & Precision \\ -\hline -String & As many as the machine can handle & \, \\ -Integer & $ \pm 2^{53}-1 $ & exact within the range \\ -Float & $ \pm 4.9406564584124654 \times 10^{-324} $ -- $ \pm 1.7976931348623157 \times 10^{308} $ & about 16 significant figures \\ -\end{tabulary} - -\section{Operators} -\subsection{Order of Precedence} - -The order of precedence of the operators is as shown below, lower numbers means they have higher precedence (more tightly bound) - -\begin{longtable}{*{2}{m{\textwidth}}}\hline -\endfirsthead -\endhead - -\endfoot -\hline -\endlastfoot -\centering -\begin{tabulary}{\textwidth}{cCc} -Order & Op & Associativity \\ -\hline -1 & \basicexp & Right \\ -2 & \ast\quad$/$\quad$\backslash$ & Left \\ -3 & \condensedfont{MOD} & Left \\ -4 & $+$\quad$-$ & Left \\ -5 & \condensedfont{NOT}\quad\condensedfont{BNOT} & Left \\ -6 & <\!<\quad>\!> & Left \\ -7 & <\enskip>\enskip=\!<\enskip<\!=\enskip=\!>\enskip>\!= & Left \\ -8 & ==\quad<\!>\quad>\!< & Left \\ -9 & \condensedfont{MIN}\quad\condensedfont{MAX} & Left \\ -10 & \condensedfont{BAND} & Left \\ -\end{tabulary} -\begin{tabulary}{\textwidth}{cCc} -Order & Op & Associativity \\ -\hline -11 & \condensedfont{BXOR} & Left \\ -12 & \condensedfont{BOR} & Left \\ -13 & \condensedfont{AND} & Left \\ -14 & \condensedfont{OR} & Left \\ -15 & \condensedfont{TO}\quad\condensedfont{STEP} & Left \\ -16 & ! & Right \\ -17 & \sim & Left\\ -18 & \# & Left \\ -19 & \basiccurry & Left \\ -%19.5 & \basicclosure & Right \\ -20 & = & Right \\ -\end{tabulary} -\end{longtable} - -\subsubsection*{Examples} -\begin{itemlist} -\item Exponentiation is more tightly bound than negation: \code{-1\basicexp 2 == -(1\basicexp 2) == -1} but \code{(-1)\basicexp 2 == 1} -\item Exponentiation is right-associative: \code{4\basicexp 3\basicexp 2 == 4\basicexp (3\basicexp 2) == 262144}. This behaviour is \emph{different} from GW-BASIC in which its exponentiation is left-associative. -\end{itemlist} - -\subsection{Mathematical Operators} - -Mathematical operators operate on expressions that returns numeric value only, except for the \code{+} operator which will take the action of string concatenation if either of the operand is non-numeric. - -\begin{tabulary}{\textwidth}{clL} -Code & Operation & Result \\ -\hline -\emph{x} $=$ \emph{y} & Assignment & Assigns \emph{y} into \emph{x} \\ -\emph{x} $\basicexp$ \emph{y} & Exponentiation & \emph{x} raised to the \emph{y}th power \\ -\emph{x} $\ast$ \emph{y} & Multiplication & Product of \emph{x} and \emph{y} \\ -\emph{x} $/$ \emph{y} & Division & Quotient of \emph{x} and \emph{y} \\ -\emph{x} $\backslash$ \emph{y} & Truncated Division & Integer quotient of \emph{x} and \emph{y} \\ -\emph{x} \condensedfont{MOD} \emph{y} & Modulo & Integer remainder of \emph{x} and \emph{y} with sign of \emph{x} \\ -\emph{x} $+$ \emph{y} & Addition & Sum of \emph{x} and \emph{y} \\ -\emph{x} $-$ \emph{y} & Subtraction & Difference of \emph{x} and \emph{y} \\ -$+$ \emph{x} & Unary Plus & Value of \emph{x} \\ -$-$ \emph{x} & Unary Minus & Negative value of \emph{x} \\ -\emph{x} \condensedfont{MIN} \emph{y} & Minimum & Lesser value of two \\ -\emph{x} \condensedfont{MAX} \emph{y} & Maximum & Greater value of two \\ - -\end{tabulary} - -\subsubsection*{Notes} -\begin{itemlist} -\item Type conversion rule follows underlying Javascript implementation. In other words, \emph{only the god knows.} -\item The expression \code{0\basicexp 0} will return \code{1}, even though the expression is indeterminant. -\end{itemlist} - -\subsubsection*{Errors} -\begin{itemlist} -\item Any expression that results \code{NaN} or \code{Infinity} in Javascript will return some kind of errors, mainly \code{Division by zero}. -\item If \code{\emph{x}<0} and \code{\emph{y}} is not integer, \code{\emph{x}\basicexp\emph{y}} will raise \code{Illegal function call}. -\end{itemlist} - -\subsection{Comparison Operators} - -Comparison operator can operate on numeric and string operands. String operands will be automatically converted to numeric value if they can be; if one operand is numeric and other is non-numeric string, the former will be converted to string value. - -\begin{tabulary}{\textwidth}{clL} -Code & Operation & Result \\ -\hline -\emph{x} == \emph{y} & Equal & True if \emph{x} equals \emph{y} \\ -\emph{x} <\!> \emph{y} \quad \emph{x} >\!< \emph{y} & Not equal & False if \emph{x} equals \emph{y} \\ -\emph{x} < \emph{y} & Less than & True if \emph{x} is less than \emph{y} \\ -\emph{x} > \emph{y} & Greater than & True if \emph{x} is greater than \emph{y} \\ -\emph{x} <\!= \emph{y} \quad \emph{x} =\!< \emph{y} & Less than or equal & False if \emph{x} is greater than \emph{y} \\ -\emph{x} >\!= \emph{y} \quad \emph{x} =\!> \emph{y} & Greater than or equal & False if \emph{x} is less than \emph{y} \\ -\end{tabulary} - -When comparing strings, the ordering is as follows: - -\begin{itemlist} -\item Two strings are equal only when they are of the same length and every codepoint of the first string is identical to that of the second. This includes any whitespace or unprintable characters. -\item Each character position of the string is compared starting from the leftmost character. When a pair of different characters is encountered, the string with the character of lesser codepoint is less than the string with the character of greater codepoint. -\item If the strings are of different length, but equal up to the length of the shorter string, then the shorter string is less than the longer string. -\end{itemlist} - -\subsection{Bitwise Operators} - -Bitwise operators operate on unsigned integers only. Floating points are truncated\footnote{truncated towards zero} to integers. - -\begin{tabulary}{\textwidth}{clL} -Code & Operation & Result \\ -\hline -\emph{x} <\!< \emph{y} & Bitwise Shift Left & Shifts entire bits of \emph{x} by \emph{y} \\ -\emph{x} >\!> \emph{y} & Bitwise Shift Right & Shift entire bits \emph{x} by \emph{y}, including sign bit \\ -\condensedfont{BNOT} \emph{x} & Ones' complement & $-\emph{x}-1$ \\ -\emph{x} \condensedfont{BAND} \emph{y} & Bitwise conjunction & Bitwise AND of \emph{x} and \emph{y} \\ -\emph{x} \condensedfont{BOR} \emph{y} & Bitwise disjunction & Bitwise OR of \emph{x} and \emph{y} \\ -\emph{x} \condensedfont{BXOR} \emph{y} & Bitwise add-with-no-carry & Bitwise XOR of \emph{x} and \emph{y} \\ -\end{tabulary} - -\subsection{Boolean Operators} - -Boolean operators operate on boolean values. If one of the operand is not boolean, it will be cast to appropriate boolean value. See \ref{valuesandtypes} for casting rules. - -\begin{tabulary}{\textwidth}{clL} -Code & Operation & Result \\ -\hline -\condensedfont{NOT} \emph{x} & Logical negation & True if \emph{x} is false and vice versa \\ -\emph{x} \condensedfont{AND} \emph{y} & Bitwise conjunction & True if \emph{x} and \emph{y} are both true \\ -\emph{x} \condensedfont{OR} \emph{y} & Bitwise disjunction & True if \emph{x} or \emph{y} is true, or both are true \\ -\end{tabulary} - -\subsection{Generator Operators} - -Generator operators operate on numeric values and generators to create and modify a generator. - -\begin{tabulary}{\textwidth}{clL} -Code & Result \\ -\hline -\emph{x} \condensedfont{TO} \emph{y} & Creates an generator that counts from \emph{x} to \emph{y} \\ -\emph{x} \condensedfont{STEP} \emph{y} & Modifies an counting stride of the generator \emph{x} into \emph{y} \\ -\end{tabulary} - -\subsection{Array Operators} - -Array operators operate on arrays and numeric values. - -\begin{tabulary}{\textwidth}{clL} -Code & Operation & Result \\ -\hline -\emph{x} $!$ \emph{y} & Cons & Prepends a value of \emph{x} into an array of \emph{y} \\ -\emph{x} $\sim$ \emph{y} & Push & Appends a value of \emph{y} into an array of \emph{x} \\ -\emph{x} $\#$ \emph{y} & Concat & Concatenates two arrays \\ -\end{tabulary} - -Arbitrary arrays can be constructed using empty-array constant \codebf{NIL}. - -\subsection{Function Operators} - -Function operators operate on functions and some values. - -\begin{tabulary}{\textwidth}{clL} -Code & Operation & Result \\ -\hline -\emph{f} \basiccurry\ \emph{x} & Curry & Apply \emph{x} into the first parameter of the function \emph{f} \\ -%{[}\emph{x},\,\emph{y}\ldots{]} \basicclosure\ \emph{e} & Closure & Creates a closure (anonymous function) from one or more parameters \emph{x},\,\emph{y}\ldots\ and an expression \emph{e} \\ -\end{tabulary} - -\emph{Currying}\footnote{\emph{Partial Application} should be more appropriate for this operator, but oh well: \emph{currying} is less mouthful.} is an operation that returns new function that has given value applied to the original function's first parameter. See \ref{currying101} for tutorials. - -\section{Constants} - -Some variables are pre-defined on the language itself and cannot be modified; such variables are called \emph{constants}. - -\begin{tabulary}{\textwidth}{rllL} -Name & Type & Value & Description \\ -\hline -NIL & Array & Empty Array & Used to construct arbitrary array using CONS-operator \\ -PI & Number & $3.141592653589793$ & $\pi$ \\ -TAU & Number & $6.283185307179586$ & $2 \pi$ \\ -EULER & Number & $2.718281828459045$ & Euler's number $e$ \\ -\end{tabulary} - -\section{Syntax In EBNF} - -If you're \emph{that} into the language theory of computer science, texts above are just waste of bytes/inks/pixel-spaces/whatever; this little section should be more than enough! - -\verbatiminput{syntax.txt} diff --git a/assets/disk0/tbas/doc/sample_99.tex b/assets/disk0/tbas/doc/sample_99.tex deleted file mode 100644 index 0c02b4d..0000000 --- a/assets/disk0/tbas/doc/sample_99.tex +++ /dev/null @@ -1,17 +0,0 @@ -This is a sample program that prints out the infamous \emph{99 Bottles of Beer}. - -\begin{lstlisting} -10 FOR I = 99 TO 1 STEP -1 -20 MODE = 1 -30 GOSUB 12 -40 PRINT I;" bottle";BOTTLES;" of beer on the wall, ";i;" bottle";BOTTLES;" of beer." -50 MODE = 2 -60 GOSUB 12 -70 PRINT "Take one down and pass it around, ";(I-1);" bottle";BOTTLES;" of beer on the wall." -80 NEXT -90 PRINT "No more bottles of beer on the wall, no more bottles of beer." -100 PRINT "Go to the store and buy some more. 99 bottles of beer on the wall." -110 END -120 IF I == MODE THEN BOTTLES = "" ELSE BOTTLES = "s" -130 RETURN -\end{lstlisting} diff --git a/assets/disk0/tbas/doc/sample_amazing.tex b/assets/disk0/tbas/doc/sample_amazing.tex deleted file mode 100644 index 5e6eac4..0000000 --- a/assets/disk0/tbas/doc/sample_amazing.tex +++ /dev/null @@ -1,142 +0,0 @@ -This is a sample program that draw a randomised maze. The original program was on \emph{BASIC Computer Games: Microcomputer Edition} and was translated into \tbas. - -\begin{lstlisting} -1 OPTIONBASE 1 -10 PRINT SPC(28);"AMAZING PROGRAM" -20 PRINT SPC(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" -30 PRINT:PRINT:PRINT -100 PRINT "WHAT ARE YOUR WIDTH";:INPUT H -102 PRINT "WHAT ARE YOUR LENGTH";:INPUT V -105 IF H<>1 AND V<>1 THEN GOTO 110 -106 PRINT "MEANINGLESS DIMENSIONS. TRY AGAIN.":GOTO 100 -110 WS=DIM(H,V):VS=DIM(H,V) -120 PRINT:PRINT:PRINT:PRINT -160 Q=0:Z=0:X=INT(RND(1)*H+1) -165 FOR I=1 TO H -170 IF I==X THEN GOTO 173 -171 PRINT ".--"; -172 GOTO 175 -173 PRINT ". "; -180 NEXT -190 PRINT "." -195 C=1:WS(X,1)=C:C=C+1 -200 R=X:S=1:GOTO 260 -210 IF R<>H THEN GOTO 240 -215 IF S<>V THEN GOTO 230 -220 R=1:S=1 -222 GOTO 250 -230 R=1:S=S+1:GOTO 250 -240 R=R+1 -250 IF WS(R,S)==0 THEN GOTO 210 -260 IF R-1==0 THEN GOTO 530 -265 IF WS(R-1,S)<>0 THEN GOTO 530 -270 IF S-1==0 THEN GOTO 390 -280 IF WS(R,S-1)<>0 THEN GOTO 390 -290 IF R==H THEN GOTO 330 -300 IF WS(R+1,S)<>0 THEN GOTO 330 -310 X=INT(RND(1)*3+1) -320 ON X GOTO 790,820,860 -334 IF Z==1 THEN GOTO 370 -338 Q=1:GOTO 350 -340 IF WS(R,S+1)<>0 THEN GOTO 370 -350 X=INT(RND(1)*3+1) -360 ON X GOTO 790,820,910 -370 X=INT(RND(1)*2+1) -380 ON X GOTO 790,820 -390 IF R==H THEN GOTO 470 -400 IF WS(R+1,S)<>0 THEN GOTO 470 -405 IF S<>V THEN GOTO 420 -410 IF Z==1 THEN GOTO 450 -415 Q=1:GOTO 430 -420 IF WS(R,S+1)<>0 THEN GOTO 450 -430 X=INT(RND(1)*3+1) -440 ON X GOTO 790,860,910 -450 X=INT(RND(1)*2+1) -460 ON X GOTO 790,860 -470 IF S<>V THEN GOTO 490 -480 IF Z==1 THEN GOTO 520 -485 Q=1:GOTO 500 -490 IF WS(R,S+1)<>0 THEN GOTO 520 -500 X=INT(RND(1)*2+1) -510 ON X GOTO 790,910 -520 GOTO 790 -530 IF S-1==0 THEN GOTO 670 -540 IF WS(R,S-1)<>0 THEN GOTO 670 -545 IF R==H THEN GOTO 610 -547 IF WS(R+1,S)<>0 THEN GOTO 610 -550 IF S<>V THEN GOTO 560 -552 IF Z==1 THEN GOTO 590 -554 Q=1:GOTO 570 -560 IF WS(R,S+1)<>0 THEN GOTO 590 -570 X=INT(RND(1)*3+1) -580 ON X GOTO 820,860,910 -590 X=INT(RND(1)*2+1) -600 ON X GOTO 820,860 -610 IF S<>V THEN GOTO 630 -620 IF Z==1 THEN GOTO 660 -625 Q=1:GOTO 640 -630 IF WS(R,S+1)<>0 THEN GOTO 660 -640 X=INT(RND(1)*2+1) -650 ON X GOTO 820,910 -660 GOTO 820 -670 IF R==H THEN GOTO 740 -680 IF WS(R+1,S)<>0 THEN GOTO 740 -685 IF S<>V THEN GOTO 700 -690 IF Z==1 THEN GOTO 730 -695 Q=1:GOTO 830 -700 IF WS(R,S+1)<>0 THEN GOTO 730 -710 X=INT(RND(1)*2+1) -720 ON X GOTO 860,910 -730 GOTO 860 -740 IF S<>V THEN GOTO 760 -750 IF Z==1 THEN GOTO 780 -755 Q=1:GOTO 770 -760 IF WS(R,S+1)<>0 THEN GOTO 780 -770 GOTO 910 -780 GOTO 1000 -790 WS(R-1,S)=C -800 C=C+1:VS(R-1,S)=2:R=R-1 -810 IF C==H*V+1 THEN GOTO 1010 -815 Q=0:GOTO 260 -820 WS(R,S-1)=C -830 C=C+1 -840 VS(R,S-1)=1:S=S-1:IF C==H*V+1 THEN GOTO 1010 -850 Q=0:GOTO 260 -860 WS(R+1,S)=C -870 C=C+1:IF VS(R,S)==0 THEN GOTO 880 -875 VS(R,S)=3:GOTO 890 -880 VS(R,S)=2 -890 R=R+1 -900 IF C==H*V+1 THEN GOTO 1010 -905 GOTO 530 -910 IF Q==1 THEN GOTO 960 -920 WS(R,S+1)=C:C=C+1:IF VS(R,S)==0 THEN GOTO 940 -930 VS(R,S)=3:GOTO 950 -940 VS(R,S)=1 -950 S=S+1:IF C==H*V+1 THEN GOTO 1010 -955 GOTO 260 -960 Z=1 -970 IF VS(R,S)==0 THEN GOTO 980 -975 VS(R,S)=3:Q=0:GOTO 1000 -980 VS(R,S)=1:Q=0:R=1:S=1:GOTO 250 -1000 GOTO 210 -1010 FOR J=1 TO V -1011 PRINT "|"; -1012 FOR I=1 TO H -1013 IF VS(I,J)<2 THEN GOTO 1030 -1020 PRINT " "; -1021 GOTO 1040 -1030 PRINT " |"; -1040 NEXT -1041 PRINT -1043 FOR I=1 TO H -1045 IF VS(I,J)==0 THEN GOTO 1060 -1050 IF VS(I,J)==2 THEN GOTO 1060 -1051 PRINT ": "; -1052 GOTO 1070 -1060 PRINT ":--"; -1070 NEXT -1071 PRINT "." -1072 NEXT -1073 END -\end{lstlisting} diff --git a/assets/disk0/tbas/doc/sample_hamurabi.tex b/assets/disk0/tbas/doc/sample_hamurabi.tex deleted file mode 100644 index a94ed16..0000000 --- a/assets/disk0/tbas/doc/sample_hamurabi.tex +++ /dev/null @@ -1,142 +0,0 @@ -This is a sample program that is the \emph{Hamurabi} game. The original program was on \emph{BASIC Computer Games: Microcomputer Edition} and was translated into \tbas. This game is considered as the grand ancestor of the strategy, simulation and city-building games; in fact it's so great it has got its own Wikipedia article. - -\begin{lstlisting} -10 PRINT SPC(32);"HAMURABI" -20 PRINT SPC(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" -30 PRINT:PRINT:PRINT -80 PRINT "TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA" -90 PRINT "FOR A TEN-YEAR TERM OF OFFICE.":PRINT -95 D1=0:P1=0 -100 Z=0:P=95:S=2800:H=3000:E=H-S -110 Y=3:A=H/Y:I=5:Q=1 -210 D=0 -215 PRINT:PRINT:PRINT "HAMURABI: I BEG TO REPORT TO YOU,":Z=Z+1 -217 PRINT "IN YEAR ";Z;", ";D;" PEOPLE STARVED, ";I;" CAME TO THE CITY," -220 P=P+I -227 IF Q>0 THEN GOTO 230 -228 P=INT(P/2) -229 PRINT "A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED." -230 PRINT "POPULATION IS NOW ";P -232 PRINT "THE CITY NOW OWNS ";A;" ACRES." -235 PRINT "YOU HARVESTED ";Y;" BUSHELS PER ACRE." -250 PRINT "THE RATS ATE ";E;" BUSHELS." -260 PRINT "YOU NOW HAVE ";S;" BUSHELS IN STORE." -261 PRINT -270 IF Z==11 THEN GOTO 860 -310 C=INT(10*RND(1)) -311 Y=C+17 -312 PRINT "LAND IS TRADING AT ";Y;" BUSHELS PER ACRE." -320 PRINT "HOW MANY ACRES DO YOU WISH TO BUY"; -321 INPUT Q -322 IF Q<0 THEN GOTO 850 -323 IF Y*Q<=S THEN GOTO 330 -324 GOSUB 710 -325 GOTO 320 -330 IF Q==0 THEN GOTO 340 -331 A=A+Q:S=S-Y*Q:C=0 -334 GOTO 400 -340 PRINT "HOW MANY ACRES DO YOU WISH TO SELL"; -341 INPUT Q -342 IF Q<0 THEN GOTO 850 -343 IF QC/2 THEN GOTO 530 -523 REM *** RATS ARE RUNNING WILD!! -525 E=INT(S/C) -530 S=S-E+H -531 GOSUB 800 -532 REM *** LET'S HAVE SOME BABIES -533 I=INT(C*(20*A+S)/P/100+1) -539 REM *** HOW MANY PEOPLE HAD FULL TUMMIES? -540 C=INT(Q/20) -541 REM *** HORROS, A 15% CHANCE OF PLAGUE -542 Q=INT(10*(2*RND(1)-0.3)) -550 IF P