无聊写了个小解释器
只实现了赋值、输出、字符串连接功能,主要用的字典和正则两个对象
谁有兴趣的一起把for、if实现啊 哈哈
[解决办法]
sf~~~
[解决办法]
确实够小的:)
[解决办法]
UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUP
[解决办法]
呵呵,不错不错啊
[解决办法]
真是羡慕啊。
[解决办法]
楼主很强大啊.
[解决办法]
哎!本人初学,感觉楼主太牛了,想跟楼主学习一下,
希望楼主有空的教一下我。
本人QQ:718429464
希望在编程这方面强的人都能指导一下我.
[解决办法]
我这里有一段逆波兰表达式的现实算法,可以计算四则混合运算,调用eval函数
Public Sub Push(Data As String, ByRef SP As String)
SP = SP & Data & ","
End Sub
Public Function Pop(ByRef SP As String) As String
Dim Arr() As String, I As Integer
If Len(SP) = 0 Then
Pop = ""
Else
Arr = Split(SP, ",")
I = UBound(Arr) - 1
SP = Left(SP, Len(SP) - Len(Arr(I)) - 1)
Pop = Arr(I)
End If
End Function
Public Function RPN(Str As String) As String
Dim SP As String, A As String, B As String, C As String, R As String
Dim PA As Integer, PB As Integer
Dim I As Integer, D As Integer
C = Str & "#"
D = Len(C)
R = "0"
For I = 1 To D
A = Mid(C, I, 1)
Select Case A
Case "+", "-", "*", "/", "(", ")", ">", " <", "=", "#"
R = R & IIf(Len(R) > 0, "$", "")
Do
If (Len(SP) = 0) Or (A = "(") Then
If A <> ")" Then SP = SP & A
Exit Do
Else
B = Right(SP, 1)
Select Case A
Case "*", "/"
PA = 4
Case "+", "-"
PA = 3
Case " <", ">", "="
PA = 2
Case "(", ")"
PA = 1
Case Else
PA = 0
End Select
Select Case B
Case "*", "/"
PB = 4
Case "+", "-"
PB = 3
Case " <", ">", "="
PB = 2
Case "(", ")"
PB = 1
Case Else
PB = 0
End Select
If PA > PB Then
SP = SP & A
Exit Do
Else
SP = Left(SP, Len(SP) - 1)
B = Replace(B, "(", "")
R = R & B
End If
End If
Loop
Case Else
R = R & A
End Select
Next
RPN = R
End Function
Public Function Eval(Str As String) As Single
Dim Arr() As String
Dim X As String, SP1 As String, SP2 As String, R As String
Dim CHA As String, CHB As String, CHC As String, CHD As String
Dim C As Integer, D As Integer, I As Integer, J As Integer
X = RPN("0$" & Str)
C = Len(X)
For I = 1 To C
CHA = Mid(X, I, 1)
Select Case CHA
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."
CHB = CHB & CHA
Case "$"
Push CHB, SP1
CHB = ""
Case Else
CHB = Pop(SP1)
CHC = Pop(SP1)
If Len(CHC) = 0 Then CHC = "0"
Select Case CHA
Case "+"
CHD = CStr(CSng(CHC) + CSng(CHB))
Case "-"
CHD = CStr(CSng(CHC) - CSng(CHB))
Case "*"
CHD = CStr(CSng(CHC) * CSng(CHB))
Case "/"
CHD = CStr(CSng(CHC) / CSng(CHB))
Case ">"
CHD = IIf(CSng(CHC) > CSng(CHB), "1", "0")
Case " <"
CHD = IIf(CSng(CHC) < CSng(CHB), "1", "0")
Case "="
CHD = IIf(CSng(CHC) = CSng(CHB), "1", "0")
End Select
Push CHD, SP1
CHB = ""
End Select
Next
Eval = CSng(Pop(SP1))
End Function
实现了变量替换、连接符、十来个命令、系统变量、执行第三方命令等。。。
已经大约写了650行了。。。
解释器写起来就是累啊,字串符处理搞得头都晕。。。
[解决办法]
改用C写吧,才会强大。
[解决办法]
呵呵,使用现成的正则表达式来作为词法分析,自动机省掉了,很巧妙。
[解决办法]
何不用C++写呢,C++能力更强。
[解决办法]
mark
[解决办法]
不错,顶!
[解决办法]
很好很强大!
[解决办法]
学习.....厉害...
[解决办法]
看不到,能不能下载呀?
[解决办法]
学习学习!!
[解决办法]
qianghan
[解决办法]
呵呵,不错不错啊
[解决办法]
顶……
[解决办法]
强悍,还是躲起来接分吧
[解决办法]
厲害.....
[解决办法]
强悍,还是躲起来接分吧
[解决办法]
up !up !up !up !up !up !up !up !
[解决办法]
jf 。。。。。。
[解决办法]
围观 膜拜
[解决办法]
还是躲起来接分吧
[解决办法]
哎 真是
[解决办法]
初来乍到,感觉都是高手啊。。
[解决办法]