baysick, 一种面向 Scala 实现基本编程语言的嵌入式疯狂语言

分享于 

3分钟阅读

GitHub

 
A Scala DSL implementing the BASIC programming language
  • 源代码名称:baysick
  • 源代码网址:http://www.github.com/fogus/baysick
  • baysick源代码文档
  • baysick源代码下载
  • Git URL:
    git://www.github.com/fogus/baysick.git
    Git Clone代码到本地:
    git clone http://www.github.com/fogus/baysick
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/fogus/baysick
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    

    一种嵌入的疯狂语言,用于实现基本的基本语言子集。

    这里是一个很小的例子:

    
    
    
    
     object SquareRoot extends Baysick {
    
    
     def main(args:Array[String]) = {
    
    
     10 PRINT "Enter a number"
    
    
     20 INPUT 'n
    
    
     30 PRINT "Square root of " % "'n is " % SQRT('n)
    
    
     40 END
    
    
    
     RUN
    
    
     }
    
    
     }
    
    
    
    

    这里是一个较大的例子

    
    
    
    
     object Lunar extends Baysick {
    
    
     def main(args:Array[String]) = {
    
    
     10 PRINT "Welcome to Baysick Lunar Lander v0.0.1"
    
    
     20 LET ('dist := 100)
    
    
     30 LET ('v := 1)
    
    
     40 LET ('fuel := 1000)
    
    
     50 LET ('mass := 1000)
    
    
    
     60 PRINT "You are a in control of a lunar lander."
    
    
     70 PRINT "You are drifting towards the surface of the moon."
    
    
     80 PRINT "Each turn you must decide how much fuel to burn."
    
    
     90 PRINT "To accelerate enter a positive number, to decelerate a negative"
    
    
    
     100 PRINT "Distance " % 'dist % "km, " % "Velocity " % 'v % "km/s, " % "Fuel " % 'fuel
    
    
     110 INPUT 'burn
    
    
     120 IF ABS('burn) <= 'fuel THEN 150
    
    
     130 PRINT "You don't have that much fuel"
    
    
     140 GOTO 100
    
    
     150 LET ('v := 'v + 'burn * 10 / ('fuel + 'mass))
    
    
     160 LET ('fuel := 'fuel - ABS('burn))
    
    
     170 LET ('dist := 'dist - 'v)
    
    
     180 IF 'dist > 0 THEN 100
    
    
     190 PRINT "You have hit the surface"
    
    
     200 IF 'v < 3 THEN 240
    
    
     210 PRINT "Hit surface too fast (" % 'v % ")km/s"
    
    
     220 PRINT "You Crashed!"
    
    
     230 GOTO 250
    
    
     240 PRINT "Well done"
    
    
    
     250 END
    
    
    
     RUN
    
    
     }
    
    
     }
    
    
    
    

    享受吧。

    注意:的基本编程语言是 50年的

    许可证

    版权所有 2010 -2014,Fogus 在MIT许可下许可。
    文件重新分发必须保留上述版权声明。


    IMP  LAN  LANG  SCA  Scala  spec  
    相关文章