laoki8888 发表于 2009-4-20 22:20:20

[linux]移植bwbasic(BASIC解释器)到arm-linux平台

bwbasic的介绍,是一款Linux平台下的BASIC的解释器

Bywater BASIC Interpreter
The Bywater BASIC Interpreter (bwBASIC) implements a large superset
of the ANSI Standard for Minimal BASIC (X3.60-1978) and a significant
subset of the ANSI Standard for Full BASIC (X3.113-1987) in C.It
also offers shell programming facilities as an extension of BASIC.
bwBASIC seeks to be as portable as possible.

最近要移植一款basic解释器到arm开发板上,本来想移植yabasic的,下了yabaisc的源码包,发现其makefile文件写的太复杂了,都不知道从何改起。继续在ubuntu的新立得里搜索basic解释器,于是就搜到了今天的主角bwbasic。从网上下载到源码包,configure过后,发现makefile异常简洁,完全可以交叉编译,ok,go!

1)首先下载bwbasic-2.20.tar.gz这个文件
点击此处下载 ourdev_438356.zip(文件大小:161K) (原文件名:bwbasic.zip)


2)解压后,在控制台该目录下运行./configure

checking for gcc
checking how to run the C preprocessor
checking for install
checking for size_t in sys/types.h
checking for string.h
checking for stdlib.h
checking for unistd.h
checking for raise
creating config.status
creating Makefile


3)修改Makefile

将CC = gcc改为CC = arm-linux-gcc

4)make,但有个错误

root@kyon-desktop:/4020/BASIC/bwbasic-2.20# make
arm-linux-gcc -c-I. -DHAVE_STRING=1 -DHAVE_STDLIB=1 -DHAVE_UNISTD=1 -DHAVE_RAISE=1 -g -ansi bwbasic.c
bwbasic.c:54: error: initializer element is not constant
make: *** 错误 1


5)修改bwbasic.c文件54行

FILE *errfdevice = stderr;

改为

FILE *errfdevice;

6)make通过
拷到ARM板子上试试吧,可以正确读取a.bas文件

VFS: Mounted root (nfs filesystem).
Freeing init memory: 116K
init started: BusyBox v1.9.2 (2008-08-15 10:15:54 CST)
starting pid 15, tty '': '/etc/init.d/rcS'

********************************
   SEU 4020 ARM Linux-2.6.16   
********************************

# mount all...........
# Starting mdev.........
starting pid 23, tty '': '/bin/sh'
hwclock: settimeofday() failed: Invalid argument
/ # ls
1.txt             demo            mg-samples-1.3.1sbin
1.txt~            dev               mnt               shell
2.txt             espeak            oos.c             sys
2.txt~            etc               oos.c~            test.wav
a.bas             home            osstest         tests
a.bas~            i.mp3             plugins         tmp
bin               lib               proc            usr
bwbasic         linuxrc         root            var
bwbtest         madplay.arm       rt73.ko
/ # ./bwbasic
Bywater BASIC Interpreter/Shell, version 2.20
Copyright (c) 1993, Ted A. Campbell

bwBASIC: load "a.bas"
bwBASIC: list
       :
   20: print "hello,world!"
   30: print "second"
   40: end
bwBASIC: run
hello,world!
second



附录:BWBASIC简单使用手册

========================================================

Bywater BASICBywater BASIC fundamentals
Introduction
This document discusses fundamental operations of using Bywater BASIC on a Unix
computer (such as cis.niagara.edu).
Case sensitivity
Bywater BASIC is case sensitive with respect to programmer-created identifiers
such as variable names. This means, for example, that taxrate, taxRate, and
TAXRATE are 3 distinct variable names.
However, command and function names are not case sensitive.Thus, you may
execute your program via run or RUN; you may compute the absolute value of the
variable x via abs(x) or ABS(x).
Getting into BASIC
At the operating system prompt message, give the command bwbasic.Thus (with
your typing underlined):
cis $ bwbasic
(Note: Unix commands are case sensitive - for example, BWBASIC won't work.) You
should notice that the prompt message changes: the Bywater BASIC prompt message
is
bwBASIC:
as opposed to the Unix prompt
cis $
Retrieving a saved program file
Use a command of the form load "programname".For example, if you have saved a
program using the file name miles.bas, then you can retrieve this program as
follows:
bwBASIC: load "miles.bas"
The quotation marks around the file name are required.
Listing your program
This refers to printing the list of statements that make up the program. You may
list the entire program, or a single line, or a range of lines. Examples:
bwBASIC: list
   10: Rem a few lines of code to demo the behavior of the LIST command
   20: rem Here's a jolly good line of code.
   30: rem Here's a lousy line for attempting to start a relationship.
Assume that the previous example shows the entire program used for the following
examples.
- - - - - - - - - - - -

bwBASIC: list 10-20
   10: Rem a few lines of code to demo the behavior of the LIST command
   20: rem Here's a jolly good line of code.
The above is an example of listing a range of lines, when the lines
corresponding to the first and last linenumber in the range exist in the
program.
- - - - - - - - - - - -

bwBASIC: list 10-15
   10: Rem a few lines of code to demo the behavior of the LIST command
   20: rem Here's a jolly good line of code.
   30: rem Here's a lousy line for attempting to start a relationship.
The above shows if you try to list a range, and the first linenumber of the
range corresponds to an existing line of code but the last linenumber of the
range does not, then the entire program is listed. Other dialects of BASIC would
simply list all lines with linenumbers in the specified range.
- - - - - - - - - - - -

bwBASIC: list 10
   10: Rem a few lines of code to demo the behavior of the LIST command
The above is an example of trying to list one line, when the line requested
exists in the program.
- - - - - - - - - - - -

bwBASIC: list 11

ERROR: Line number 11 not found
Thus if you attempt to list one line using a non-existent linenumber, a message
informs you that no such line exists.
Entering a new line of code, or correcting an existing line
Type the line (with its linenumber) as you wish it to appear in your program.
Note when you list your program, Bwbasic will insert a colon following the
linenumber.
Lines of code are ordered by linenumber - if you enter lines out of order, they
will automatically be sorted (using ascending order) according to their
linenumbers.Since the linenumber must be an integer, it is wise to leave gaps
in your numbering, so that you have the ability to insert additional lines of
code if you decide it's desirable to do so.
Removing an undesired line of code
Just enter the linenumber of the undesired line to remove the line from your
listing. For example, to remove line 15:
bwBASIC: 15
Saving a program file
Use a command of the form save "programname".For example, if you wish to save
your current program using the file name blah.bas, use
bwBASIC: save "blah.bas"
The quotation marks around the file name are required.
Running a program
Running, or executing, a program, is the process of having the program do the
work it's designed to do. This is done via the run command:
bwBASIC: run
Quitting BASIC
Use the command quit -
bwBASIC: quit
This will return you to the operating system prompt message.
Links
Bywater BASIC - more info
To Boxer's home page

aozima 发表于 2009-4-20 22:28:21

LINUX 下玩BASIC!!强...
页: [1]
查看完整版本: [linux]移植bwbasic(BASIC解释器)到arm-linux平台