The text of a manual · part 7 of 47
PDT 1100 Terminal Programmer's Guide: Chapter 2 Development Environment and Procedures, pages 47 to 56
Pages 47 to 56 of 413, from PDT 1100 Terminal Programmer's Guide
The original document is the PDF (3.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Symbol PDT-1100
Page 47
Program Structure
Jumping Into/Out of Statement Blocks It is not recommended to jump control from a main routine or subroutines into or out of the middle of significant statement blocks using the GOTO statement. Statement Blocks
Jump into
Jump out
Subroutine
X
X
Error-/event-handling routine
X
X
Block-format user-defined function
X
X
Block-structured statement
X z
X : To be avoided. An execution error may occur. z: Not recommended, although no execution error results. Nesting may cause an execution error. !
!
It is possible to jump control out of the midst of block-structured statements using the GOTO statement, except for FOR...NEXT. Jumping the control out of the midst of FOR...NEXT statement block by the GOTO statement does not directly result in an execution error, although it may eventually if repeated. The program below, for example, should be avoided. FOR I%=0 TO 10 IF I%=5 THEN GOTO AAA ENDIF NEXT I% AAA
Note: Frequent or improper use of GOTO statements in a program decreases debugging efficiency and might cause fatal execution errors. Avoid using GOTO statements, if possible.
3-3
Page 48
PDT 1100 Terminal Programmer’s Guide
Handling User Programs User Programs in the Memory The user area of the memory (RAM and flash ROM) in the PDT 1100 can store more than one user program. If you have selected a user program as an execution program in the Setting menu of System Mode, the PDT 1100 runs the user program when powered on. For the operating procedure of System Mode, refer to the PDT 1100 Terminal Product Reference Guide .
Program Chaining Program chaining, caused by the CHAIN statement below, terminates a currently running user program and transfers control to another program. CHAIN “another.PD3”
To transfer the variables and their values used in the current calling user program to the chained-to program along the program chain, use the COMMON statement as follows: COMMON a$(2),b,c%(3) CHAIN “another.PD3”
The Interpreter writes these declared variable values into the “common variable area” in memory. To make the chained-to program refer to these values, use the COMMON statement again. COMMON a$(2),b,c%(3)
In BASIC 3.0, the name, type, definition order, and number of COMMON-declared variables used in the current calling program must match those in the next program (the chained-to program) since they have special significance, while in MS-BASIC the names of variables may be changed. ' prog1.PD3 COMMON a(10),b$(3),c% : CHAIN “prog2.PD3” ' prog2.PD3 COMMON a(10),b$(3),c% :
3-4
Page 49
Program Structure
Since the COMMON statement is a declarative statement, no matter where it is placed in a source program, the source program results in the same output (same object program), if compiled.
Included Files “Included files” are separate source programs which may be called by the INCLUDE metacommand. When INCLUDE metacommand is encountered in a source program, the Compiler fetches the included file and compiles the main source program while integrating that file to generate a user program. Specify the name of an included file using the REM $INCLUDE or '$INCLUDE. In the included files, describe any of the statements and functions except the REM $INCLUDE and '$INCLUDE. Storing definitions of variables, subroutines, user-defined functions, and other data to be shared by source programs into the included files promotes application of valuable program resources. If a compilation error occurs in an included file, it is indicated on the line where the included file is called by the INCLUDE metacommand in the main source program, but detailed information of syntax errors detected in the included files and the cross reference list is not output. Debug the individual included files carefully beforehand.
3-5
Page 50
PDT 1100 Terminal Programmer’s Guide
3-6
Page 51
Chapter 4 Basic Program Elements Structure of a Program Line Format of a Program Line A program line consists of the following elements: [label] [statement] [:statement] ... [comment]
Labels A label is placed at the beginning of a program line to identify lines. Labels, which designate jump destinations can be used to transfer control to any other processing flow like program branching. They can be omitted if unnecessary. Labels differ from line numbers used in the general BASIC languages; they do not determine the execution order of statements. Write a label beginning in the first column of a program line. To write a statement following a label, place one or more separators (spaces or tabs) between the label and the statement. As shown below, using a label in the IF statement block can eliminate the GOTO statement which should usually precede a jump-destination label. IF a = 1 THEN Check ELSE 500 ENDIF Check and 500 are used as labels.
For detailed information about labels, refer to Labels on page 4-6.
4-1
Page 52
PDT 1100 Terminal Programmer’s Guide
Statements A statement is a combination of functions, variables, and operators according to the syntax. A group of the statements is a program. Statements can come in two types: executable and declarative statements.
Executable statements These cause the Interpreter to process programs by instructing the operation to be executed.
Declarative statements These manage the memory allocation for variables and handle comments. Declarative statements available in BASIC 3.0 are listed below. REM or single quotation mark (') DATA COMMON DEFREG
You can describe multiple statements in one program line by separating them with a colon (:).
Comments Comments make programs easier to understand. An apostrophe (') or REM can begin a comment.
Apostrophe (') An apostrophe (') can begin in the first column of a program line to describe a comment. When following any other statement, a comment starting with an apostrophe requires no preceding colon (:) as a delimiter. ' comment PRINT “abc” 'comment
REM The REM cannot begin in the first column of a program line. When following any other statement, a comment starting with REM requires a preceding colon (:).
4-2
Page 53
Basic Program Elements
REM comment PRINT “abc” :REM comment
Program Line Length and Maximum Number of Lines Terminate a program line with a CR code by pressing the carriage return key. The allowable line length is 512 characters excluding a CR code and the maximum number of lines in a source program is 9,999. Use one of the following methods, however, to write a program line of up to 8192 characters: In the samples below, “↓” denotes a CR code entered by the carriage return key. !
Extend a program line with an underline (_) and a CR code. IF (a$ = “,” OR a$ = “.”) AN AND EOF(d) THEN ...
!
D b<c_ ↓
Extend a program line with a comma (,) and a CR code. FIELD #1,13 as p$,5 a 10 as t $↓ s k$, ↓
The second method (using a comma and CR code) cannot be used for the PRINT, PRINT#, and PRINT USING statements.
Usable Characters Following are characters which can be used for writing programs. Note that a double quote (") cannot be used inside a character string. Symbols | and ~ inside a character string appear as ↓ and → on the LCD of the PDT 1100, respectively. If used outside of a character string, symbols and control codes below have special meaning described in Special Symbols and Control Codes on page 4-4. Letters
Including both uppercase and lowercase letters (A to Z and a to z).
Numerals
Including 0 to 9 for decimal notation, and 0 to 9 and A to F (a to f) for hexadecimal notation.
Symbols
Including the following: $ % * + – . / < = > " & ' ( ) : ; [ ] { } # ! ? @ ¥ | ~ , _
Control codes
CR, space, and tab
4-3
Page 54
PDT 1100 Terminal Programmer’s Guide
Distinction between Uppercase and Lowercase Letters The Compiler makes no distinction between the uppercase and lowercase letters, except for those used in a character string data. The statements below, for example, all produce the same effect. PRINT a print a PRINT A print A
When used in a character string data, uppercase and lowercase letters are distinguished from each other. The statements below, for example, both produce different display output. PRINT “abc” PRINT “ABC”
Special Symbols and Control Codes Symbols and control codes used outside of a character string have the following special meaning: Table 4-1. Symbols and Control Codes Symbols and Control Codes $ (Dollar sign)
String suffix for variables or user-defined functions.
% (Percent sign)
Integer suffix for variables, constants (in decimal notation), or user-defined functions.
* (Asterisk)
Multiplication operator.
+ (Plus sign)
Addition operator or unary positive sign. Concatenation operator in string operation. Format control character in PRINT USING statement.
/ (Slant)
Division operator. Separator for date information in DATE$ function.
. (Period)
Decimal point. Format control character in PRINT USING statement.
– (Minus sign)
4-4
Typical Use
Subtraction operator or unary negative sign.
Page 55
Basic Program Elements
Table 4-1. Symbols and Control Codes (Continued) Symbols and Control Codes < (Less-than sign) = (Equal sign)
> (Greater-than sign)
Typical Use Relational operator. Relational operator. Assignment operator in arithmetic or string operation. User-defined function definition expressions in single-line form DEF FN. Register variable definition expressions. Relational operator.
" (Double quote)
A pair of double quotes delimits a string constant or a device file name.
& (Ampersand)
Integer prefix for constants (in hexadecimal notation), which should be followed by an H. Format control character in PRINT USING statement.
' (Apostrophe)
Initiates a comment. A pair of apostrophes delimits an included file name.
() (Left and right parentheses) : (Colon) (Half-width space)
Delimits an array subscript or a function parameter. Forces the order of evaluation in mathematical, relational, string, and logical expressions. Separates statements. Separates time information in TIME$ function. Separator which separates program elements in a program line. (Note that a two-byte full-width space cannot be used as a separator.)
CR code (Enter)
Terminates a program line.
_ (Underline)
If followed by a CR code, an underline extends one program line up to 8192 characters.
' (Comma)
Separates parameters or arguments. Line feed control character in INPUT and other statements.
@
Format control character in PRINT USING statement.
! (Exclamation mark)
Format control character in PRINT USING statement.
4-5
Page 56
PDT 1100 Terminal Programmer’s Guide
Table 4-1. Symbols and Control Codes (Continued) Symbols and Control Codes # (Pound sign) {} (Braces)
Typical Use File number prefix in OPEN, CLFILE, FIELD, and other statements. Format control character in PRINT USING statement. Define the initial value for an array element.
[] (Square brackets)
Define the length of a string variable. Define the string length of the returned value of a string userdefined function.
; (Semicolon)
Line feed control character in INPUT and other statements.
TAB (Tab code)
Separates program elements in a program line.
Labels A label can contain alphanumeric characters and a period (.).
Rules for naming labels ! ! !
Limit label length to 10 characters including periods. A program can contain up to 9,999 labels. Label names do not distinguish between uppercase and lowercase letters. The following labels, for example, are treated as the same label. filewrite FILEWRITE FileWrite
!
Do not use an asterisk (*) or dollar sign ($) for a label. The following label examples are invalid: *Label0 Label1$
!
A label consisting of only numerals is valid. 1000 1230
4-6