The text of a manual · part 9 of 47
PDT 1100 Terminal Programmer's Guide: Chapter 2 Development Environment and Procedures, pages 67 to 76
Pages 67 to 76 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 67
Data Types
Parameters for Functions If parameters i and j of the functions below are real expressions, for example, the Interpreter converts them into integers before passing them to each function. CHR$(i),HEX$(i),LEFT$(x$,i),MID$(x$,i,j), RIGHT$(x$,i),...
File Numbers The Interpreter also rounds off file numbers to integers. EOF(f0),LOC(f0),LOF(f0),...
5-9
Page 68
PDT 1100 Terminal Programmer’s Guide
5-10
Page 69
Chapter 6 Expressions and Operators Overview An expression is a combination of constants, variables, and other expressions which are connected using operators. There are two types of expressions – numeric expressions and string expressions. BASIC 3.0 has the following types of operators: Operators
Description
Arithmetic operator
Performs arithmetic operations.
Relational operator
Compares two values.
Logical operator
Combines multiple tests or Boolean expressions into a single true/ false test.
Function operator
Performs the built-in or user-defined functions.
String operator
Concatenates or compares character strings.
Operator Precedence When an expression contains more than one operator, BASIC 3.0 performs the operations in the standard priority of the following.
Precedence 1. Parentheses ( ) Parentheses allow you to override operator precedence; that is, operations enclosed with parentheses are first carried out.
6-1
Page 70
PDT 1100 Terminal Programmer’s Guide
To improve the readability of an expression, use parentheses to separate two operators placed in succession. 2. Function operations 3. Arithmetic operations Operations
Arithmetic Operators
Precedence
–
1
Multiplication and division
* and /
2
Modulo arithmetic
MOD
3
Addition and subtraction
+ and –
4
Logical Operators
Precedence
Logical Negation
NOT
1
Logical multiplication
AND
2
Logical addition
OR
3
Exclusive logical addition
XOR
4
Negation
4. Relational operations =, <>, ><, <, >, <=, >=, =<, => 5. Logical operations Operations
6. String operations When more than one operator occurs at the same level of precedence, the BASIC 3.0 resolves the expression by proceeding from left to right. a=4+5.0/20*2-1
In the above example, the operation order is as follows: 5.0/20 (=0.25) 0.25*2 (=0.5) 4+0.5 (=4.5) 4.5-1 (=3.5)
6-2
Page 71
Expressions and Operators
Operators Arithmetic Operators Arithmetic operators include a negative sign (-) and operators for multiplication (*), division (/), addition (+), and subtraction (-). They also include modulo operator MOD. Operations
Arithmetic Operators
Precedence
–
1
–a
Multiplication and division
* and /
2 a*b, a/b
Modulo arithmetic
MOD
3 a MOD b
Addition and subtraction
+ and –
4 a+b, a–b
Negation
Examples
Modulo Operation (MOD) The MOD operator executes the modulo operation; that is, it divides expression 1 by expression 2 (see the format below) and returns the remainder. Syntax:
expression1 MOD expression2 where one or more spaces or tab codes precede and follow the MOD. If these expressions include real values, the MOD first rounds them off to integers and then executes the division operation. For example, the MOD treats expression 8 MOD 3.4 as 8 MOD 3 and return the remainder “2”.
Overflow and Division by Zero Arithmetic overflow resulting from an operation or division by zero causes an execution error. Such an error may be trapped by error trapping.
6-3
Page 72
PDT 1100 Terminal Programmer’s Guide
Relational Operators A relational operator compares two values, and returns true (–1) or false (0). Use the operation result to control the program flow. Relational operators include the following: Relational Operators
Meanings
Examples
Equal to
A = B
Not equal to
A <> B
<
Less than
A < B
>
Greater than
A > B
<= or =<
Less than or equal to
A <= B
>= or =>
Greater than or equal to
A >= B
= <> or ><
If an expression contains both arithmetic and relational operators, the arithmetic operator has priority over the relational operator.
Logical Operators A logical operator combines multiple tests and manipulates Boolean operands, then returns the results. For example, it controls the program execution flow and tests the value of an INP function bitwise, as shown below. IF d<200 AND f<4 THEN ... WHILE i>10 OR k<0 ... IF NOT p THEN ... barcod% = INP(0) AND &h02
Following are the four types of logical operators available. Operations
6-4
Logical Operators
Precedence
Logical Negation
NOT
1
Logical multiplication
AND
2
Logical addition
OR
3
Exclusive logical addition
XOR
4
Page 73
Expressions and Operators
One or more spaces or tab codes should precede and follow the NOT, AND, OR, and XOR operators. In the logical expressions (or operands), the logical operator first carries out the type conversion to integers before performing the logical operation. If the resulting integer value is out of the range of -32768 to +32767, an execution error occurs. If an expression is equal to 0 (zero) or -1, the logical operation returns 0 or -1, as shown below. PRINT 0 OR (NOT 0) -1
If an expression contains logical operators with arithmetic and relational operators, the logical operators are given lowest priority.
NOT Operator The NOT operator reverses data bits by evaluating each bit in an expression and setting the resultant bits according to the truth table below. Syntax:
NOT expression
Table 6-1. Truth Table for NOT Bit in Expression
Resultant Bit
0
1
1
0
For example, NOT 0 = -1 (true). The NOT operation for an integer has the returned value of negative 1's complement. TheNOT X, for instant, is equal to –(X+1).
6-5
Page 74
PDT 1100 Terminal Programmer’s Guide
AND Operator The AND operator ANDs the same order bits in two expressions on either side of the operator, then sets 1 to the resulting bit if both bits are 1. Syntax:
expression1 AND expression2
Table 6-2. Truth Table for AND Bit in Expression1
Bit in Expression2
Resultant Bit
0
0
0
0
1
0
1
0
1
1
1
1
OR Operator The OR operator ORs the same order bits in two expressions on either side of the operator, then sets 1 to the resulting bit if at least one bit is 1. Syntax:
expression1 OR expression2
Table 6-3.TruthTable for OR
6-6
Bit in Expression1
Bit in Expression2
Resultant Bit
0
0
0
0
1
1
1
0
1
1
1
1
Page 75
Expressions and Operators
XOR Operator The XOR operator XORs the same order bits in two expressions on either side of the operator, then sets the resulting bit according to the truth table below. Syntax:
expression1 XOR expression2
Table 6-4. Truth Table for XOR Bit in Expression1
Bit in Expression2
Resultant Bit
0
0
0
0
1
1
1
0
1
1
1
0
Function Operators The following two types of functions are available in BASIC 3.0 and work as function operators:
Built-in Functions Already built in BASIC 3.0, e.g., ABS and INT.
User-Defined Functions Defined by DEF FN statements in single-line or block form.
String Operators A character string operator may concatenate or compare character strings. Following are the types of operators available. Table 6-5. String Operators Operations
Character String Operators
Examples
Concatenation
+ (Plus sign)
a$+“."+b$
Comparison
= (Equal)
a$=b$
<>, >< (Not equal)
a$<>b$, a$><b$
>, <, =<, =>, <=, >= (Greater or less)
a$>b$, a$=>b$
6-7
Page 76
PDT 1100 Terminal Programmer’s Guide
Concatenation of Character Strings The process of combining character strings is called concatenation and is executed with the plus sign (+). The example below concatenates the character strings, a$ and b$. a$=“Work1” : b$ = “dat” PRINT a$+“."+b$ Work1.dat
Comparison of Character Strings The relational operators compare two character strings according to character codes assigned to individual characters. In the example below, the expression a1$<b1$ returns the value of true to output -1. a1$=“ABC001” b1$=“ABC002” PRINT a1$<b1$ -1
6-8