ArnoldC:关键字出自斯瓦辛格电影的趣味编程语言

jopen 11年前

        英文原文:ArnoldC

        ArnoldC 是一种命令式编程语言,其基本的关键字均出自阿诺·斯瓦辛格的电影。该语言编写的程序可用 Parboiled 和 ASM 解析成 Java 字节码。

        下面一起来看看如何使用这种蛋疼趣味语言。

ArnoldC:关键字出自斯瓦辛格电影的趣味编程语言

        Main 方法

        每个 ArnoldC 程序必须有一个 main 方法。如下:

IT'S SHOWTIME [语句]  YOU HAVE BEEN TERMINATED

        最简单的 ArnoldC 程序如下:

IT'S SHOWTIME   YOU HAVE BEEN TERMINATED

        语句

        输出

        TALK TO THE HAND  语句用于打印输出字符串或变量。打印字符串:

TALK TO THE HAND "cnblogs"

        打印变量:

TALK TO THE HAND myvar

        声明变量

        ArnoldC 语言中唯一的变量类型是 16 位的有符号整数。必须在声明时赋值。

HEY CHRISTMAS TREE variablename  YOU SET US UP initialvalue

        @I LIED 和 @NO PROBLEMO 这两个“宏” 对应的值是  0 和 1

        声明两个变量,值分别是 0 和 1

HEY CHRISTMAS TREE varFalse  YOU SET US UP @I LIED  HEY CHRISTMAS TREE varTrue  YOU SET US UP @NO PROBLEMO

        变量赋值

        变量赋值语句用如下格式:

GET TO THE CHOPPER myvar  HERE IS MY INVITATION firstOperand  [operations]  ENOUGH TALK

        HERE IS MY INVITATION 用来对栈顶的变量做赋值。经过其他操作,最终赋值给变量 myvar。

        算术操作

        加法

GET UP operand

        减法

GET DOWN operand

        乘法

YOU'RE FIRED operand

        除法

HE HAD TO SPLIT operand

        所有算术操作优先级同一样。比如: a = (4 + b) * 2

GET TO THE CHOPPER a  HERE IS MY INVITATION 4 GET UP b  YOU'RE FIRED 2 ENOUGH TALK

        逻辑操作

        真语句的值为 1,假语句的值为 0。

        等于

YOU ARE NOT YOU YOU ARE ME operand

        大于

LET OFF SOME STEAM BENNET operand

        或

CONSIDER THAT A DIVORCE operand

        与

KNOCK KNOCK operand

        比如: a = (b + 5) > c

GET TO THE CHOPPER a  HERE IS MY INVITATION b  GET UP 5 LET OFF SOME STEAM BENNET c  ENOUGH TALK

        比如 a = (b c) && d

GET TO THE CHOPPER a  HERE IS MY INVITATION b  CONSIDER THAT A DIVORCE c  KNOCK KNOCK d  ENOUGH TALK

        条件语句

        如果 value 非0,执行条件分支

        If

if (value) [statements]    BECAUSE I'M GOING TO SAY PLEASE value [statements]  YOU HAVE NO RESPECT FOR LOGIC

        If Else

if (value) [statements] else [statements]    BECAUSE I'M GOING TO SAY PLEASE value [statements]  BULLSHIT  [statements]  YOU HAVE NO RESPECT FOR LOGIC

        例1

if(a) print "a is true" else print "a is not true" BECAUSE I'M GOING TO SAY PLEASE a TALK TO THE HAND "a is true"  BULLSHIT   TALK TO THE HAND "a is not true"  YOU HAVE NO RESPECT FOR LOGIC

        例 2  条件语句的值必须先计算 if (a > b) print “a is greater than b”

GET TO THE CHOPPER result  HERE IS MY INVITATION a  LET OFF SOME STEAM BENNET b  ENOUGH TALK  BECAUSE I'M GOING TO SAY PLEASE result TALK TO THE HAND "a is greater b" YOU HAVE NO RESPECT FOR LOGIC

        While

STICK AROUND value   [statements]   CHILL

        例子  打印 1 到 10

IT'S SHOWTIME HEY CHRISTMAS TREE isLessThan10  YOU SET US UP @NO PROBLEMO  HEY CHRISTMAS TREE n  YOU SET US UP  STICK AROUND isLessThan10  GET TO THE CHOPPER n  HERE IS MY INVITATION n  GET UP 1 ENOUGH TALK  TALK TO THE HAND n  GET TO THE CHOPPER isLessThan10  HERE IS MY INVITATION 10 LET OFF SOME STEAM BENNET n  ENOUGH TALK  CHILL  YOU HAVE BEEN TERMINATED

        方法

        方法必须在主函数外定义。方法参数用 I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE 定义。每个变量必须单独定义。GET YOUR ASS TO MARS 放在方法申明末尾,表明该方法是非空方法。I’LL BE BACK 就是 RETURN,根据方法是否为空,可以带一个变量。

        空方法

LISTEN TO ME VERY CAREFULLY methodName  [Statements]  HASTA LA VISTA, BABY

        一个带两个参数的非空方法

LISTEN TO ME VERY CAREFULLY methodName  I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE arg1  I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE arg2  GET YOUR ASS TO MARS  [Statements]  HASTA LA VISTA, BABY

        典型示例

        更多例子可以在测试包中查看

        Printing squares from 1 to 10

IT'S SHOWTIME HEY CHRISTMAS TREE limit  YOU SET US UP 10 HEY CHRISTMAS TREE index  YOU SET US UP 1 HEY CHRISTMAS TREE squared  YOU SET US UP 1 HEY CHRISTMAS TREE loop  YOU SET US UP @NO PROBLEMO  STICK AROUND loop  GET TO THE CHOPPER squared  HERE IS MY INVITATION index  YOU'RE FIRED index ENOUGH TALK  TALK TO THE HAND squared  GET TO THE CHOPPER loop  HERE IS MY INVITATION limit  LET OFF SOME STEAM BENNET index  ENOUGH TALK  GET TO THE CHOPPER index  HERE IS MY INVITATION index  GET UP 1 ENOUGH TALK  CHILL  YOU HAVE BEEN TERMINATED

        申明一个 modulo 函数,并在主函数调用它

IT'S SHOWTIME HEY CHRISTMAS TREE result1  YOU SET US UP  HEY CHRISTMAS TREE result2  YOU SET US UP  HEY CHRISTMAS TREE result3  YOU SET US UP  HEY CHRISTMAS TREE result4  YOU SET US UP  GET YOUR ASS TO MARS result1  DO IT NOW modulo 9 4 TALK TO THE HAND result1  GET YOUR ASS TO MARS result2  DO IT NOW modulo 4795 87 TALK TO THE HAND result2  GET YOUR ASS TO MARS result3  DO IT NOW modulo 3978 221 TALK TO THE HAND result3  GET YOUR ASS TO MARS result4  DO IT NOW modulo 5559 345 TALK TO THE HAND result4  YOU HAVE BEEN TERMINATED  LISTEN TO ME VERY CAREFULLY modulo  I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE dividend  I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE divisor  GIVE THESE PEOPLE AIR  HEY CHRISTMAS TREE quotient  YOU SET US UP  HEY CHRISTMAS TREE remainder  YOU SET US UP  HEY CHRISTMAS TREE product  YOU SET US UP  GET TO THE CHOPPER quotient  HERE IS MY INVITATION dividend  HE HAD TO SPLIT divisor  ENOUGH TALK  GET TO THE CHOPPER product  HERE IS MY INVITATION divisor  YOU'RE FIRED quotient ENOUGH TALK  GET TO THE CHOPPER remainder  HERE IS MY INVITATION dividend  GET DOWN product  ENOUGH TALK  I'LL BE BACK remainder HASTA LA VISTA, BABY

        翻译: 伯乐在线 - 黄利民

        译文链接: http://blog.jobbole.com/60440/