Plain Script 内部版本

一月 10, 2013 at 12:15 下午Easton

经过近一个月的开发,终于把plain script的内部版本搞定,目前功能基本上满足自己使用

 

【变量类型】

str:字符串类型

strl:字符串可变数组类型

int:64位整数类型

double:双精度小数类型

bool:布尔类型

date: 时间日期类型

 

【基本语法】

var

{

变量声明区域,一个脚本代码文件只能包含一个var区域,code中使用的变量必须在var区域中声明。

(如果不需要用到变量此处可省略)

}

code

{

代码编写区域,一个脚本代码文件只能包含一个code区域。

(此处是必要部分)

}

 

【plain script hello world】

code

{

console("hello world");//“;”可省略,增加“;”主要是C语言情节作怪。

解析器解析代码是一行一行的解析的;

编写脚本代码的时候需要注意不能将多行代码写在一行;

包括{}也需要注意,因此脚本代码原生就不支持类似Java代码的那种{}风格。

{}只能另起一行,如下:

if(表达式)

{

//正确写法。

}

if(表达式){

//错误写法。(由于此写法不方便程序员在没有IDE编辑器辅助的情况下成对区分{},因此并不被解析器识别。)

}

}

 

【Sum】

var

{

    int : num1, num2, sum = 0;

}

code

{

    num1 = 10;

    num2 = 20;

    sum = num1 + num2;

    console("sum = " + sum);

}

 

【for print multiplication table】(for循环)

var

{

    int:i=1,j=1;

}

code

{

    console("demo1-[Print multiplication table]\n");

    for(i=1;i<=9;i=i+1)

    {

        for(j=1;j<=i;j=j+1)

            console(i + "*" + j +  "=" + i * j + "\t");

        console("\n");

    } 

}

 

【while print multiplication table】(while循环)

var

{

    int:i=1,j=1;

}

code

{

    console("demo2-[Print multiplication table]\n");

    while(i<=9)

    {

        j = 1;

        while(j<=i)

        {

            console(i+"*"+j+"="+i*j+"\t");

            j = j + 1;

        }

        console("\n");

        i = i + 1;

    }

}

 

【if】

code

{

    if(1<2)

      if(1>2)

        if(1>2)

         console("abc");

        else

         console("abc2");

      else

        if(1<2)

          console("abc3");

        else

          if(1>2)

            console("abc5");

          else

            console("abc4");

    else

      console("abc6");

    if(1<2)

    {

      if(1>2)

      {

        if(1>2)

         console("abc");

        console("abc4");

        console("abc5");

      }

      else

        console("abc2");

      if(3>2)

      {

        if(4>2)

         console("abc6");

        console("abc7");

        console("abc8");

      }

      else

        console("abc9");

      console("abc4");

      console("abc5");

    }

    else

    {

      console("abc3");

    }

}

 

【strl变量演示】

var

{

  int:len2,i=0;

  strl:list;//声明一个strl类型的变量(可存放字符串数组)

}

code

{

    //调用内置函数strladd为list变量添加数据

    strladd(list,"abc1");

    strladd(list,"abc2");

    strladd(list,"abc3");

    //获取list的长度

    len2 = len(list);

    //遍历list变量

    for(;i<len2;i=i+1)

        console(list[i]+"\n");

}

 

【网页获取与解析实例】

var

{

  //声明str类型的str1变量,并初始化该变量的值为腾讯官方网站首页源代码。

  //gethtml函数以default方式获取www.qq.com首页源代码。

  str:str1=gethtml("http://www.qq.com","d"),str2,str3;

  int:len2,i=0;

  strl:list;

}

code

{

  //解析源代码中以>开头,<结尾的字符串,并将结果存放入list变量。

  list = regrev(str1,">","<",false);

  len2 = len(list);

  for(;i<len2;i=i+1)

    console(list[i]+"\n");//遍历结果

}

Posted in: 技术文章 | 作品展示

Tags: ,

添加评论

  Country flag

biuquote
  • 评论
  • 在线预览
Loading