Home
xBasic 1.0 - Parallax Forums
Contents
1. 3 1 2 6 negation Syntax expr This expression negates or returns the negative value of expr Example The value of the following expression is negative three 23 xBasic User Manual Page 12 3 1 3 Relational Expressions lt gt lt lt gt gt Relational expressions make arithmetic comparisons between numbers They return O zero to represent FALSE and 1 one to represent TRUE 3 1 3 1 equality The value of this expression is 1 one if the specified expressions are equal to each other otherwise the value is O zero Note This expression should not be confused with the assignment statement Syntax expr expr Examples The value of the following expression is O representing FALSE 3 2 The value of the following expression is 1 representing TRUE 4 4 3 1 3 2 inequality The value of this expression is 1 one if the specified expressions are not equal to each other otherwise the value is O zero Syntax expr lt gt expr Examples The value of the following expression is O representing FALSE 3 lt gt 3 The value of the following expression is 1 representing TRUE 3 lt gt 4 xBasic User Manual Page 13 3 1 3 3 less than The value of this expression is the 1 one if the value of expr is strictly less than the value of expr otherwise the value is 0 zero Syntax expr lt expr Examples The value of the following expressi
2. This example is based on one in the PHP sections of the w3schools com web site One IF statement can be nested inside another DEF furry 1 DEF flying 2 DEF slimy 3 DEF arach 4 IF level MOD 2 1 THEN IF LEVEL gt 5 THEN monster_type furry ELSE monster_type slimy END IF ELSE IF level gt 5 monster_type arach ELSE monster_type END IF END IF Flying 3 3 4 SELECT Syntax SELECT expr CASE case expr case expr statements C CASE ELSE statements xBasic User Manual Page 36 END SELECT This statement performs one or more different statements or sequences of statements based on whether expr matches any of the values in the CASE statements Each CASE statement except the ELSE variant includes one or more case expressions If there are more than one each is separated from the one before it by a comma Each case expr can be either an individual value or a range of value i e expr or lower bound expr TO upper bound expr Individual values and value ranges can be intermixed freely It works this way First expr is evaluated Each case expr in each CASE statement is examined in turn If the case expr is an individual value then if expr is exactly equal to that value then the immediately following statements will be performed or if expr is equal to or greater than Tlower bound expr and less than or equal to upper bound expr then the immediately following sta
3. 32768 32768 Page 9 3 1 1 2 hexadecimal constant The value of this expression is a specific integer value represented as a unsigned hexadecimal number Syntax L Oxhex digit string where hex digit string is from 1 to 4 hexadecimal digits with no intervening characters of any kind The lower bound is 0000 and the upper bound is FFFF The two character string 0x prefixes the hexadecimal number in order to let the compiler and a subsequent human reader know that any decimal digits are actually part of a base sixteen number No space is allowed between the two characters 0 and x or between the x and the hex digit string The letter x must be in lower case it must not be a capital or upper case X A minus negative value symbol may precede the 0x and space is allowed between the sign and the Ox Examples This expression has this value 0x0 O 0x00000 O 0x9 9 0x00009 9 OxF 15 OxOOOOF 15 OxFF 255 OxFFF 4095 Ox7FFF 32767 0x8000 32768 OXFFFF 1 OXFFFFF 1 Oxf 15 0x0000f 5 Oxf 15 OXf upper case X none OxG invalid hex digit none xBasic User Manual Page 10 3 1 1 3 string constant The value of this expression is a specific sequence of printable characters Syntax printable characters The printable characters include the blank 0x20 as well as punctuation digits and upper case and lower case letters The characters of the string must be enclosed in a pair of d
4. PRINT rightTriangleArea 9 8 which would display the number 36 on a line by itself 3 3 3 IF Syntax IF expr THEN statement IF expr THEN ELSE IF expr THEN ELSE END IF This statement is the way for a program to do different things instead of each other depending on circumstances The simplest case provides the means to either do a thing or not do a thing The second form provides a way to do several things or not do them or to do more than one alternative thing or set of things Examples If a value is zero set it to some specific default value IF number_of_monsters O THEN LET number_of_monsters 111 Similarly if some counter has reached a predetermined maximum set it back to one IF N gt 24 THEN N 1 xBasic User Manual Page 34 If you need to do more than one thing or not use this form IF number_of_monsters O THEN LET level level 1 LET number_of_monsters 111 level END IF If you need to do two different things depending on circumstances use this form DEF furry 1 DEF flying 2 IF level MOD 2 1 THEN monster_type furry ELSE monster_type END IF flying xBasic User Manual Page 35 If you need to do more than two different things the IF THEN ELSE IF chain may be your answer DEF Sunday 1 DEF Monday 2 DEF Saturday 7 IF dayOFweek Saturday PRINT Have a nice weekend ELSE IF dayOFweek Sunday PRINT Have a nice Sunday ELSE PRINT Have a nice day
5. is shown in normal typeface The actual syntax is shown in bold face By contrast the meta syntax those characters indicating denoting which pieces of actual syntax are optional or alternatives are shown in normal case Keywords are shown in ALL UPPERCASE although as noted above this is not a requirement of the language it s just used here to help distinguish keywords from things that are not keywords Terms that require further definition and are defined below where they are used are shown in italics xBasic User Manual Page 41 As with BNF brackets and enclose optional pieces of syntax you can include them or leave them out either at your whim or as appropriate to the situation Braces and enclose sets of alternatives each alternative separated from its neighbor s by a vertical bar A trio of dots or periods is used to indicate that the previous piece of syntax may be repeated any number of times 5 1 Labels Any statement may be preceeded by an identifier followed by a colon This is called a label and can be the target of a GOTO statement 5 2 Statements statements statement statements Note This definition is somewhat informal It means that the word statements plural as used in the syntax descriptions above mean either a single statement or more than one statement each on a line by itself 5 3 Statement statement REM comment text t
6. within a hex constant 5 22 string constant string constant printable characters Note There is no specific limit to the length of a strong constant only the practical limit of the available memory The doublequotes one at each end of the string constant are required xBasic User Manual Page 46 5 23 printable characters printable characters printable characters printable character printable characters 5 24 printable character printable character letter digit punctuation mark blank 5 25 alphanums alphanums alphanum alphanum alphanums 5 26 alphanum alphanum letter digit Page 47 xBasic User Manual The following define the which specific characters make up the syntactic items above 5 27 letter letter A BIC D E FIG H I I IJ KILIM NIOIPIQIRISI T U VI IWIXI Y Z albi clditelfilgih i iltljtlktidiom nlolplqirils t tlulvijlwi xfiylz 5 28 punctuation mark punctuation mark Us sar ed ee el eh A 1 i 1 eI Al amp ae Poe eo 1 E Pe Epa I 5 29 hex digit hex digit AI B CI ID EI F al b cld el tf digit 5 30 digit digit 0 1 2 31 4 5 6 7 8 09 Note also that if there is more than one of a particular kind of metavariable they are subscripted for reference in the description 3There are two forms of the DEF statement One is a simple statement requiring no other statements to be c
7. 1 then the corresponding bit in the result is set to 1 otherwise it is set to O zero Syntax expr 8 expr Examples This expression has this value 0 10 0x0000 0x0001 0x0000 1620 0x0001 0x0002 0x0000 2432 0x0002 0x0003 0x0002 256 amp 255 0 OxFFOO OxOOFF 0x0000 21846 21845 O OxAAAA 0x5555 0x0000 21846 256 22016 OxAAAA OXFFOO OXAAOO xBasic User Manual Page 21 3 1 5 5 bitwise shift left The value of this expression is the integer representation of shifting expr left by the number of bits specified by expr Syntax expr lt lt expr Examples This expression has this value 1 lt lt 12 0x0001 lt lt 0x0001 1 lt lt 2 4 0x0001 lt lt 0x0002 1 lt lt 8 256 0x0001 lt lt 0x0008 15 lt lt 4 240 0x000F lt lt 0x0004 15 lt lt 8 3840 Ox000F lt lt 0x0008 255 lt lt 8 256 OxOOFF lt lt 0x0008 255 lt lt 16 0 OxOOFF lt lt 0x0010 0x0002 0x0004 0x0100 Ox00FO Ox0F0O OxFFOO 0x0000 xBasic User Manual Page 22 3 1 5 6 bitwise shift right The value of this expression is the integer representation of shifting expr right by the number of bits specified by expr Note This is an arithmetic shift Hence the sign bit the most significant bit is preserved and is also copied to the next bit to its right for as many bits as specified by expr Syntax expr gt gt expr Examples This ex
8. 7 gt 7 The value of the following expression is 1 representing TRUE 7 gt 6 xBasic User Manual Page 15 3 1 4 Logical Expressions NOT OR AND Logical expressions treat O zero as FALSE and any non zero value as TRUE Similarly they return O zero to represent FALSE and 1 one to represent TRUE Note These are not the same as bitwise operations with the same or similar names Logical operators perform their operations on the whole value of each expression and return either an integer O zero or an integer 1 one bitwise operators see below perform their operations on corresponding bits in each of the expressions and return a new integer representing those result of those operations 3 1 4 1 logical NOT The value of this expression is TRUE if the specified expression is FALSE and is FALSE if the specified expression is TRUE Syntax NOT expr Examples The value of the following expression is 1 representing TRUE NOT 0 The value of the following expression is O representing FALSE NOT 3 xBasic User Manual Page 16 3 1 4 2 logical OR The value of this expression is TRUE if the values of either or both of the specified expressions is or are TRUE Note This operator uses short circuit evaluation That is if expr s TRUE then expr is never even evaluated and the entire expression evaluates to TRUE Syntax expr OR expr Examples The value of the following expressi
9. T X CASE 1 to 3 PRINT would go at top CASE 4 TO 20 PRINT would go in main area CASE 21 TO 23 PRINT would go at bottom CASE ELSE PRINT invalid value END SELECT In the following example there is no CASE ELSE statement Because of this if the variable does not match one of the six specified ranges nothing happens select X CASE 01 TO 03 PRINT X is in first three years of first decade CASE 11 TO 13 PRINT X is in first three years of second decade CASE 21 TO 23 PRINT X is in first three years of third decade CASE 31 TO 33 PRINT X is in first three years of fourth decade CASE 41 TO 43 xBasic User Manual Page 38 PRINT X is in first three years of fifth decade CASE 51 TO 53 PRINT X is in first three years of sixth decade end select 3 3 5 FOR Syntax FOR variable expr TO expr STEP expr statements NEXT variable This statement is the way to do one or more statements over and over again a certain number of times each time setting the value of some variable to a new value First the variable is set of the value of the first expression Then the statements in the middle are executed The NEXT statement indicates that the variable note that this is the same variable that is part of the FOR statement should be set to the next value if the new value of the variable is greater than the second expression the statements in the middle are skipped an
10. a bare Propeller chip using only hub memory or it can make use of various forms of external memory to extend program and data space 2 Command Line Syntax Use the following syntax to compile an XBasic source file xbcom b board type p port r t input file Use the p option to specify the serial port to use to download the compiled program to the Propeller chip If you don t provide this option the default port is COM4 The port will be configured to 115200 baud 8 bits no parity To select COM2 enter either pCOM2 or p2 e Use b hub to compile for hub memory any Propeller board e Use b hub96 to compile for hub memory on a board with a 6mhz crystal 96mhz e Use b c3 to compile for the Parallax C3 board placing the code in the SPI flash and data in the SPI SRAMs e Use b ssf to compile for the SpinSocket Flash board by Steve Denson jazzed e Use r to download and run the program e Use t to enter terminal mode after the download completes xBasic User Manual Page 5 The input file parameter is required as is the b to select the target board The compiler produces an output file with the same name as the input file but with the extension bai in place of bas xBasic User Manual Page 6 3 Language Syntax Names Before going further a discussion of names is in order Several kinds of things are identified by names variables both scalars and arrays constants statement la
11. a part of that function xBasic User Manual Page 7 3 1 Expressions An expression is either a constant a variable or some combination of one or more of those using various operators There are so many that it is helpful to consider them in groups or categories e Constant Expressions decimal constant Oxhex constant string constant e Arithmetic Expressions MOD e Logical Expressions NOT OR AND lt gt lt lt gt gt e Bitwise Expressions amp lt lt gt gt e Other Expressions C variable array reference function call Below are descriptions of each of them by category We examine constant expressions first because we will see them in examples of all the other expressions 3 1 1 Constant Expressions decimal constant hexadecimal constant string constant 3 1 1 1 decimal constant The value of this expression is a specific integer value represented as a signed decimal number Syntax L 3 decimal digit string where decimal digit string is from 1 to 5 decimal digits with no intervening characters of any kind The lower bound is 32768 and the upper bound is 32767 A minus negative value symbol may precede the decimal digit string and space is allowed between the sign and the decimal digit string Examples This expression has this value xBasic User Manual Page 8 xBasic User Manual 00 0 0 000 0 99 09 9 9 9 09 9 32767 32767
12. bels and subroutines and functions A name can be at most 32 characters long A name must start with a letter but can contain letters of either case digits and _ Also a variable name that ends with is assumed to be a string variable unless otherwise specified similarly a variable name that ends with is assumed to be an integer variable It should be noted that XBasic is not case sensitive the names foo Foo and FOO are all the same name as far as it is concerned Programs in XBasic consist of statements Each statement occupies a single line and each line consists of a single statement Expressions Expressions are used in many of the statements of this language While there are some statements that are so simple that they do not require any expressions expressions are so fundamental that we will discuss them before discussing the actual statements Statements Any statement may be preceded by a abel Doing so is required for some purposes but most lines do not require them and should not have them This dialect of BASIC does not support the concept of line numbers The use of labels will be discussed later as necessary Some statements are not complete in and of themselves and must be used in groups or at least in pairs For example the DEF statement begins the definition of a function The END DEF statement is ends the definition All statements in between the two statements are
13. d is a required part of hexadecimal constant expr expr OR expr expr AND expr expr A expr expr expr expr expr expr expr expr lt gt expr expr lt expr expr lt expr expr gt expr expr gt expr expr lt lt expr expr gt gt expr expr expr expr expr xBasic User Manual Page 44 expr expr expr expr expr MOD expr expr NOT expr expr C expr decimal constant Oxhex constant string variable array reference function call 5 11 value l value array reference variable 5 12 array reference array reference variable index gt 5 13 variable variable name 5 14 function call function call name arg arg J Note The argument list including the parentheses may be omitted IFF the function does not require any arguments xBasic User Manual Page 45 5 18 name name letter letter alphanums 5 19 decimal constant decimal constant sign digit string Note The value of a decimal constant must be in the range 32768 through 32767 inclusive Spaces are not allowed within a decimal constant 5 20 digit string digit string digit digit digit string Note Spaces are not allowed within a digit string 5 21 hex constant hex constant hex digit hex digit hex constant Note The value of a hex constant must be in the range 0x0000 through OxFFFF inclusive Spaces are not allowed
14. d the next statement to be executed will be the one immediately following the NEXT statement By default i e if the STEP clause is omitted the next value is always one integer 1 greater than the previous value The variable may be used in the statements between the FOR and NEXT statements or not sometimes you only need it to control how many times a thing is done not use it for anything else Examples Print out the numbers from 1 to 10 FOR j 1 TO 10 PRINT j NEXT j Print out every 3 number from 1 to 20 1 4 7 10 13 16 and 19 FOR j 1 TO 20 STEP 3 PRINT j NEXT j 3 3 6 DO xBasic User Manual Page 39 Syntax DO UNTIL WHILE expr statements LOOP or DO statements LOOP UNTIL WHILE expr This statement is the way to do one or more statements over and over again based on very general criteria In either case in which the test is or appears syntactically before the controlled statements that is DO UNTIL expr or DO WHILE expr the test is performed prior to executing the statements In either case in which the test is or appears syntactically after the controlled statements that is LOOP UNTIL expr or LOOP WHILE expr the test is performed after executing the statements and therefore the loop executes at least once no matter what the value of the expression is The difference between WHILE and UNTIL is that WHILE performs the controlled statements as long as the value of the test expression rema
15. fines a name to have an unchangeable value Example The following defines hundredpi to be a constant whose value is always roughly 100 times the value of Tt DEF hundredpi 314 3 2 5 DIM Syntax DIM variable defs See section variable defs below This statement is the way to declare one or more either scalar or array variables The initializers may be spread over more than one line Examples DIM A DIMA 1 DIM B 3 DIM B 3 1 2 3 3 2 6 LET Syntax LET 7 value expr xBasic User Manual Page 29 This is the assignment statement It assigns the expression to the right of the equals sign to the I value on the left An I value is just a way of saying something that can have a value assigned to it i e either a scalar one dimensional variable or a single element of an array Note that the word LET is optional However if present it must be the first word of the statement and no other word may be there instead Example LETA 7 pixels_per_brick 47 let ballwidth 15 3 2 7 IF Syntax IF expr THEN statement This statement is a way for a program to do a thing or not do a thing Examples If a value is zero set it to some specific default value IF number_of_monsters O THEN LET number_of_monsters 111 Similarly if some counter has reached a predetermined maximum set it back to one IF N gt 24 THEN N 1 3 2 8 GOTO Syntax GOTO label This statement causes the p
16. g or name That is the parentheses are optional if there are no arguments The name is just the name of the function There can be any number of arguments even none at all as long as they match they number of arguments with which the function was defined Each argument can be any expression as long as it matches the type of expression of the corresponding argument with which the function was defined Example Suppose your program contains the following statements which define a function that computes the area of a right triangle given the two orthogonal sides DEF rightTriangleArea sidel side2 rightTriangleArea sidel side2 2 END DEF This function could then be called as follows LET A rightTriangleArea 3 4 which would set the variable A to the value 3 4 2 or 6 Or it could be called this way PRINT rightTriangleArea 9 8 which would display the number 36 that is 9 8 2 on a line by itself Now we are ready to consider the statements that use all these expressions 3 2 Simple Statements Here is a list of statements that stand by themselves INCLUDE REM xBasic User Manual Page 27 DEF DIM IF LET GOTO PRINT STOP END Here are descriptions of each of them 3 2 1 INCLUDE Syntax INCLUDE filename string This statement is the way to include the contents of another file in your program This can be convenient if you have definitions or code that is shared amon
17. g a number of programs so that you don t have to type it again each time you need to use it It is also useful for including standard definitions that come with XBasic like the example below Example INCLUDE chameleon bas 3 2 2 REM Syntax REM comment text to end of line This statement is used to include remarks or comments in the program They are completely ignored by the compiler and do not show up in compiled and downloaded and executed program in any form They are included in a program as a means of communicating to some other programmer or oneself at a future time what a certain part of the program is supposed to do or what algorithm is being used or something of that sort Comments can also be included using the syntaxes common to C and many other languages L comment text to end of Tine comment text between slash asterisk pair and matching asterisk slash pair Examples REM The following takes place xBasic User Manual Page 28 REM on the day of the Massachusetts primary election REM It is the shortest day of my career or The following takes place on the day of the Massachusetts primary election It is the shortest day of my career or LET a 3 Set variable to length of one side LET b 4 Set variable to length of other side 3 2 4 DEF Syntax DEF name value This form of the DEF statement is self contained and merely defines a constant that is it de
18. ins true whereas UNTIL performs the controlled statements as long as the value of the test expression remains false IMPORTANT Unlike the FOR statement the DO statement in all its forms can very easily become an infinite i e never ending loop Specifically if no statement s inside the loop alter any of the variables that make up the expression in the DO or LOOP statement then the expression will never be altered and can never become true for UNTIL or false for WHILE Even changing one or more variables that make up the expression doesn t guarantee that the expression will change from false to true or vice versa so considerable care is required xBasic User Manual Page 40 Examples Get 128 bytes of data from somewhere using a user defined function byteCount 0 DO until byteCount 128 CALL loadByte byteCount byteCount 1 LOOP Get bytes of data from somewhere using a user defined function until an EOF byte is encountered As each byte comes in store it in a buffer and keep a count Don t store the EOF in the buffer or include it in the count DEF EOF Ox0F i 1 do until byte EOF byte getByte if byte EOF THEN buffer i byte i 1 1 END IF LOOP byteCount i 1 5 Language Summary This section summarizes the entire syntax of XBasic using a format very similar to one known as Backus Naur Form or BNF In each definition or production the first term is the one being defined and it
19. ipt The index may be any expression whose value is an integer that is it may not be a floating point value or a string Note array indexes in XBasic start with O zero and range up to the array size 1 Generally an array is used to group together two or more values that are in some sense alike for instance the highest temperature on each day of the year or the wave frequency of each note in a scale or tune Syntax variable index Example Suppose your program includes the following statements LET piano 40 261 C4 LET piano 41 277 C 4 or Db4 LET piano 42 293 D4 LET piano 43 311 D 4 or Eb4 LET piano 44 329 E4 LET piano 45 349 F4 LET piano 46 369 F 4 or Gb4 LET piano 47 391 G4 LET piano 48 415 G 4 or Ab4 LET piano 49 440 A4 LET piano 50 466 A 4 or Bb4 LET piano 51 493 B4 LET piano 52 523 C5 This stores the frequencies of the musical pitches noted in the comments into a set of array elements Yes those frequencies are approximate The index of each array element is the piano key corresponding to that pitch Dim Array Syntax Dim variable index xBasic User Manual Page 26 3 1 6 4 function call The value of a function call is the value of the name of the function immediately prior to ending or returning or exiting See the section later in this document regarding how to define a function Syntax name arg ar
20. lined Subheadings for Syntax Examples and similar topics are merely underlined Specifications of syntax shown using BNF are indented set using Lucida Sans Typewriter a fixed width font bold for example expr MOD expr Within a syntax specification e Keywords are shown like this Metavariables are shown like this e Metasyntactic characters brackets braces vertical bars are shown like this That is monospace but not bold and not italic Within the body of text e A keyword is shown like this e A metavariable is shown like this e A file name is shown like this e A product name is shown like this Examples of operators statements and functions are shown in 11pt Lucida Sans Typewriter for example PRINT abcdefghij 3 4 cdef Headings for such examples are shown in Lucida Sans but in italic and underlined xBasic User Manual Page 4 1 Introduction This system consists of the following parts e the compiler xbcom exe the virtual machine The compiler program is called XBCOM EXE It is an MS Windows console application that is in runs on MS DOS or under MS Windows but only using the COMMAND or CMD application You will need to use one of those methods to navigate to the folder and run command lines with arguments A full description of the command line syntax is given below The virtual machine VM runs on the Parallax Propeller Chip P8X32A It can either run on
21. n of the inclusive OR of the corresponding bits of the specified expressions That is if a given bit in expr is set to 1 or the corresponding bit in expr is set to 1 or both bits are set then the corresponding bit in the result is set to 1 otherwise it is set to O zero Syntax expr expr Examples This expression has this value O 11 0x0000 0x0001 0x1 1123 0x0001 0x0002 0x0003 2133 0x0002 0x0003 0x0003 256 255 1 OxFFOO OxOOFF OXFFFF xBasic User Manual Page 19 3 1 5 3 bitwise exclusive OR The value of this expression is the integer representation of the exclusive OR of the corresponding bits of the specified expressions That is if a given bit in expr is set to 1 orthe corresponding bit in expr is set to 1 but not both bits are set then the corresponding bit in the result is set to 1 otherwise it is set to O zero Syntax expr expr Examples This expression has this value 0A11l 0x0000 A 0x0001 0x0001 1423 0x0001 0x0002 0x0003 2431 0x0002 A 0x0003 0x0001 65280 255 1 OxFFOO A OxOOFF OxFFFF 43690 A 21845 1 OxAAAA A 0x5555 OxFFFF 43690 A 65280 21930 OxAAAA A OXFFOO Ox55AA xBasic User Manual Page 20 3 1 5 4 bitwise AND The value of this expression is the integer representation of the AND of the corresponding bits of the specified expressions That is if a given bit in expr is set to 1 and the corresponding bit in expr is set to
22. nguage SUMMARY sisi ia a Neal chstessepetaroussaagySers 41 xBasic User Manual Page 2 eM ADE ON 42 Did ta MO coin dinar Tania renta E TEA A EE E EE S a E ARE AEE EAEE ASAN a EES 42 5 3 Statement PO OOO niia supa v ania i aE a Sea iA Vane A Ea a EEEE EE ani Aa K 42 5 4 variable defs OO 43 BS Vana DOG pecs sicesccctescneasuscacvates a a E a E susesestersvacteasantess 43 5 6 Dasic Variable det aci aude at ohare didnt A eee ee 43 IAN Pi a A A AA a o 43 SS iM AIZEN A A A 44 e D a OM EEE EET T T A E E A EE A T T 44 ELO o E e in cavveeeeosaelveneeed 44 5 TLJ Ue aa tases aa a a ace eE AN AEN EE E aE E 45 5 T2 aray reference treen ee EE a N er a EE A r E E aR 45 SS Vala aii NEN 45 5 14 f nction Call viii ia 45 LIN AM aca 46 5 19 decimal constat issis ipiis niani aniani iiaae aaki aaaeaii 46 S20 digit Sting O OA 46 5 21 NEC Mii a E a a a N a a 46 3 22 SEINEB CONStaN Linera 46 5 23 printable Ch TICS 0 A A AAA a a 47 5 24 printablesch aci is N 47 A ET 47 5 26 PNUMA A dl a Shee an 47 5 27 lettet sirmus aides eed iy nee a eet nde dee ed cee eee 48 5 28 p nct ation mank sesceds occtecciescseidudes A cadesetdeceds ands cacaeeeiiuand iucdseskeddesdeuesecesseiieedeats ace 48 By DOME Eo Y y ROO EE TAS 48 O 48 xBasic User Manual Page 3 Typography Used in This Manual The body of this manual is set using 12pt Lucida Sans a variable width font Section headings are numbered and in bold face and the text but not the numbers is under
23. o end of Tine OPTION TARGET tile bitmap DEF name value DEF name arg arg END DEF DIM variable defs LET 7 value expr IF expr THEN statement IF expr THEN ELSE IF expr THEN ELSE END IF SELECT CASE CASE ELSE xBasic User Manual Page 42 END SELECT FOR var expr TO expr STEP expr NEXT var DO DO WHILE expr DO UNTIL expr LOOP LOOP WHILE expr LOOP UNTIL expr GOTO label function name arg arg PRINT STOP END 5 4 variable defs variable defs variable def variable defs variable def 5 5 variable def variable def basic variable def initializer 5 6 basic variable def basic variable def variable AS type variable size AS type 5 7 type type xBasic User Manual Page 43 BYTE INTEGER STRING 5 8 initializer initializer init expr init expr init expr 5 9 init expr init expr an expression composed of integer constants and possible also simple arithmetic operators 5 10 expr In what follows it may not always be clear that the punctuation marks that either are between one expr and another or precede the expr or surround the expr are in bold face They are just like the keywords OR AND MOD and so forth As such they are required Likewise it may not be clear that Ox is in bold face It is an
24. omplete That form is described in this section The other form requires a matching END DEF statement and is described in the Compound Statements section below 4There are two forms of the IF statement One is a simple statement requiring no other statements to be complete That form is described in this section The other form requires a matching END IF statement and may also include ELSE or ELSE IF statements and is described in the Compound Statements section below xBasic User Manual Page 48 5There are two forms of the DEF statement One is a simple statement requiring no other statements to be complete That form is described in the Simple Statements section above The other form requires a matching END DEF statement and is described in the this section 6There are two forms of the IF statement One is a simple statement requiring no other statements to be complete That form is described in the Simple Statements section above The other form requires a matching END DEF statement and may also include ELSE or ELSE IF statements and is described in the this section xBasic User Manual Page 49
25. on is O representing FALSE 4 lt 3 The value of the following expression is O representing FALSE 4 lt 4 The value of the following expression is 1 representing TRUE 4 lt 5 3 1 3 4 less than or equal to The value of this expression is the 1 one if the value of expr is less than or equal to the value of expr otherwise the value is O zero Syntax expr lt expr Examples The value of the following expression is O representing FALSE 4 lt 3 The value of the following expression is 1 representing TRUE 4 lt 4 The value of the following expression is 1 representing TRUE 4 lt 5 xBasic User Manual Page 14 3 1 3 5 greater than The value of this expression is the 1 one if the value of expr is strictly greater than the value of expr otherwise the value is 0 zero Syntax expr gt expr Examples The value of the following expression is O representing FALSE 6 gt 7 The value of the following expression is O representing FALSE 7 gt 7 The value of the following expression is 1 representing TRUE 7 gt 6 3 1 3 6 greater than or equal to The value of this expression is the 1 one if the value of expr is greater than or equal to the value of expr otherwise the value is O zero Syntax expr gt expr Examples The value of the following expression is O representing FALSE 6 gt 7 The value of the following expression is 1 representing TRUE
26. on is O representing FALSE OORO The value of the following expression is 1 representing TRUE 0 OR 3 The value of the following expression is 1 representing TRUE 12 ORO The value of the following expression is 1 representing TRUE 11 OR 1 3 1 4 3 logical AND The value of this expression is TRUE if the values of both of the specified expressions are TRUE Note This operator uses short circuit evaluation That is if expr iS FALSE then expr is never even evaluated and the entire expression evaluates to FALSE Syntax expr AND expr Examples The value of the following expression is O representing FALSE O AND O The value of the following expression is O representing FALSE O AND 3 The value of the following expression is 0 representing FALSE 12 ANDO The value of the following expression is 1 representing TRUE 11 AND 1 3 1 5 Bitwise Expressions amp lt lt gt gt xBasic User Manual Page 17 3 1 5 1 bitwise NOT The value of this expression is the integer representation of the inversion or ones complement of the bits of the specified expression Syntax expr Examples This expression has this value 0 1 0x0000 OXFFFF 10 OXFFFF 0x0000 2 1 OXFFFE 0x0001 256 255 OXFFOO OxOOFF 275 274 OXFEED 0x0112 xBasic User Manual Page 18 3 1 5 2 bitwise inclusive OR The value of this expression is the integer representatio
27. ouble quotes a double quote character may be included in the string by preceding it with a backslash in the manner of the C language and its descendents Examples This statement produces this output PRINT ABcd 09 2 ABcd 09 PRINT ABcd 09 ABcd 09 PRINT ABcd 09 2 ABcd 09 2 3 1 2 Arithmetic Expressions Arithmetic expressions include those with the following operators MOD 3 1 2 1 addition Syntax expr expr This expression adds expr to expr number Example The value of the following expression is 11 6 5 3 1 2 2 subtraction Syntax expr expr This expression subtracts expr from expr Example The value of the following expression is 6 11 5 3 1 2 3 multiplication xBasic User Manual Page 11 Syntax expr expr2 This expression multiplies expr by expr Example The value of the following expression is 30 6 5 3 1 2 4 division Syntax expr expr This expression divides expr by expr Example The value of the following expression is 6 30 5 3 1 2 5 modulo Syntax expr MOD expr This expression divides expr by expr and returns the remainder Example The value of the following expression is 0 30 MOD 5 The value of the following expression is also 0 30 MOD 6 The value of the following expression is 1 31 MOD 5 The value of the following expression is 2 30 MOD 4
28. pression has this value 1 gt 10 0x0001 gt gt 0x0001 0x0000 1 gt 20 0x0001 gt gt 0x0002 0x0000 2 gt 11 0x0002 gt gt 0x0001 0x0001 15 gt gt 1 7 Ox000F gt gt 0x0001 0x0007 240 gt gt 4 15 Ox00FO gt gt 0x0004 Ox000F 256 gt gt 8 1 OxFFOO gt gt 0x0008 OXxFFFF 256 gt gt 16 1 OxFFOO gt gt 0Ox0010 OxFFFF xBasic User Manual Page 23 3 1 6 Other Expressions C variable array reference function call 3 1 6 1 parentheses The value of this expression is the value of the expression inside the matched pair of parentheses Syntax expr Parentheses simply provide the traditional way of grouping expressions together particularly for the purpose of over riding operator precedence Examples This expression has this value 6 2 47 xBasic User Manual Page 24 3 1 6 2 variable A variable is simply a value that changes while the variable name remains the same Syntax variable Examples This expression or statement has this value or does this x undefined LET x 6 assigns x the value 6 LET y 2 assigns y the value 2 z 4 assigns z the value 4 x6 y2 z4 x y3 y z6 x y z7 x y z7 x y zZ 1 z x y7 z x y5 xBasic User Manual Page 25 3 1 6 3 array reference or element An array is simply a variable that can contain or represent more than one value simultaneously each one distinguished from the others by its index or subscr
29. r is a semicolon the second expression will appear immediately adjacent to the previous expression in effect they will appear to be concatenated On the other hand if the separator is a comma the second expression will begin at the next 8 column on the line Examples Print an empty or blank line PRINT Print the number 7 on a line by itself LET A 7 PRINT A Print 4715 ona line by itself xBasic User Manual Page 31 LET pixels_per_brick 47 LET ballWidth 15 PRINT pixels_per_brick ballWidth Print 47 15 that is 47 followed by 6 blanks or spaces followed by 15 on a line PRINT pixels_per_brick ballWidth 3 2 12 STOP Syntax STOP This statement tells the program to stop altogether regardless of where in the program it appears or how it was encountered 3 2 13 END Syntax END This statement tells the compiler that it is the last statement of the program It has no effect on the program at run time It is optional but its use is encouraged xBasic User Manual Page 32 3 3 Compound Statements Here is a list of statements that must appear in groups DEF END DEF SUB END SUB IF ELSE IF ELSE END IF SELECT CASE CASE ELSE END SELECT FOR NEXT DO LOOP Here are descriptions of each of them 3 3 1 DEF This form of the DEF statement defines a function Syntax DEF name arg arg END DEF The statement itself with the name and pa
30. rentheses and arguments specifies how the function will be called It must be followed by a matching END DEF statement as shown All the statements in between specify what the function does to achieve the result that it returns In this form the END DEF statement is required Note that if the function does not use any arguments the entire argument list including the parentheses may be omitted Inside of the function the function s name is used as a variable to which to assign the return value the value of that variable at the time the function completes execution is the return value of the function There is no RETURN statement as in some other dialects of BASIC xBasic User Manual Page 33 Examples The following defines a function that computes the area of a right triangle given the two orthogonal sides The body of the function consists of just two statements which compute the area of the square and divides that by 2 and assigns that the name of the function DEF rightTriangleArea sidel side2 rightTriangleArea sidel side2 rightTriangleArea rightTriangleArea 2 END DEF The body of this function could just as easily be written as a single line as follows DEF rightTriangleArea sidel side2 rightTriangleArea sidel side2 2 END DEF This function could then be called as follows LET A rightTriangleArea 3 4 which would set the variable A to the value 6 Or it could be called this way
31. rogram execute the statement at label instead of executing the statement immediately following the GOTO statement The GOTO statement seems obvious and innocent at first but has generally been found to cause complexity and confusion if used more than sparingly The XBasic language has many ways to organize sequences of statements in an orderly way so the GOTO statement should be easy to avoid in most cases xBasic User Manual Page 30 Note GOTO in the main code can refer only to labels in the main code GOTO within a function or subroutine can refer only to labels within the same function or subroutine Example LET x 1 abc LET x x 1 GOTO hijk efg LET x x 5 GOTO efg hijk LET x x 2 STOP END Two questions immediately arise 1 Does this program ever finish 2 What is the value of x if and when it does 3 2 10 PRINT This statement sends text to the serial interface To send text to the screen see the DISPLAY statement below Syntax PRINT expr expr J The text will represent zero or more expressions as specified in the statement Each expression may be a string or decimal or hexadecimal constant or a scalar variable or an array element If no expressions are included a blank line is displayed If only one expression is included no other syntax is required If more than one expression is included each must be separated from the next by either a comma or a semicolon If the separato
32. tements will be performed If none of the ordinary CASE statements match expr but there is a CASE ELSE statement the immediately following statements will be performed If and when a matching CASE is encountered and the immediately following statements are peformed all further statements including CASE statements will be ignored until the matching END SELECT statement The SELECT statement may be thought of as an express version of a sequence of IF THEN ELSE IF END IF statements where a the initial IF comparison and all the ELSE IF comparisons all involve the same variable or expression and b the comparison is always one of equality Rather than repeating that variable or expression and the equality operator in the SELECT statement the expression is specified only once and comparison of equality is implied xBasic User Manual Page 37 Examples The following examines a simple variable and compares it to a range and to members of a list and does something different in each case if neither case applies the CASE ELSE statement does something else entirely select X case 1 to 3 Use a range print would go at top case 21 22 23 Use a list print would go at bottom case else Catch all other cases print would go in main area end select One can readily see that if X is outside the expected range 1 through 23 inclusive this will behave badly A better rendering would be SELEC
33. xBasic 1 0 User Manual Copyright O 2009 Kenneth G Goutal All rights reserved Updates Copyright O 2009 2011 David M Betz This manual describes the xBasic system version 1 0 xBasic User Manual Page 1 Table of Contents Introducir tri errs tad 5 2 Command Line Sta iii A Ad da dd 5 3 Language Md do is 7 SA A Guia nsas ce a a A E sesuuausas ress carshgucnaccenancecess 8 a A cies cacugeetbesctaltenenstchdthucesceaavavevasduevecdsiveverersiteeenessded 8 3 1 2 Arithmetic EXPressiOns wisciiseseciscsses diia aid ici 11 3 1 3 Relational Expressions ccccocconooooooononnnnnnnnnnonnnonononononnnnnnonnnnn non nnnnnnnnnnnnnnnnne non nnnnnnnnnnnnnnannnn conan 13 3 14 Logical EXPressiONS curn A A e eae Sheen ets 16 3 1 5 Bitwise EXPreSSIONS c ccecs sccsceecaevasescaeseseveercecderesesdvevvens canteeaeecnbcertemsabaeaueessduesererseseverescsdesivieecd 17 3 1 6 Other EXPESSI ONS aia a 24 3 2 Simple Statement a dt 27 3 2 1 INCLUDE coo AR 28 3 2 2 RE Mision A EA Aa 28 32 Dri actoral 29 3 215 DIM hreina E AR A AAE seesnteestecaes eases 29 3 26 LE Toripe Ae E EERTE E EE EAA EALA EEG ER eee 29 O O 30 3128 GOTO ota 30 322210 PRINT ta E ia 31 32D STOP uc a o ida 32 32 I3 BIND eae cae AO 32 3 3 Compound Statements viccccicseccccicedsseccadeessccccdeevsscceaesscescacecsvsscccadeuecceadvusvedsadacdveccceteesedscaeusvenstededenbecd 33 3 3 1 DEl is 33 O TO 34 3 3 A SELECT 1 ic 36 33 5 FOR ainicin iea a E E A a A 39 3 3 6 DO NN 39 Sla
Download Pdf Manuals
Related Search
Related Contents
取扱説明書[SR-SPX104/184] (17.13 MB/PDF) ₄₀₀LMT / MY ₄₅₀LMT ₂₅₀LM Scarica - Safescan.com TuneUp Utilities - 2009 User's Manual Copyright © All rights reserved.
Failed to retrieve file