-------------------------------------------------------------------- -- Copyright (C) 2002,2003 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 $an var $an.$an Too complex to summarize. But the upshot is that all var declarations are handled. $an con #define \1 output pboutput(); Currently stubbed. input pbinput(); " high pbhigh(); " low pblow(); " $an = pblet(&\1,); if = then $an: if( pbeq(,) ) goto \3; All if compares, not just = supported. if/then/else/endif supported. 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. debug printf("DEBUG: ...",...) Must end with CR. Ignores DEC/HEX, but always outputs both. ---------------------------------------------------------- Parts of Expressions abs() pbabs() not() pbnot() MAX pbmax(,) MIN pbmin(,) + pbadd(,) - pbsub(,) * pbmul(,) / pbdiv(,) \ pbmod(,) << pbshl(,) shift left >> pbshr(,) shift right = pbeq(,) <> pbne(,) > pbgt(,) < pblt(,) >= pbge(,) <= pble(,) and pbland(,) Logical or pblor(,) xor pblxor(,) & pbband(,) Bitwise | pbbor(,) ^ pbbxor(,) ~ pbbnot() () Parenthesis supported. ---------------------------------------------------------- Not implemented [] Brackets don't seem to provide useful information. 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. 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. ----------------------------------------------------------