BASIC-PLUS-2 User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
BASIC-PLUS-2 User's Guide Order Number : AA-JP35B-TK May 1991 This manual provides tutorial information on BASIC-PLUS-2 language features . It also contains information on advanced program development techniques . Revision/Update Information : This manual is a revision . Operating System and Version : RSX-11M Version 4 .6 or higher RSX-11M-PLUS Version 4 .3 or higher Micro/RSX Version 4 .3 or higher RSTS/E Version 9.7 or higher Software Version : BASIC-PLUS-2 Version 2 .7 Digital Equipment Corporation Maynard, Massachusetts The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation . Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document . The software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license. No responsibility is assumed for the use or reliability of software on equipment that is not supplied by Digital Equipment Corporation or its affiliated companies . Restricted Rights : Use, duplication, or disclosure by the U .S. Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252 .227-7013 . © Digital Equipment Corporation 1987, 1991 . All Rights Reserved . Printed in U .S.A. The postpaid Reader's Comments forms at the end of this document request your critical evaluation to assist in preparing future documentation . The following are trademarks of Digital Equipment Corporation : BASIC-PLUS, BASIC-PLUS-2, DEC, DECnet, DECUS, Digital, DOCUMENT, Micro/RSX, PDP, PDP-11, RMS, RMS-11, RSTS, RSTS/E, RSX, RSX-11M, RSX-11M-PLUS, RX50, TK50, UNIBUS, VAX, VAXcluster, VAXinfo, VMS, and the Digital logo . BASIC is a trademark of Dartmouth College . This document was prepared using VAX DOCUMENT, Version 2 .0. Contents Preface xix Summary of Technical Changes xxv 1 Developing Programs in the BASIC Environment 1 .1 Entering the Environment 1-1 1 .2 Creating Programs 1-3 1 .2.1 Creating a Program Interactively 1-3 1 .2.2 Creating a Program Using a Text Editor 1-4 1 .3 Running Programs 1-4 1 .4 Indirect Command Files 1-5 1 .5 Multiple-Unit Programs 1-6 1 .6 Exiting from the Environment 1-7 1 .7 Immediate Mode 1-8 1 .8 Environment Commands 1-10 1 .8.1 The $ System-Command 1-12 1 .8 .2 The APPEND Command 1-13 1 .8 .3 The BRLRES Command 1-13 1 .8 .4 The BUILD Command 1-13 1 .8 .5 The COMPILE Command 1-14 1 .8 .6 The DELETE Command 1-15 1 .8 .7 The DSKLIB Command 1-15 1 .8.8 The EDIT Command 1-15 1 .8.9 The EXIT Command 1-16 1 .8.10 The EXTRACT Command 1-16 1 .8.11 The HELP Command 1-17 1 .8.12 The IDENTIFY Command 1-17 1 .8.13 The INQUIRE Command 1-17 1 .8.14 The LIBRARY Command 1-17 1 .8.15 The LIST and LISTNH Commands 1-18 1 .8.16 The LOAD Command 1-18 iii 1 .8.17 The LOCK Command 1-19 1 .8.18 The NEW Command 1-19 1 .8.19 The ODLRMS Command 1-19 1 .8.20 The OLD Command 1-20 1 .8.21 The RENAME Command 1-20 1 .8.22 The REPLACE Command 1-20 1 .8.23 The RUN and RUNNH Commands 1-20 1 .8.24 The SAVE Command 1-21 1 .8.25 The SCALE Command 1-22 1 .8.26 The SCRATCH Command 1-22 1 .8.27 The SEQUENCE Command 1-22 1 .8.28 The SET Command 1-23 1 .8.29 The SHOW Command 1-23 1 .8.30 The UNSAVE Command 1-25 1 .9 Setting Environment Defaults with an Initialization File 1-26 2 Developing Programs at DCL Command Level 2.1 Using EDT to Create a BASIC-PLUS-2 Program 2-1 2.2 Compiling a BASIC-PLUS-2 Program 2-2 2.2.1 The BASIC Command 2-3 2.2.2 BASIC Command Qualifiers 2-3 2.2.3 Compiler Listings 2-7 2.2.3.1 Source Program Listing 2-7 2.2.3.2 Cross-Reference Listing 2-9 2.2.3.3 Qualifier Summary 2-11 2.3 Linking a BASIC-PLUS-2 Program 2-12 2.3 .1 The TKB Command 2-12 2.3 .2 The LINK Command 2-13 2.4 Executing a BASIC-PLUS-2 Program 2-14 3 Debugging Programs 3.1 Introduction 3-1 3.2 Invoking the Debugger 3-1 3.3 Sample Debugging Session in the BASIC-PLUS-2 Environment 3-5 3.4 Sample Debugging Session at DCL Command Level 3-7 3.5 Debugger Error Messages 3-18 iv 4 Program Elements 4.1 Line Numbers 4-1 4 .2 Labels 4-2 4.3 Continuing Long Program Statements 4-2 4.4 Identifying Program Units 4-3 4.5 The BASIC-PLUS-2 Character Set 4-4 4.6 Program Documentation 4-4 4.7 Declarations and Data Types 4-5 4.7.1 Implicit Data Typing 4-6 4.7 .2 Explicit Data Typing 4-7 4.8 Constants 4-7 4.9 Variables 4-9 4.9 .1 Floating-Point Variables 4-9 4.9 .2 Integer Variables 4-10 4.9 .3 String Variables 4-10 4.9.4 Subscripted Variables 4-10 4 .9.5 Initialization of Variables 4-11 4 .10 Keywords and Reserved Words 4-11 4 .11 Operands, Operators and Expressions 4-12 4 .12 Assignment Statements 4-13 5 Simple Input-Output 5.1 Program Input 5-1 5.1 .1 Providing Input Interactively 5-1 5.1 .1 .1 The INPUT Statement 5-1 5.1 .1 .2 The INPUT LINE and LINPUT Statements 5-4 5.1 .1 .3 Enabling and Disabling the Question Mark Prompt . 5-4 5.1 .2 Providing Input from the Source Program 5-5 5.1 .2.1 The READ and DATA Statements 5-6 5.1 .2.2 The RESTORE Statement 5-7 5 .2 Program Output 5-8 5 .2.1 Print Zones-the Comma and the Semicolon 5-9 5 .2.2 Output Format for Numbers and Strings 5-12 5 .3 Terminal-Format Files 5-14 5 .3.1 Opening and Closing a Terminal-Format File 5-14 5 .3.2 Writing Records to a Terminal-Format File 5-14 v 6 Control Statements 6 .1 Statement Modifiers 6-1 6 .1 .1 The IF Modifier 6-2 6 .1 .2 The UNLESS Modifier 6-2 6 .1 .3 The FOR Modifier 6-2 6.1 .4 The UNTIL Modifier 6-2 6.1 .5 The WHILE Modifier 6-3 6.1 .6 Nested Modifiers 6-3 6.2 Loops 6-3 6.2.1 FOR. .NEXT Loops 6-4 6.2.2 WHILE ...NEXT Loops 6-7 6.2.3 UNTIL. .NEXT Loops 6-8 6.2 .4 Nested Loops 6-9 6.3 Unconditional Branching 6-9 6.4 Conditional Branching 6-9 6.4 .1 The ON...GOTO. .OTHERWISE Statement 6-10 6.4 .2 The IF.. THEN. .ELSE Statement 6-10 6.4.3 The SELECT. .CASE Statement 6-13 6.5 The EXIT and ITERATE Statements 6-15 6.6 Executing Local Subroutines 6-16 6.6.1 The GO SUB and RETURN Statements 6-17 6.6.2 The ON...GOSUB.. .OTHERWISE Statement 6-18 6.7 Suspending and Halting Program Execution 6-19 6.7.1 The SLEEP Statement 6-19 6.7.2 The WAIT Statement 6-20 6.7.3 The STOP Statement 6-20 6.7.4 The END Statement 6-21 7 Declarations and Data Types 7.1 Declarative Statements 7-1 7.2 Data Types 7-1 7.3 Setting the Default Data Type and Size 7-4 7.4 Declaring Variables Explicitly 7-5 7.5 Declaring Named Constants Explicitly 7-6 7.5.1 Declaring Constants Within a Program Unit 7-7 7.5.2 Declaring Constants External to the Program Unit 7-7 7.6 Operations with Multiple Data Types 7-7 7.7 Allocating Static Storage 7-9 7.7 .1 The COMMON Statement 7-9 vi 7 .7.2 The MAP Statement 7-10 7 .7.2.1 Single Maps 7-10 7.7.2.2 Multiple Maps 7-12 7 .7.3 FILL Items 7-13 7.7.4 Using COMMON and MAP in Subprograms 7-14 7.8 Dynamic Mapping 7-17 8 Functions 8.1 Built-In Functions 8-1 8.1 .1 Using Numeric Functions 8-2 8.1 .1 .1 The ABS Function 8-2 8.1 .1 .2 The INT and FIX Functions 8-2 8.1 .1 .3 The SIN, COS, and TAN Functions 8-3 8 .1 .1 .4 The LOG10 Function 8-4 8.1 .1 .5 The EXP Function 8-5 8.1 .1 .6 The RND Function 8-5 8 .1 .2 Using Data Conversion Functions 8-7 8.1 .2 .1 The ASCII Function 8-7 8.1 .2.2 The CHR$ Function 8-7 8 .1 .3 Using String Numeric Functions 8-8 8.1 .3 .1 The FORMAT$ Function 8-8 8.1 .3.2 The NUM$ and NUM1$ Functions 8-8 8 .1 .3 .3 The VAL% and VAL Functions 8-10 8.1 .4 Using String Arithmetic Functions 8-10 8.1 .4.1 The PLACE$ Function 8-13 8 .1 .4 .2 The PROD$ Function 8-14 8.1 .5 Using Date and Time Functions 8-14 8.1 .5 .1 The DATE$ Function 8-14 8.1 .5 .2 The TIME$ Function 8-15 8.1 .5 .3 The TIME Function 8-15 8 .1 .6 Using Terminal Control Functions 8-16 8.1 .6 .1 The CTRLC and RCTRLC Functions 8-16 8.1 .6 .2 The ECHO and NOECHO Functions 8-17 8 .2 User-Defined Functions 8-17 8.2.1 Single-Line DEF Functions 8-18 8.2.2 Multi-Line DEF Functions 8-19 8 .3 External Functions 8-24 8.3.1 The FUNCTION, EXIT FUNCTION, and END FUNCTION Statements 8-24 8 .3.2 The EXTERNAL Statement 8-25 vii 9 String Handling 9.1 Introduction 9-1 9.2 Using Dynamic Strings 9-2 9.3 Using Fixed-Length Strings 9-4 9.4 String Virtual Arrays 9-5 9.5 Assigning String Data 9-6 9.5 .1 The LET Statement 9-6 9.5 .2 The LSET Statement 9-7 9.5 .3 The RSET Statement 9-8 9.6 Manipulating String Data with String Functions 9-9 9 .6.1 The LEN Function 9-9 9 .6.2 The POS Function 9-10 9 .6.3 The SEG$ Function 9-12 9 .6.4 The MID$ Function 9-14 9 .6.5 The STRING$ Function 9-15 9 .6.6 The SPACE$ Function 9-15 9 .6.7 The TRM$ Function 9-16 9 .6.8 The EDIT$ Function 9-16 9 .7 Manipulating String Data with Multiple Maps 9-18 10 Arrays 10.1 Introduction 10-1 10.2 Creating Arrays Explicitly 10-2 10.2.1 Creating Arrays with the DECLARE Statement 10-3 10.2.2 Creating Arrays with the DIM Statement 10-4 10.2 .2.1 Declarative DIM Statements 10-5 10.2 .2.2 Executable DIM Statements 10-5 10.2 .3 Creating Arrays with the COMMON Statement 10-6 10.2 .4 Creating Arrays with the MAP Statement 10-7 10.3 Creating Arrays Implicitly 10-7 10.3 .1 Referencing an Undeclared Array Element 10-7 10.3 .2 Using MAT Statements 10-9 10.3 .2.1 The MAT Statement 10-10 10.3 .2.2 The MAT READ Statement 10-12 10.3 .2.3 The MAT INPUT [#] Statement 10-13 10.3 .2.4 The MAT LINPUT [#] Statement 10-15 10.3 .2.5 The MAT PRINT [#] Statement 10-16 10.3 .2.6 Matrix I/O Functions 10-17 10.4 Array Input and Output 10-18 10.4 .1 Assigning Values with the LET Statement 10-18 10.4 .2 Listing Array Elements with the PRINT Statement 10-19 10-19 10.5.1 Arithmetic Matrix Operations 10-19 10.5 .1 .1