print "this program demonstrates all features." www.rhsgdt.com
for x = 1 to 100
print x; x/2, x; x*x
next
gosub 300
print "hello"
input h
if h10 then print "this is ok"
print a
print a+34
input h
print h
input "this is a test ", y
print h+y
end
300 print "this is a subroutine"
return
下面这个程序演示了子程序的嵌套调用过程:
print "this program demonstrates nested gosubs."
input "enter a number: ", i
gosub 100
end
100 for t = 1 to i
x = x + i
gosub 150
next
return
150 print x;
return
接下来这个程序详细演示了input语句的用法:
print "this program computes the volume of a cube."
input "enter length of first side ", l
input "enter length of second side ", w
input "enter length of third side ", d
t = l * w * d
print "volume is ", t
下面这个程序演示了嵌套的for循环:
print "this program demonstrates nested for loops."
for x = 1 to 100
for y = 1 to 10
print x; y; x*y
next
next
最后这www.rhsgdt.com个程序则使用了所有的关系运算符:
print "this demonstrates all of the relational operators."
a = 10
b = 20
if a = b then print "a = b"
if ab"
if ab then print "a > b"
if a >= b then print "a >= b"
if a <= b then print "a <= b"
对注释器履行增强和扩展
向smalba sic注释器中增加语句并不复杂,可以或许仿照本章中已列出代码的个体花式。如果要增加不同的变量范例,那么必要成立一个新的类以保存该类型和变量的值,尔后再操纵该类型的对象数组来保存变量。
成立本身的计算机语言
对smalba sic注释器履行增强或扩展,www.rhsgdt.com熟识smalba sic把持和谈话注释器工作原理的一种好方法。但是您毋庸规模于ba sic说话。采用本章中描述的注释器技术,可以或许编写出任何计算机语言的注释器,包孕java说话的一个简化子集,甚至可以或许发明能反映自己编程气势和个性的说话。实际上,smalba sic所采用的注释器框架,就是轨范员可能遇到对于任何范例的谈话特性的抱负的测试集”举例来说,向注释器中增加repea t/until循环语句必要遵照如下步调:
1增添repea t和until关键字,并为它定义响应的整型值;
2主循环中的switch语句中添加repea t和until语句;
3界说repeat和until体式格局分袂处置惩罚repea t和until语句首先挪用execforc和next
对于那些喜爱挑衅的轨范员来说,可以或许成立一种脚本语言,以自动执行分歧的计算使命,例如复制或者删除文件、编译轨范等。尔后为该谈话成立一个解释器。这样可以或许供给一种选择,来替代标准的批处理文件,本质上,您可以或许对注释器进行修改,从而完成定制的批处理任务。
======================================================
在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定 这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/