📄 frmcifa.frm
字号:
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 345
Left = 5640
TabIndex = 7
Top = 120
Width = 1875
End
Begin VB.Line Line14
X1 = 5280
X2 = 5280
Y1 = 2520
Y2 = 2160
End
Begin VB.Line Line13
X1 = 7080
X2 = 5280
Y1 = 2520
Y2 = 2520
End
Begin VB.Line Line12
X1 = 7080
X2 = 7080
Y1 = 2160
Y2 = 2520
End
Begin VB.Line Line11
X1 = 7080
X2 = 7080
Y1 = 1560
Y2 = 2160
End
Begin VB.Line Line10
X1 = 6120
X2 = 7080
Y1 = 1560
Y2 = 1560
End
Begin VB.Line Line9
X1 = 5280
X2 = 5280
Y1 = 2160
Y2 = 1560
End
Begin VB.Line Line8
X1 = 3600
X2 = 5520
Y1 = 2160
Y2 = 2160
End
Begin VB.Label Label
Alignment = 2 'Center
AutoSize = -1 'True
BackColor = &H00FFFFC0&
BorderStyle = 1 'Fixed Single
Caption = "读字符"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Index = 1
Left = 3240
TabIndex = 5
Top = 840
Width = 765
End
Begin VB.Label Label
Alignment = 2 'Center
AutoSize = -1 'True
BackColor = &H00FFFFC0&
BorderStyle = 1 'Fixed Single
Caption = "是空字符? "
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Index = 2
Left = 3090
TabIndex = 4
Top = 1440
Width = 1215
End
Begin VB.Label LabelChar
Alignment = 2 'Center
AutoSize = -1 'True
BackColor = &H0000FFFF&
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 345
Left = 5955
TabIndex = 3
Top = 0
Visible = 0 'False
Width = 255
End
Begin VB.Line Line7
X1 = 3600
X2 = 3600
Y1 = 1440
Y2 = 2160
End
Begin VB.Line Line6
X1 = 2520
X2 = 3600
Y1 = 600
Y2 = 600
End
Begin VB.Line Line5
X1 = 2520
X2 = 2520
Y1 = 1560
Y2 = 600
End
Begin VB.Line Line4
X1 = 3600
X2 = 2520
Y1 = 1560
Y2 = 1560
End
Begin VB.Line Line2
X1 = 3600
X2 = 3600
Y1 = 840
Y2 = 1440
End
Begin VB.Line Line1
X1 = 3600
X2 = 3600
Y1 = 480
Y2 = 840
End
Begin VB.Label Label1
AutoSize = -1 'True
BackColor = &H0080C0FF&
BorderStyle = 1 'Fixed Single
Caption = "输入TEST程序:"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 345
Index = 0
Left = 240
TabIndex = 1
Top = 0
Width = 2235
End
Begin VB.Menu mmnu0
Caption = "词法规则"
End
Begin VB.Menu mnu1
Caption = "语法规则"
End
Begin VB.Menu mnu3
Caption = "语义规则"
End
Begin VB.Menu mnu2
Caption = "抽象机指令"
End
Begin VB.Menu mnu4
Caption = "代码输出"
End
Begin VB.Menu mnuYuFa
Caption = "语法分析"
End
Begin VB.Menu mnuYuYi
Caption = "语义分析"
End
Begin VB.Menu mnuEnd
Caption = "结束"
End
End
Attribute VB_Name = "frmCiFa"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim currentpos As Long
Dim CurrentChar As String
Dim currentStr As String
Dim s As Long
Public Function GetNextChar(currentpos As Long) As String '获取当前位置的字符
currentpos = currentpos + 1
Source.SelStart = currentpos
Source.SelLength = 1
GetNextChar = LCase$(Source.SelText)
End Function
Public Sub MoveChar(Line As Line) '获取当前位置的字符
Dim l As Integer
LabelChar.Left = Line.X1 - LabelChar.Width / 2
LabelChar.Top = Line.Y1 - 200
If Line.X2 >= Line.X1 Then
For l = Line.X1 To Line.X2 Step 2
LabelChar.Left = l - LabelChar.Width / 2
Sleep
Next l
Else
For l = Line.X1 To Line.X2 Step -2
LabelChar.Left = l - LabelChar.Width / 2
Sleep
Next l
End If
If Line.Y2 >= Line.Y1 Then
For l = Line.Y1 To Line.Y2 Step 2
LabelChar.Top = l - 200
Sleep
Next l
Else
For l = Line.Y1 To Line.Y2 Step -2
LabelChar.Top = l - 200
Sleep
Next l
End If
End Sub
Private Sub comCiFaBegin_Click()
mnuYuFa.Enabled = False
mnuYuYi.Enabled = False
mnuEnd.Enabled = False
comCiFaBegin.Enabled = False
Source.SetFocus
LabelChar.Caption = ""
LabelChar.Visible = True
LabelStr.ZOrder
LabelChar.ZOrder
lstToken.Clear
MoveChar Line1
currentpos = -1 '设当前处理的字符位置为-1
Do While currentpos < Len(Source.Text) - 1
txtCurrentStr = ""
LabelStr.Caption = ""
currentStr = ""
CurrentChar = GetNextChar(currentpos) '获取下一个的字符
LabelChar.Caption = CurrentChar
MoveChar Line2
Do While CurrentChar = "" Or CurrentChar = " " Or CurrentChar = Chr$(13) Or CurrentChar = Chr$(10)
MoveChar Line4
MoveChar Line5
MoveChar Line6
CurrentChar = GetNextChar(currentpos) '获取下一个的字符
If currentpos = Len(Source.Text) - 1 Then Exit Do
LabelChar.Caption = CurrentChar
MoveChar Line2
Loop
If currentpos = Len(Source.Text) - 1 Then Exit Do
Select Case CurrentChar
Case "a" To "z", "A" To "Z" '标识符处理
MoveChar Line7
MoveChar Line8
currentStr = currentStr & CurrentChar '将当前字符接到当前字符串的后面
txtCurrentStr.Text = currentStr
MoveChar Line9
MoveChar Line3
CurrentChar = GetNextChar(currentpos) '获取下一个的字符
LabelChar.Caption = CurrentChar
MoveChar Line10
MoveChar Line11
Do While IsNumeric(CurrentChar) Or (CurrentChar >= "a" And UCase$(CurrentChar) <= "z")
MoveChar Line12
MoveChar Line13
MoveChar Line14
currentStr = currentStr & CurrentChar
txtCurrentStr.Text = currentStr
LabelChar.Caption = CurrentChar
MoveChar Line9
MoveChar Line3
CurrentChar = GetNextChar(currentpos) '获取下一个的字符
LabelChar.Caption = CurrentChar
MoveChar Line10
MoveChar Line11
Loop
CurrentChar = GetPreChar(currentpos)
LabelStr.Visible = True
LabelChar.Visible = False
LabelStr.Caption = currentStr
MoveStr Line15
Dim i As Integer
Dim isKeyWord As Boolean
isKeyWord = False
For i = 0 To lstKeyWord.ListCount - 1
If currentStr = Trim$(Left$(lstKeyWord.List(i), 10)) Then
lstKeyWord.ListIndex = i
lstToken.AddItem currentStr
lstToken.ListIndex = lstToken.ListCount - 1
MoveStr Line16
isKeyWord = True
Exit For
End If
Next i
If Not isKeyWord Then
lstToken.AddItem "ID" & Space(10) & currentStr '标识符的记号为ID
lstToken.ListIndex = lstToken.ListCount - 1
MoveStr Line17
End If
Case "0" To "9" '数字处理
MoveChar Line7
MoveChar Line21
MoveChar Line22
currentStr = currentStr & CurrentChar '将当前字符接到当前字符串的后面
txtCurrentStr.Text = currentStr
MoveChar Line23
MoveChar Line24
CurrentChar = GetNextChar(currentpos) '获取下一个的字符
LabelChar.Caption = CurrentChar
MoveChar Line25
MoveChar Line26
Do While IsNumeric(CurrentChar)
MoveChar Line27
MoveChar Line28
MoveChar Line29
currentStr = currentStr & CurrentChar
txtCurrentStr.Text = currentStr
LabelChar.Caption = CurrentChar
MoveChar Line23
MoveChar Line24
CurrentChar = GetNextChar(currentpos) '获取下一个的字符
LabelChar.Caption = CurrentChar
MoveChar Line25
MoveChar Line26
Loop
CurrentChar = GetPreChar(currentpos)
LabelStr.Visible = True
LabelChar.Visible = False
'整数的记号为NUM
lstToken.AddItem "NUM" & Space(5) & currentStr
lstToken.ListIndex = lstToken.ListCount - 1
LabelStr.Caption = currentStr
MoveStr Line30
'纯单分界符
Case "+", "-", "*", "(", ")", "{", "}", ";", ",", ":"
MoveSingleWord
Case "=", ">", "<", "!"
MoveDoubleWord
Case "/"
MoveChar Line7
MoveChar Line21
MoveChar Line31
MoveChar Line33
MoveChar Line39
currentStr = CurrentChar
LabelStr.Caption = currentStr
txtCurrentStr.Text = currentStr
MoveChar Line40
CurrentChar = GetNextChar(currentpos)
LabelChar.Caption = CurrentChar
MoveChar Line41
If CurrentChar <> "*" Then
LabelStr.Visible = True
LabelChar.Visible = False
CurrentChar = GetPreChar(currentpos)
LabelStr.Caption = currentStr
lstToken.AddItem currentStr
lstToken.ListIndex = lstToken.ListCount - 1
MoveStr Line42
Else '注释处理
currentStr = currentStr & CurrentChar
txtCurrentStr.Text = currentStr
Dim NextChar As String
MoveChar Line43
CurrentChar = GetNextChar(currentpos)
currentStr = currentStr & CurrentChar
txtCurrentStr.Text = currentStr
LabelChar.Caption = CurrentChar
MoveChar Line44
NextChar = GetNextChar(currentpos)
currentStr = currentStr & CurrentChar
txtCurrentStr.Text = currentStr
LabelChar.Caption = NextChar
MoveChar Line45
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -