IVY DOM


 

人生就像一副复杂拼图
每个人总有属於自己的记忆碎片
优质美国空间-老薛主机|IVY DOM|Flowline|

联系我

RSS




七月 16, 2012

[开源]onlinescript开源

语言:易语言

因本人放弃易语言编程 特开源此程序

一.郑重声明:
本程序所有代码均为原创,请不要将本源码用于商业用途!
如果您有兴趣欢迎继续开发本源码,若开发完毕可以发一套给我.

二.技术指导:
首先请看一下我们自己规定的声明布尔型变量的代码:
$bol:[VarNmae]=[true]or[false]
e.t
$bol:r
$bol:c,d
$bol:a=true
$bol:e,f=false
从上面的代码中我们可以看到以下规则:
1.开头必须为$bol
2.变量数据类型和变量名称必须用半角冒号隔开
3.赋值用=连接
4.多变量声明用,隔开
5.赋值的内容必须为true或false

解析流程:
说明:各线程用代号表示[Ⅰ Ⅱ Ⅲ Ⅳ分别代表4种声明方式,L代表单变量声明解析线程,M代表多变量声明解析线程,①代表有赋值操作,②代表无赋值操作](带有”-“的自行组合)
为了防止用户打代码时在前部留空,因此我们只要先用trim()函数删除该段文本的前面与后面的空值再进行解析.
然后再用left()函数寻找前5个文本是否为”$bol:”,若是则用instr()函数取其后文本.这时可能会得到Ⅰ”r”,Ⅱ”c,d”,Ⅲ”a=true”,Ⅳ”e,f=false”
这时候我们把布尔型变量解释器分为2个主线程,①线程解析有赋值的代码,②线程解析无赋值的代码.因为存在①②线程都包括单变量声明解析线程(L)和多变量声明解析线程(M)
区分2个线程检测是否有等于(用instr()函数),有等于进入①线程,无等于的进入②线程.
①线程:Ⅲ Ⅳ
①-L-Ⅲ:以”=”为分割符用split()分割,如果ubound(数组下标)的数值超过2则代表变量名或者值有问题,抛出异常,若等于2则检测分割储存变量的第二个元素值是否为”true”or”false”,若都不是抛出异常.
①-L-Ⅳ:重复①-L-Ⅲ中的分割检测ubound,若没超过2(超过2抛出异常)则以”,”为分割符分割数组元素0.最终目标都是解析出所有变量和值保存到listbox
②线程:Ⅰ Ⅱ
②-L-Ⅰ:直接保存即可
②-M-Ⅱ:以”,”为分隔符分割文本获得各个变量名称,然后保存

以下是完整代码:你需要一个button,1个listbox(改名为var),2个textbox(一个名为codebox,一个名为getbox)
(请尊重作者劳动版权,转载请注明来源:ivysoft.sinaapp.com OR www.64xc.tk OR ivysoft.tk)

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
getbox.Text = ""
var.Items.Clear()
Dim linestr() As String
If codebox.Text <> "" Then
linestr = Split(codebox.Text, Chr(13) + Chr(10))
For i = 0 To UBound(linestr)
InterpreterMachine_Var_bol(linestr(i), i + 1)
Next
End If
End Sub
Function WriteInterpretiInformation(ByVal beaddedtext As String, ByVal line As Integer) As Integer '写解释信息
getbox.Text += beaddedtext + " on line " + line.ToString + Chr(13) + Chr(10)
Return 1
End Function
Function InterpreterMachine_Var_bol(ByVal linecodes As String, ByVal whichline As Integer)
Dim strbeforecode As String
Dim strbehindcode As String
strbeforecode = Mid(linecodes, 1, 5)
strbehindcode = Mid(linecodes, Len(strbeforecode) + 1)
WriteInterpretiInformation("first token=" + strbeforecode + Chr(13) + Chr(10), whichline)
WriteInterpretiInformation("rest token=" + strbehindcode + Chr(13) + Chr(10), whichline)
If strbeforecode = "$bol:" Then
Dim equal As Integer
equal = InStr(strbehindcode, "=")
If equal <> 0 Then
interpret_withequal_var_bol(strbehindcode, whichline)
ElseIf equal = 0 Then
WriteInterpretiInformation("bol var name or liang=" + strbehindcode + Chr(10) + Chr(13), whichline)
Dim whetherhasdhwithoutequal As Integer
whetherhasdhwithoutequal = InStr(strbehindcode, ",")
If whetherhasdhwithoutequal <> 0 Then
Dim dhsplitcode() As String
dhsplitcode = Split(strbehindcode, ",")
For j = 0 To UBound(dhsplitcode)
var.Items.Add(dhsplitcode(j))
Next
ElseIf whetherhasdhwithoutequal = 0 Then
var.Items.Add(strbehindcode)
End If
End If
ElseIf strbeforecode <> "$bol:" Then
'其他事件
End If
Return 1
End Function
Function interpret_withequal_var_bol(ByVal withequalbehindcode As String, ByVal online As Integer) As Integer
Dim whetherhasdhwithequal As Integer
whetherhasdhwithequal = InStr(withequalbehindcode, ",")
If whetherhasdhwithequal <> 0 Then
Dim withdyandequal_behind() As String
Dim withdyandequal_front() As String
withdyandequal_behind = Split(withequalbehindcode, "=")
withdyandequal_front = Split(withdyandequal_behind(0), ",")
If withdyandequal_behind(1) = "true" Or withdyandequal_behind(1) = "false" Then
For k = 0 To UBound(withdyandequal_front)
var.Items.Add(withdyandequal_front(k) + "=" + withdyandequal_behind(1))
Next
ElseIf withdyandequal_behind(1) <> "true" Or withdyandequal_behind(1) <> "false" Then
WriteInterpretiInformation("bol var grammar has gone beyond structure" + Chr(10) + Chr(13), online)
End If
ElseIf whetherhasdhwithequal = 0 Then
Dim withoutdhequalsplit() As String
withoutdhequalsplit = Split(withequalbehindcode, "=")
Dim arrybolubound As Integer
arrybolubound = UBound(withoutdhequalsplit)
WriteInterpretiInformation("bol arry ubound=" + arrybolubound.ToString + Chr(10) + Chr(13), online)
If arrybolubound > 1 Then
WriteInterpretiInformation("bol var grammar was wrong" + Chr(10) + Chr(13), online)
ElseIf arrybolubound = 1 Then
If withoutdhequalsplit(1) = "true" Or withoutdhequalsplit(1) = "talse" Then
var.Items.Add(withoutdhequalsplit(0) + "=" + withoutdhequalsplit(1))
ElseIf withoutdhequalsplit(1) <> "true" Or withoutdhequalsplit(1) <> "talse" Then
WriteInterpretiInformation("bol var grammar has gone beyond structure" + Chr(10) + Chr(13), online)
End If
End If
End If
Return 1
End Function
End Class

以上仅以VB.NET做一个原理介绍

三.作者信息
博客:www.ivysoft.tk
微博:t.qq.com/ivystk

金山快盘下载∶http://www.kuaipan.com.cn/file/id_16658206751195147.htm

相关文章

返回
  1. Looking regarding wedded seeking single web-site, you¡¯ve go to a good option. go here after which enroll in completely free.

  1. 暂无 Trackback

You must be logged in to post a comment.