PPL Structure Basics A PPL program is created by a programmer with a standard text editor. Each line consists of standard ASCII text (up to 2048 characters long) terminated with a carriage return/line feed pair. Character case is not significant except in literal text strings. Three types of lines are recognized by the compiler: comment lines, variable declaration statements and code statements. Comments Comments are used by the PPL programmer to make notes in the source code about what the code is supposed to do and generally clarify things so that code maintenance is easier. They are completely ignored by the PPL compiler so they may contain any text desired. A comment may be on a line all by itself or at the end of a line after a valid statement. A blank line is considered a comment. Any text following a quote character (') or semi-colon (;) is also a comment. The following are all valid comments: ; This is a comment line STRING buf, str, ssNum ' This is a comment too ' The blank line above this (as well as these ' lines) are all comments CLS ; Yet *ANOTHER* comment! Variable Declaration Statements Variable declaration statements must start with a keyword denoting the variable type. Valid type keywords are BOOLEAN, DATE, INTEGER, MONEY, STRING and TIME. The keyword must be followed by one or more valid variable names (or array declarations) which should be separated by commas (,). A valid variable name must start with a letter (A-Z) and may contain letters, numbers (0-9) and the underscore character (_). Any number of characters may be used but only the first 32 will be recognized by PPL. If the variable is an array then the name should be followed by an open parenthesis [(], one, two or three constant subscript expressions (separated by commas), and finally a closing parenthesis [)]. Here are some examples: BOOLEAN adultFlag DATE this_IS_a_VARIABLE_to_HOLD_todays_DATE ; Only this_IS_a_VARIALBE_to_HOLD_today is significant INTEGER age MONEY prices(2,5) STRING buf, labels(10), ssNum TIME start, stop Code Statements Code declaration statements must start with a keyword indicating the operation or process to be performed. There is one exception to this rule, however, and that is the LET statement. If no keyword is found at the beginning of a line, a LET statement is implied and the rest of the line should follow the format: VAR = EXPRESSION There are many statements defined in PPL and it is beyond the scope of this part of the manual to cover the precise syntax for each and every one of them. Simply put, a statement takes zero, one or more expressions (see Expressions later in this section) and/or variable names (see Variable Declaration Statements) as arguments (separated by commas), does something, using any passed expressions and/or variables, and assigning new values, as needed, to passed variables. Here are a few sample statements: ' This statement clears the screen and takes no arguments CLS ' Evaluates the single expression and assigns the result to ans LET ans = 5+4*3/2-1 ; Evaluates all three (could be more, could be less) expressions (two of ; which have only one term) and prints them in order, following them ; with a carriage return PRINTLN "The answer "+"is ",STRING(ans),"." ; Evaluate the expression on the left, display it, then get a string ; from the user and assign it to the variable name on the left INPUT "What is "+"your age",current_Age Here are the valid statements accepted in PPL source code: ADJTIME ANSIPOS BACKUP BLT BROADCAST BYE CALL CDCHKOFF CDCHKON CHAT CLOSECAP CLREOL CLS COLOR CONFFLAG CONFUNFLAG DBGLEVEL DEC DEFCOLOR DELAY DELETE DELUSER DIR DISPFILE DISPSTR DISPTEXT DOINTR DTROFF DTRON ELSE ELSEIF END ENDIF ENDWHILE FAPPEND FCLOSE FCREATE FGET FOPEN FOR FORWARD FPUT FPUTLN FPUTPAD FRESHLINE FREWIND GETTOKEN GETUSER GOODBYE GOSUB GOTO HANGUP IF INC INPUT INPUTCC INPUTDATE INPUTINT INPUTMONEY INPUTSTR INPUTTEXT INPUTTIME INPUTYN JOIN KBDCHKOFF KBDCHKON KBDFILE KBDSTUFF LET LOG MESSAGE MORE MPRINT MPRINTLN NEWLINE NEWLINES NEWPWD NEXT OPENCAP OPTEXT PAGEOFF PAGEON POKEB POKEDW POKEW POP PRINT PRINTLN PROMPTSTR PUSH PUTUSER QUEST RDUNET RDUSYS RENAME RESETDISP RESTSCRN RETURN SAVESCRN SENDMODEM SHELL SHOWOFF SHOWON SOUND SPRINT SPRINTLN STARTDISP STOP TOKENIZE VARADDR VAROFF VARSEG WAIT WAITFOR WHILE WRUNET WRUSYS Expressions An expression in PPL can take just about any form imaginable. It consists of one or more constants, variables (see Variable Declaration Statements), functions (which take zero, one or more arguments), or sub-expressions, all of which are separated by PPL operators. Although most statements and functions in PPL expect expressions of a specific type as arguments, you need not pass it an expression of the correct type; PPL will automatically convert from one type to another when it needs to. Here are a few sample expressions: ' Define a few variables to hold expression results INTEGER i, j, k STRING s, t, u ' Single term expressions ' (All expressions here are to the right of the =) LET i = 2 LET j = 3 LET k = 4 LET s = "STRING" ' Complex expressions LET i = i*j*k+2*i+3*j+k/2-5 LET j = i*j*(k+2)*(i+3)*(j+k)/(2-5) LET k = (RANDOM(5)+1)*5+ABS(j) LET t = CHR(i%256) LET u = s+" "+t Constants PPL supports both user defined constants and pre-defined constants. User defined constants may be any of the following: $#.## A MONEY constant (dollar sign followed by optional dollars followed by decimal point followed by cents; # = 0-9) ##h An INTEGER hexadecimal constant (a decimal digit followed by zero, one or more hexadecimal digits followed by an H; # = 0-9 & A-F) ##d An INTEGER decimal constant (one or more decimal digits followed by a D; # = 0-9) ##o An INTEGER octal constant (one or more octal digits f o l l o w e d b y a n O ; # = 0-7) ##b An INTEGER binary constant (one or more binary d i g i t s f o l l o w e d b y a B ; # = 0-1) +/-## An INTEGER constant (an optional plus or minus sign followed by one or more decimal digits; # = 0-9) "X" A STRING constant (a double quote followed by displayable text followed by another double quote; X = any displayable text) @X## An INTEGER @X constant (a commercial at sign followed by an X followed by two hexadecimal digits; # = 0-9 & A-F) The following predefined constant labels are also available. Their values and uses will be defined later. AUTO BELL DEFS ECHODOTS ERASELINE FALSE FCL FIELDLEN FNS F_EXP F_MW F_REG F_SEL F_SYS GRAPH GUIDE HIGHASCII LANG LFAFTER LFBEFORE LOGIT LOGITLEFT NC NEWLINE NOCLEAR O_RD O_RW O_WR SEC STACKED S_DB S_DN S_DR S_DW TRUE UPCASE WORDWRAP YESNO Functions PPL supports many functions which may be used by the programmer in expressions. Here is a list of valid PPL functions. As with the predefined constants, their return values and uses will be documented later. ABORT ABS AND ANSION ASC B2W CALLID CALLNUM CARRIER CCTYPE CDON CHR CURCOLOR CURCONF CURSEC DATE DAY DBGLEVEL DEFCOLOR DOW EXIST FERR FILEINF FMTCC GETENV GETTOKEN GETX GETY GRAFMODE HELPPATH HOUR I2S INKEY INSTR KINKEY LANGEXT LEFT LEN LOGGEDON LOWER LTRIM MASK_ALNUM MASK_ALPHA MASK_ASCII MASK_FILE MASK_NUM MASK_PATH MASK_PWD MAXNODE MGETBYTE MID MIN MINKEY MINLEFT MINON MKADDR MKDATE MODEM MONTH NOCHAR NOT ONLOCAL OR PAGESTAT PCBDAT PCBNODE PEEKB PEEKDW PEEKW PPENAME PPEPATH PSA RANDOM READLINE REGAH REGAL REGAX REGBH REGBL REGBX REGCF REGCH REGCL REGCX REGDH REGDI REGDL REGDS REGDX REGES REGF REGSI REPLACE RIGHT RTRIM S2I SCRTEXT SEC SHOWSTAT SLPATH SPACE STRING STRIP STRIPATX SYSOPSEC TEMPPATH TIME TIMEAP TOKCOUNT TOKENSTR TRIM UPPER UN_CITY UN_NAME UN_OPER UN_STAT U_BDL U_BDLDAY U_BUL U_FDL U_FUL U_INCONF U_LDATE U_LDIR U_LOGONS U_LTIME U_MSGRD U_MSGWR U_NAME U_PWDHIST U_PWDLC U_PWDTC U_RECNUM U_STAT U_TIMEON VALCC VALDATE VALTIME VER XOR YEAR YESCHAR Sub-Expressions A sub-expression is simply any valid PPL expression surrounded by parentheses. For example, this is an expression: 7+6-5*4/3%2 To make it into a sub-expression, surround it with parentheses like this: (7+6-5*4/3%2) This sub-expression could be used in yet another expression: PRINTLN 2*(7+6-5*4/3%2)*RANDOM(4) Operators PPL supports a full set of operators in addition to the functions listed previously. They are: Operator Function ( Starts a sub-expression; requires a ) to terminate Example: 3*(2+1) (result is 9, not 7) ) E n d s a s u b - e x p r e s s i o n Example: 3*(2+1) (result is 9, not 7) ^ Returns the result of raising a number to a s p e c i f i e d p o w e r E x p e c t s a n d r e t u r n s t y p e I N T E G E R Example: 3^2 (result is 9) * Returns the product of two numbers E x p e c t s a n d r e t u r n s t y p e I N T E G E R Example: 3*2 (result is 6) / Returns the quotient of two numbers E x p e c t s a n d r e t u r n s t y p e I N T E G E R Example: 9/4 (result is 2) % Returns the remainder of two numbers E x p e c t s a n d r e t u r n s t y p e I N T E G E R Example: 9%4 (result is 1) + Returns the sum of two numbers or a string c o n c a t e n a t e d t o a n o t h e r Expects and returns type INTEGER or STRING E x a m p l e : 1 + 2 ( r e s u l t i s 3 ) Example: "String plus "+"String" (result is "String plus String") - Returns the difference between two numbers E x p e c t s a n d r e t u r n s t y p e I N T E G E R Example: 3-2 (result is 1) = Returns TRUE if two values are equal Expects any type; returns type BOOLEAN Example: 3 = 3 (result is TRUE) Example: "String" = "STRING" (result is FALSE) <> Returns TRUE if two values are not equal Expects any type; returns type BOOLEAN Example: 3 <> 3 (result is FALSE) Example: "String" <> "STRING" (result is TRUE) < Returns TRUE if a value is less than another Expects any type; returns type BOOLEAN Example: 2 < 3 (result is TRUE) Example: "STRING" < "STRING" (result is FALSE) <= Returns TRUE if a value is less than or equal to a n o t h e r Expects any type; returns type BOOLEAN Example: 2 <= 3 (result is TRUE) Example: "STRING" <= "STRING" (result is TRUE) > Returns TRUE if a value is greater than another Expects any type; returns type BOOLEAN Example: 2 > 3 (result is FALSE) Example: "STRING" > "STRING" (result is FALSE) >= Returns TRUE if a value is greater than or equal to a n o t h e r Expects any type; returns type BOOLEAN Example: 2 >= 3 (result is FALSE) Example: "STRING" >= "STRING" (result is TRUE) ! Returns the logical not of a BOOLEAN value E x p e c t s a n d r e t u r n s t y p e B O O L E A N Example: !TRUE (result is FALSE) & Returns the logical and of two BOOLEAN values E x p e c t s a n d r e t u r n s t y p e B O O L E A N Example: TRUE & FALSE (result is FALSE) | Returns the logical or of two BOOLEAN values Expects and returns type BOOLEAN Example: TRUE | FALSE (result is TRUE) PPL operators have a precedence between one and six that determines which operators get processed first. A precedence of one gets processed first, six gets processed last. Precedence Operators 1 ( ) 2 ^ 3 * / % 4 + - 5 = <> < <= > >= 6 ! & | Binary operators expect both the left and right operands to be of the same type. If they are not then appropriate type conversions will be performed automatically.