Do you know? Codes sometimes just like shit!
implements:program,begin,var,procedure.

ListBox3.Items.Clear()

ListBox4.Items.Clear()

ListBox5.Items.Clear()

ListBox6.Items.Clear()

ListBox3.Items.Add("start compiler.")

''counters

Dim i, j As Integer

''step 1

Dim fp_position As Integer

''set 0

fp_position = 1

''check start line

Dim start_line As Integer

For i = 0 To ListBox2.Items.Count - 1

If Val(ListBox2.Items.Item(i)) = 35 Then

''if ; is missing

If Not Val(ListBox2.Items.Item(i - 1)) = 33 Then

ListBox3.Items.Add("; is missing.")

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

End If

fp_position += 1

End If

If Val(ListBox2.Items.Item(i)) = 1 Then

start_line = i

Exit For

Else

ListBox3.Items.Add("compiler paused at the beginnin

Exit Sub

End If

Next


''check if structure of the label "program" is right.

If Not (Val(ListBox2.Items.Item(start_line)) = 1 Or Val(ListBox2.Items.Item(ListBox2.Items.Count - 1)) = 34) Then

If Not Val(ListBox2.Items.Item(start_line)) = 1 Then

ListBox3.Items.Add("program is missing.")

ElseIf Not Val(ListBox2.Items.Item(ListBox2.Items.Count - 1)) = 34 Then

ListBox3.Items.Add("end point is missing.")

End If

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

Else

ListBox3.Items.Add("structure:program passed.")

End If

''check program name

If Val(ListBox2.Items.Item(start_line + 1)) = 33 Then

ListBox3.Items.Add("label of program is missing.")

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

ElseIf Not Val(ListBox2.Items.Item(start_line + 1)) = 17 Then

ListBox3.Items.Add("name must not be a number.")

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

ElseIf Not Val(ListBox2.Items.Item(start_line + 2)) = 33 Then

ListBox3.Items.Add("; is missing.")

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

Else

TextBox1.Text = ListBox1.Items.Item(start_line + 1)

ListBox3.Items.Add("label:program passed.")

End If

''step 2

''check if structure of the process is right

''does label "begin" or "end" exist?


''save the first newline position.

''as we know, is start_line+3.

Dim fp_newline_position As Integer

fp_newline_position = start_line + 3

fp_position += 1

''save next line position

Dim checkpoint_fp_position As Integer

checkpoint_fp_position = fp_position

''seek begin

Dim begin_line As Integer

begin_line = fp_newline_position

''start seek

ListBox3.Items.Add("seeking begin...")

begin_line += 1

''if begin exist,true;

''else false;

For i = fp_newline_position + 1 To ListBox2.Items.Count

begin_line += 1

If i < ListBox2.Items.Count Then

If Val(ListBox2.Items.Item(i)) = 35 Then

If Not Val(ListBox2.Items.Item(i - 1)) = 33 Then

''if ;is missing

ListBox3.Items.Add("; is missing.")

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

End If

fp_position += 1

End If

If Val(ListBox2.Items.Item(i)) = 4 Then

''seeking 1st begin

ListBox3.Items.Add("1st begin has found at line " & fp_position & ".")

Exit For

End If

ElseIf i = ListBox2.Items.Count Then

''if begin is missing

ListBox3.Items.Add("begin is missing.")

ListBox3.Items.Add("compiler paused at the bottom.")

Exit Sub

End If

Next

''save 1st begin position

Dim first_begin_position As Integer

first_begin_position = fp_position

''restore fp_position

fp_position = checkpoint_fp_position

''analysis gramma from fp_newline_position+1 to begin_line

For i = fp_newline_position + 1 To begin_line - 1

''if newline

If Val(ListBox2.Items.Item(i)) = 35 Then

If Not Val(ListBox2.Items.Item(i - 1)) = 33 Then

''if ; is missing

ListBox3.Items.Add("; is missing.")

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

End If

fp_position += 1

End If

''===================================================

'' if procedure then

'' check if there is a (

'' if there is no (

'' add procedure name to listbox6

'' check ;

'' else

'' add procedure name to listbox6

'' record procedure name

'' check (

'' add var

'' check ,

'' check )

'' check ;

''===================================================

''

'' if not a var or procedure ? ==> fuck off!

''

If Val(ListBox2.Items.Item(i)) = 3 Then

''check if there is a procedure

ListBox3.Items.Add("procedure found at line " & fp_position & ".")

''record i

Dim proc_position As Integer

proc_position = i + 1

''check if there is a (

Dim proc_l As Boolean

proc_l = False

While Val(ListBox2.Items.Item(proc_position)) <> 33 ''seeking ;

If Val(ListBox2.Items.Item(proc_position)) = 30 Then

proc_l = True

Exit While

End If

proc_position += 1

End While

proc_position = i + 1

''if there is no (

If proc_l = False Then

While Val(ListBox2.Items.Item(proc_position)) <> 33 ''seeking ;

If Val(ListBox2.Items.Item(proc_position)) = 17 Then

If ListBox6.Items.Count <> 0 Then

For j = 0 To ListBox6.Items.Count - 1

If ListBox1.Items.Item(proc_position) = ListBox6.Items.Item(j) Then

ListBox3.Items.Add("same procedure name " & ListBox1.Items.Item(proc_position) & ".")

ListBox3.Items.Add("proc error at line " & fp_position & ".")

Exit Sub

End If

Next

End If

ListBox6.Items.Add(ListBox1.Items.Item(proc_position))

ElseIf Val(ListBox2.Items.Item(proc_position)) = 32 Then

If Not Val(ListBox2.Items.Item(proc_position + 1)) = 17 Then

ListBox3.Items.Add("proc error at line " & fp_position & ".")

Exit Sub

End If

End If

proc_position += 1

End While

''if there is a (

ElseIf proc_l = True Then

''save procedure name

Dim proc_name As String

proc_name = ""

''process (

While Val(ListBox2.Items.Item(proc_position)) <> 30 ''seeking (

If Val(ListBox2.Items.Item(proc_position)) = 17 Then

If ListBox6.Items.Count <> 0 Then

For j = 0 To ListBox6.Items.Count - 1

If ListBox1.Items.Item(proc_position) = ListBox6.Items.Item(j) Then

ListBox3.Items.Add("same procedure name " & ListBox1.Items.Item(proc_position) & ".")

ListBox3.Items.Add("proc error at line " & fp_position & ".")

Exit Sub

End If

&n Next

End If

ListBox6.Items.Add(ListBox1.Items.Item(proc_position))

proc_name = ListBox1.Items.Item(proc_position)

ElseIf Val(ListBox2.Items.Item(proc_position)) = 32 Then

If Not Val(ListBox2.Items.Item(proc_position + 1)) = 17 Then

ListBox3.Items.Add("proc error at line " & fp_position & ".")

Exit Sub

End If

End If

proc_position += 1

End While

''process )

While Val(ListBox2.Items.Item(proc_position)) <> 31 ''seeking )

If Val(ListBox2.Items.Item(proc_position)) = 17 Then

If ListBox5.Items.Count <> 0 Then

For j = 0 To ListBox5.Items.Count - 1

If ListBox1.Items.Item(proc_position) = ListBox4.Items.Item(j) And proc_name = ListBox5.Items.Item(j) Then

ListBox3.Items.Add("same&nname " & ListBox1.Items.Item(proc_position) & " in procedure " & proc_name & ".")

ListBox3.Items.Add("proc error at line " & fp_position & ".")

Exit Sub

End If

Next

End If

ListBox4.Items.Add(ListBox1.Items.Item(proc_position))

ListBox5.Items.Add(proc_name)

ElseIf Val(ListBox2.Items.Item(proc_position)) = 32 Then

If Not Val(ListBox2.Items.Item(proc_position + 1)) = 17 Then

ListBox3.Items.Add("proc error at line " & fp_position & ".")

Exit Sub

End If

End If

proc_position += 1

End While

End If

i = proc_position

ElseIf Val(ListBox2.Items.Item(i)) = 2 Then

''check if there is a var

ListBox3.Items.Add("var found at line " & fp_position & ".")

''record i

Dim var_position As Integer

var_position = i + 1

While Val(ListBox2.Items.Item(var_position)) <> 33

If Val(ListBox2.Items.Item(var_position)) = 17 Then

If ListBox5.Items.Count <> 0 Then

For j = 0 To ListBox5.Items.Count - 1

If ListBox1.Items.Item(var_position) = ListBox4.Items.Item(j) And ListBox5.Items.Item(j) = "-1" Then

ListBox3.Items.Add("same var name " & ListBox1.Items.Item(var_position) & " in main.")

ListBox3.Items.Add("proc error at line " & fp_position & ".")

Exit Sub

End If

Next

End If

ListBox4.Items.Add(ListBox1.Items.Item(var_position))

ListBox5.Items.Add("-1")

ElseIf Val(ListBox2.Items.Item(var_position)) = 32 Then

If Not Val(ListBox2.Items.Item(var_position + 1)) = 17 Then

ListBox3.Items.Add("var error at line " & fp_position & ".")

End If

End If

var_position += 1

End While

i = var_position

End If

Next

''ok, now, where is fp_position?

''begin_line!

fp_position = first_begin_position + 1

''seek end

''make sure that begin-end structure goes right.

ListBox3.Items.Add("seeking end...")

''save end line

Dim end_line As Integer

end_line = 0

For i = begin_line + 1 To ListBox2.Items.Count

If i < ListBox2.Items.Count Then

If Val(ListBox2.Items.Item(i)) = 35 Then

fp_position += 1

ElseIf Val(ListBox2.Items.Item(i)) = 5 Then

''seeking 1st end

end_line = i

ListBox3.Items.Add("end has found at line " & fp_position & ".")

ListBox3.Items.Add("structure:begin+end passed.")

Exit For

End If

ElseIf i = ListBox2.Items.Count Then

''if begin is missing

ListBox3.Items.Add("end is missing.")

ListBox3.Items.Add("compiler paused at line " & fp_position & ".")

Exit Sub

End If

Next

''save end position

Dim end_position As Integer

end_position = fp_position

''ok ,we just find out 1st begin-end structure.

''what about multiple situation?