-------------------------------------------------------------------- -- Copyright (C) 2002 Allen Brown -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License version 2 as -- published by the Free Software Foundation. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the -- Free Software Foundation, Inc. -- 59 Temple Place, Suite 330 -- Boston, MA 02111-1307 USA -- -- To contact the author of this software: -- Allen Brown -- PO Box J -- Corvallis, OR -- -- http://brown.armoredpenguin.com/~abrown/contact.html -------------------------------------------------------------------- Pbasic simulation translator: Pbasic is case insensitive. Translate all variables and addresses to lower case. Use the following shorthand: define $an = \([a-z][a-z0-9_]+\) define $nu = \(-?[0-9].?[0-9]+\) from pbasic to C comment ------------ ----- ---------------- '\(.*\) //\1 PBasic comments are directly converted to C comments. $an var byte pbword8_t \1_w8; Original var name #define \1 \1_w8,pbword8 will be expanded to new var followed by width/point (negative). $an var $an.$an #define \1 \2_w8,\3 Bit fields are the base var followed by the bit pointer. Note that this notation only works for bit fields and if larger fields are to be supported, a new notation will be required. $an con $nu #define \1 pbconst(\2) Constants also expanded to value followed by width/point. output pboutput(); Currently stubbed. input pbinput(); " high pbhigh(); " low pblow(); " $an = pblet(&\1,); $an may be expanded by its define to either a pbword8_t or a bit pointer. if = then $an: if( pbeq(,) ) goto \3; put $nu,$nu pbput(pbconst(\1),pbconst(\2); put $nu,$an pbput(pbconst(\1),\2); get $nu,$an pbget(&\2,pbconst(\1)); gosub $an: Complex. See the code. return goto gosubreturnc; Unwind the stack that was pushed at the gosub call. goto $an: goto \1 serin pbserin Complex. See the code. serout pbserout " shiftout pbshiftout " lookup Complex. See the code. ---------------------------------------------------------- Parts of Expressions abs() pbabs(),pbword8 not() pbnot(),pbword8 MAX pbmax(,),pbword8 MIN pbmin(,),pbword8 + pbadd(,),pbword8 - pbsub(,),pbword8 * pbmul(,),pbword8 / pbdiv(,),pbword8 \ pbmod(,),pbword8 << pbshl(,),pbword8 shift left >> pbshr(,),pbword8 shift right = pbeq(,),pbword8 <> pbne(,),pbword8 > pbgt(,),pbword8 < pblt(,),pbword8 >= pbge(,),pbword8 <= pble(,),pbword8 and pbland(,),pbword8 Logical or pblor(,),pbword8 xor pblxor(,),pbword8 & pbband(,),pbword8 Bitwise | pbbor(,),pbword8 ^ pbbxor(,),pbword8 ---------------------------------------------------------- Not implemented debug Syntax is messy [] Brackets don't seem to provide useful information. var nibble var nib out$nu = value Variables connected directly to pins of the Basic Stamp are not implemented. Also, full syntax checking of the .bsx source file is not done. It is possible to write code that works on this simulator but which is not valid .bsx. And we have discovered that it is possible to have code which passes the bsx syntax checker and simulates but which will not load. This is an unsolved problem. OTOH, some valid .bsx will not compile. In particular, .bsx is cavalier about where variables may be declared. C is far more restrictive. If you place all of your declarations at the beginning of the .bsx file, you will not have trouble with either the simulator or the Basic Stamp. (This issue is why varsboxed.bsx and DefaultProgram1stick.bsx will not translate.) ----------------------------------------------------------