my name is Cookiesliyr and i would like to share one of my projects with you guys and i want to improve it some how, i hope it will be helpful for everyone, when i was in collage i was only write codes in VB6 and Java (i learned VB6 by myself but the university though me Java) but because i was way much better in VB6 i used it in one of my projects, it was the final project of ICS 410 Concepts of Programming language, the project was simple enough i guess : build a common lisp interpreter.
the time was short and we have more then one class and lab and project at once but i was exited, i liked to build something special, everyone followed the regular way which the book use but i liked to build my on code that's why i build the "String Separator", it was kinda similar to their job but a bit more complicated, to be frank i couldn't finish it, it should save variables in memory and recall them, and some functions weren't finish in time, i tried to complete it once but i was damn lazy to be frank because there is no grade on it anymore.
around 3 weeks ago i decided to finish my old job ... i wanna rebuild this code in more efficient way just like what i told my professor in his office in that day before i start working on it, i wanna build a common interpreter which can be use to make your own language by it and we can use it to give our projects more control in real time this time i wanna rewrite it in C#.
when i opened my old project i found it more complex then i though XD any way i can simply rewrite it but this is not how pro work, i wanna take the idea and improve it but to be frank i always work alone and i don't know what is a good idea and what is not that's why i was looking for brain storming guild or if i can make my own or if i can see some DIC members who have such a guild but allot of members told me "but we have such a thing !" i asked them " Where ?" they simply said "here ! Share your project forum" i said "but ... what ... i mean ... but my work is not complete !" but it is look like this forum has been made for this purpose after all.
now should i tell you my project idea first or should i show you the code ? i guess i should show you the idea first, but that well be written in another post.
===================================================================
the idea is simple i guess, the class well act in three phases
before we use get in details we need to initialize an object of String Separator (we will call it SS for short for now) to use it to interpret the code, then we send the code to it here it start the phase one.
1) First Phase : the code which we have sent will be separated, first we will check the space as you know the code might have extra space or sometimes we need to put a space but the user doesn't (yes the user is the programmer now) for example he might write a code like this "if value1 = 10 then" as you can see he put more then one space after "if" and sometimes he doesn't put space especially after operations symbols like "(1+2)" the SS will see this code as one line that's why we need the space dealer which will remove unwanted space and add them after symbols and make the last code like this " ( 1 + 2 ) "
then we will take each string blocks (yes everything here well be in String format) and save it in a string array and then we will pass it to a function called GetValue to see what is this block represent and save its type in another string array.
so far we have two arrays one save the code blocks and the other the meaning of the block
2) Second Phase : here we will call Body Body ! ahem i mean the Body function, this guy job is simple he will check for us if the body instruction is correct, then he will save some numbers to represent where is the start and the end for each body in the code by using the start of body position and it's length, this code will work recursively , you can see the code might be very simple like " 1 + 2 " or might be damn complex " ( 1 + ( 1 + 2 - ( 3 * 2 ) + ( 4 \ 5) ) + 1 ) - ( 2 * 4 ) + 3 " and don't worry it can be worst you don't know what the craze user will input in the SS ! so we should be ready for him and see his disappointing face after trying to dig a bug in the code and failed,
3) Third Phase : in here we will finally send our code to the Syntax Analyzer which well determine what will it do, this guy is a function which will return a string value, if something messed up it will return its value as an Error message, and if it is correct it will return the result that is needed or nothing if the code need to save a value in memory or whatever so it will return nothing, in any case this guy might work in recursive way too !
the Syntax Analyzer accept a number inside it which is the pointer to the code and it will be used in the string array which keep our code blocks meaning, then it pass it to switch command (it called Select case in VB6) to see what was the keyword in our code if it is "if-statement" then teda teda teda do the work of the If statement, if it is operation (because in common lisp they write the operation first for example ( 1 + 2 ) in lisp is written as (+ 1 2) and so on ) we will do the operation and see the result, if it is a bracket "(" we will call the function again !
when the Analyzer know what is the function it will check if the types are right and the code is in the right instruction so if it is an operation it expect to see two numbers after the operation, so first of all it will call another function called (Isit) function and check if the value of this code function well represent the right keywords and values for example if the code was like " 5 + ( 4 + 3 ) " the Analyzer well be called twice once for the body and the second time for the operation which is outside the body, when the first time is called it will calculated " ( 4 + 3 ) " and return the value of the Analyzer to the other one, the other one will check if it has two numbers again for the operation before it try the operation out , that's why the function return a string it is actually a keyword to itself when it call itself to see if what the body return what we need it or not.
the idea might look simple, it is just like if a normal programmer read his own code or something but when you get to work you will see it is not that easy to make such idea works, now we can take a look on the code, but that's well be in anew post.
===================================================================
[ Public SST(101) As String ' type of key words of SSV , number zero represent the expected syntax Public SSL(100) As Byte ' lenthg of a keyword , number zero represnt how many ssv is there Public SSB(50) As Byte ' this show how many key word in bodys in a line , we have 50 body max in one line Public SBL(50) As Byte ' this shiw the body sequance in a command Dim BN As Byte ' Number of bodys found in syntaxana Dim Syn As Byte ' Number of how many syntax has been called as nasted Dim i As Integer ' for some loop it jumbs from one to other while we need to continue the looping , thats why they have common value Dim SyntaxValue As Variant ' it saves the value of the last syntaxana() value Dim TempP As Integer ' common temprore pointer , it is used by budy + syntax ( cdr ) Dim TempB As Boolean ' common temprore boolean value Public DebugMode As Boolean ' to give all the results or not Public xNN As Integer ' to save values of SSV instade of sending them , it will be later save the total number of key words so it can replace the array length to it ! Dim MyMemory(2, 20) As String ' this array will save the Varibles names , values and type
' This function get a word and return it its type ( key word ) , it is mainly
' used by syntaxana () and IsIt () functions
Function GetValue(WhatIsIT As Variant) As String
Dim c1 As Boolean, c2 As Boolean
Dim v As Variant
c1 = False
c2 = False
WhatIsIT = Trim(WhatIsIT)
WhatIsIT = LCase(WhatIsIT)
v = LCase(WhatIsIT)
'v = Trim(v) not needed
Select Case v
Case "(":
GetValue = "Open-L"
Case ")":
GetValue = "Open-R"
Case "+", "-", "*", "\":
GetValue = "Operation"
Case "'":
GetValue = "Quate"
Case "#t", "#f":
GetValue = "Boolean"
Case ">", "<", ">=", "<=", "=", "<>":
GetValue = "Relational-Operation"
Case "if":
GetValue = "If-Stat"
Case "then":
GetValue = "Then-Part"
Case "else":
GetValue = "Else-Part"
Case "define":
GetValue = "Define"
Case "and", "or", "not":
GetValue = "Boolean-Operation"
Case "set":
GetValue = "Set"
Case "car":
GetValue = "F-car"
Case "cdr":
GetValue = "F-cdr"
Case "list":
GetValue = "List-Function"
Case "null?":
GetValue = "Null?"
Case "equal?":
GetValue = "Equal?"
Case "length":
GetValue = "Length"
Case "display":
GetValue = "Display"
Case "ismember":
GetValue = "IsMember"
Case "member":
GetValue = "Member"
Case "cons":
GetValue = "Cons"
Case "append":
GetValue = "Append"
Case "let":
GetValue = "Let-Function"
Case Else:
If isNumber(v) Then
GetValue = "Number"
ElseIf Left(v, 1) = """" And Right(v, 1) = """" Then
GetValue = "String"
Else
GetValue = "Variable"
End If
End Select
End Function
' This sub will take the entered code and make several checks
' and spaces places , then it will take the words and send
' them to the getvalue function which will return its meaning , then it will save them
' in two arrays , one for the meaning and the other as the value it self
' by the way , this is the main function , the program start with it
Public Sub SSeprater(ST1 As Variant, Optional b As Boolean)
Dim ST2 As String
xNN = 1
SSL(0) = 0
For i = 1 To 100
SSV(i) = ""
SST(i) = ""
Next i
If ST1 = "" Then Exit Sub:
'-------------- Space Dealer
For j = 1 To Len(ST1)
Select Case Mid(ST1, j, 1)
Case "-", "+", "*", "\", "(", ")", "'":
If j <= 1 Then GoTo 10:
If Mid(ST1, j - 1, 1) = " " And Mid(ST1, j + 1, 1) = " " Then
GoTo 11
ElseIf Not Mid(ST1, j - 1, 1) = " " And Mid(ST1, j + 1, 1) = " " Then
ST2 = ST2 + " " + Mid(ST1, j, 1)
ElseIf Mid(ST1, j - 1, 1) = " " And Not Mid(ST1, j + 1, 1) = " " Then
ST2 = ST2 + Mid(ST1, j, 1) + " "
ElseIf Not Mid(ST1, j - 1, 1) = " " And Not Mid(ST1, j + 1, 1) = " " Then
ST2 = ST2 + " " + Mid(ST1, j, 1) + " "
End If
If 1 = 2 Then
10: If Mid(ST1, j + 1, 1) = " " Then
ST2 = ST2 + Mid(ST1, j, 1)
Else
ST2 = ST2 + " " + Mid(ST1, j, 1)
End If
End If
Case " ":
If Mid(ST1, j + 1, 1) = " " Then
Else
ST2 = ST2 + " "
End If
Case Else
11: ST2 = ST2 + Mid(ST1, j, 1)
End Select
Next j
'-------------- String seprater
SSV(0) = CStr(ST2 + " ;")
For i = 1 To 100
If Len(SSV(0)) <= 2 Then GoTo en:
For j = 1 To Len(SSV(0))
If j = 1 And Mid(SSV(0), 1, 1) = " " Then
SSV(0) = Right(SSV(0), Len(SSV(0)) - 1)
ElseIf Mid(SSV(0), j, 1) = " " Then
SSV(xNN) = Trim(Left(SSV(0), j))
SST(xNN) = GetValue(SSV(xNN))
SSL(i) = Len(SSV(xNN))
SSV(0) = Right(SSV(0), Len(SSV(0)) - (SSL(i)))
xNN = xNN + 1
j = 0
ElseIf SSV(0) = ";" Then GoTo en:
End If
Next j
Next i
en:
'-------------- calling the rest methods
For j = 0 To 50
SBL(j) = 0
SSB(j) = 0
Next j
SSL(0) = xNN
TempB = True
TempP = 0
BN = 0
Body 0
If Not BN = 0 Then
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : error in the Brackets format "
Exit Sub
End If
TempP = 0
Syn = 0
If SyntaxAna(1) = "error" Then MsgBox "Error : unknow error happen", vbOKOnly + vbCritical, "error"
End Sub
' This my friend is the body body ! he makes the bodys structuer for us
' it save recusivly in SSB array the body length and SBL array the sequance of the
' body
Public Function Body(NOB As Byte)
If TempB = False Then Exit Function
For K = 1 To SSL(0)
If SST(K) = "Open-L" Then
BN = BN + 1
For j = 1 To SSL(0)
If SBL(j) = 0 Then
SBL(j) = BN
Exit For
End If
Next j
'SBL(NOB + 1) = BN
'Body (NOB + 1)
NOB = NOB + 1
ElseIf SST(K) = "Open-R" Then
If BN <= 0 Then
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : error in the Brackets format "
TempB = False
'Exit Function
Else
BN = BN - 1
For j = 1 To SSL(0)
If SBL(j) = 0 Then
SBL(j) = BN
Exit For
End If
Next j
'SBL(NOB + 1) = BN
NOB = NOB + 1
'Exit Function
End If
ElseIf Not SSV(K) = "" Then
SSB(NOB) = SSB(NOB) + 1
End If
Next K
End Function
' this function will take the a keyword from a postion and analyze what
' to do next , it will return the final type value and save it in Syntaxvalue varible
' as the last found value in this function , it depand on IsIt ( int , int ) function
Public Function SyntaxAna(SyntaxStart As Integer) As String
Syn = Syn + 1
Select Case SST(SyntaxStart)
Case "Open-L"
BN = BN + 1
If SyntaxAna(SyntaxStart + 1) = "error" Then MsgBox "Error : Syntax error happen", vbOKOnly + vbCritical, "error"
Case "F-car":
SST(0) = isit(SyntaxStart + 1, SSB(SBL(BN + 1)) + SyntaxStart + 1)
If SSB(SBL(BN)) >= 2 Then SSB(SBL(BN)) = SSB(SBL(BN)) - 2
If SST(0) = "List" Then
SyntaxValue = SSV(SyntaxStart + 3)
SyntaxAna = "Chart"
BuildBody SyntaxStart - 1, SyntaxStart
BuildBody SyntaxStart, SyntaxStart
BuildBody SyntaxStart + 1, SyntaxStart + 1 + SSB(SBL(BN)) + 2
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : car function should have List after it " + vbNewLine
Exit Function
End If
GoTo en:
Case "F-cdr":
SST(0) = isit(SyntaxStart + 1, SSB(SBL(BN + 1)) + SyntaxStart + 1)
If SST(0) = "List" Then
SyntaxValue = "("
For j = SyntaxStart + 4 To SSB(SBL(BN)) + SyntaxStart + 3 - 1
SyntaxValue = SyntaxValue & " " & SSV(j) & " "
Next j
SyntaxValue = SyntaxValue + ")"
If SSB(SBL(BN)) >= 2 Then SSB(SBL(BN)) = SSB(SBL(BN)) - 1
BuildBody SyntaxStart - 1, SyntaxStart
BuildBody SyntaxStart + 1, SyntaxStart + 1
If SyntaxValue = "( )" Then
SyntaxAna = "Empty-List"
Else
SyntaxAna = "List"
TempP = TempP + 1
End If
GoTo en:
ElseIf SST(0) = "Empty-List" Then
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : the list is empty " + vbNewLine
Exit Function
ElseIf SST(0) = "Chart" Then
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : cdr function should have List after it Not a chart" + vbNewLine
Exit Function
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : cdr function should have List after it " + vbNewLine
Exit Function
End If
Case "Member":
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SSB(SBL(BN)) >= 2 Then SSB(SBL(BN)) = SSB(SBL(BN)) - 2
If SST(0) = "Number" Or SST(0) = "Chart" Or SST(0) = "List" Then
Dim TempS As String, TempS2 As String
If SST(0) = "Number" Then
TempS = SSV(SyntaxStart + 1)
i = 2
ElseIf SST(0) = "Chart" Then
TempS = SSV(SyntaxStart + 2)
i = 3
ElseIf SST(0) = "List" Then
For i = SyntaxStart + 4 To SyntaxStart + 4 + SSB(SBL(BN - 1))
TempS = TempS + SSV(i)
Next i
End If
SST(0) = isit(SyntaxStart + i, SSB(SBL(BN)) + SyntaxStart + i)
If SST(0) = "List" Then
For j = SyntaxStart + i + 2 To SyntaxStart + SSB(SBL(BN) + 1) + i + 1
TempS2 = TempS2 + SSV(j)
Next j
TempP = InStr(TempS2, TempS) + 1
If TempP = 1 Then
SyntaxAna = "Empty-List"
GoTo en:
End If
SyntaxValue = "("
For j = SyntaxStart + TempP + i To SyntaxStart + i + TempP + (SSB(SBL(BN - 1)) - TempP) + 1
SyntaxValue = SyntaxValue & " " & SSV(j) & " "
Next j
SyntaxValue = SyntaxValue + ")"
SyntaxAna = "List"
BuildBody SyntaxStart, SyntaxStart - 2
BuildBody SyntaxStart + 2, SyntaxStart
TempP = TempP + 1
GoTo en:
ElseIf SST(0) = "Empty-List" Then
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : the list is empty " + vbNewLine
Exit Function
ElseIf SST(0) = "Chart" Then
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : Member function should have a number or a list or a chart then another List after it Not a chart" + vbNewLine
Exit Function
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : Member function should have a number or a list or a chart then another List after it " + vbNewLine
Exit Function
End If
End If
Case "Operation", "Relational-Operation":
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "Number" Or GetValue(SyntaxValue) = "Number" Then
SST(0) = isit(SyntaxStart + 2, SyntaxStart + 3)
If SST(0) = "Number" Or GetValue(SyntaxValue) = "Number" Then
Select Case SSV(SyntaxStart)
Case "+": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) + CDbl(SSV(SyntaxStart + 2))
Case "-": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) - CDbl(SSV(SyntaxStart + 2))
Case "*": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) * CDbl(SSV(SyntaxStart + 2))
Case "\": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) \ CDbl(SSV(SyntaxStart + 2))
Case ">": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) > CDbl(SSV(SyntaxStart + 2))
Case "<": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) < CDbl(SSV(SyntaxStart + 2))
Case ">=": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) >= CDbl(SSV(SyntaxStart + 2))
Case "<=": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) <= CDbl(SSV(SyntaxStart + 2))
Case "=": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) = CDbl(SSV(SyntaxStart + 2))
Case "<>": SyntaxValue = CDbl(SSV(SyntaxStart + 1)) <> CDbl(SSV(SyntaxStart + 2))
End Select
If SyntaxValue = "True" Then SyntaxValue = "#t"
If SyntaxValue = "False" Then SyntaxValue = "#f"
If SST(SyntaxStart) = "Operation" Then
SyntaxAna = "Number"
ElseIf SST(SyntaxStart) = "Relational-Operation" Then
SyntaxAna = "Boolean"
End If
BuildBody SyntaxStart - 1, SyntaxStart
BuildBody SyntaxStart, SyntaxStart + 1
SSV(SyntaxStart - 1) = SyntaxValue
GoTo en:
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : operations must have two numbers" + vbNewLine
Exit Function
End If
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : operations must have two numbers" + vbNewLine
Exit Function
End If
Case "Boolean-Operation":
SST(0) = isit(SyntaxStart + 1, SSB(SBL(BN)) + SyntaxStart + 1)
If SST(0) = "Boolean" Then
If SSV(SyntaxStart) = "not" Then
If SyntaxValue = "#t" Then TempB = False
If SyntaxValue = "#f" Then temb = True
BuildBody SyntaxStart - 1, SyntaxStart
BuildBody SyntaxStart, SyntaxStart + 1
Else
SST(0) = isit(SyntaxStart + 2, SSB(SBL(BN)) + SyntaxStart + 2)
If SST(0) = "Boolean" Then
Select Case SSV(SyntaxStart)
Case "and": TempB = (SSV(SyntaxStart + 1)) = (SSV(SyntaxStart + 2))
Case "or": TempB = ((SSV(SyntaxStart + 1) = "#t") Or (SSV(SyntaxStart + 2) = "#t"))
End Select
BuildBody SyntaxStart - 1, SyntaxStart
BuildBody SyntaxStart, SyntaxStart + 1
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : Boolean Operations must have two Boolean" + vbNewLine
Exit Function
End If
End If
If TempB = True Then SyntaxValue = "#t"
If TempB = False Then SyntaxValue = "#f"
SyntaxAna = "Boolean"
SSV(SyntaxStart - 1) = SyntaxValue
GoTo en:
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : Boolean Operations ( except not ) must have two Boolean" + vbNewLine
Exit Function
End If
Case "List-Function"
SyntaxValue = "( "
For j = SyntaxStart + 1 To SSB(SBL(BN)) + SyntaxStart - 1 ' + 1 - 2
SST(0) = isit(j + 0, j + 1)
Select Case SST(0)
Case "Number"
SyntaxValue = SyntaxValue & " " & SSV(j) & " "
Case "Chart"
SyntaxValue = SyntaxValue & " " & SSV(j + 1) & " "
j = j + 1
Case "List"
For K = j To SSB(SBL(BN - 1)) + j
SyntaxValue = SyntaxValue & " " & SSV(K) & " "
Next K
SyntaxValue = SyntaxValue + ")"
Case Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error : List function accept only numbers , charts and lists "
SyntaxAna = "Error"
Exit Function
Exit Function
End Select
Next j
SyntaxValue = SyntaxValue + ")"
SyntaxAna = "List"
BuildBody SyntaxStart, SyntaxStart
For j = SyntaxStart To SSB(SBL(BN - 4)) + SyntaxStart - 1
If SST(j) = "Quate" Then
BuildBody j + 0, j + 0
End If
Next j
GoTo en:
Case "Null?":
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "NULL" Then
SyntaxValue = "#t"
Else
SyntaxValue = "#f"
End If
SyntaxAna = "Boolean"
SSV(SyntaxStart - 1) = SyntaxValue
BuildBody SyntaxStart - 1, SyntaxStart
BuildBody SyntaxStart, SyntaxStart + 2
GoTo en:
Case "Length":
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "List" Then
SyntaxValue = SSB(SBL(BN))
SyntaxAna = "Number"
SST(SyntaxStart - 1) = "Number"
BuildBody SyntaxStart, SyntaxStart + SSB(SBL(BN)) + 4
SSV(SyntaxStart - 1) = SyntaxValue
GoTo en:
Else
SyntaxAna = "Error"
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine & "Error: Length function excpect a List after it"
Exit Function
End If
Case "IsMember":
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "Number" Then
SST(0) = isit(SyntaxStart + 2, SyntaxStart + 3)
If SST(0) = "List" Then
SyntaxAna = "Boolean"
SyntaxValue = "#f"
For j = SyntaxStart + 4 To SyntaxStart + 4 + SSB(SBL(BN - 1))
If SSV(j) = SSV(SyntaxStart + 1) Then SyntaxValue = "#t"
Next j
BuildBody SyntaxStart - 1, SyntaxStart + SSB(SBL(BN)) + 4
SSV(SyntaxStart - 1) = SyntaxValue
GoTo en:
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine & "Error: Member function excpect a number then a list after it"
Exit Function
End If
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine & "Error: Member function excpect a number then a list after it"
Exit Function
End If
Case "Display":
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "String" Then
GoTo en:
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + ("Error : can only display Strings ")
Exit Function
End If
Case "If-Stat":
For i = SyntaxStart + 2 To SSL(0)
If SST(i) = "Then-Part" Then GoTo FoundThenPart:
Next i
GoTo MissingThenPart:
FoundThenPart:
SST(0) = isit(SyntaxStart + 1, i)
If SST(0) = "Boolean" Then
If SyntaxValue = "#t" Then If SyntaxAna(4) = "Error" Then Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: If statement without then part"
For K = i To SSL(0)
If SST(K) = "Else-Part" Then GoTo elsepartfound:
Next K
GoTo en:
elsepartfound: If SyntaxValue = "#f" Then If SyntaxAna(K + 1) = "Error" Then Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: in the statement after the else part"
If 1 = 2 Then
MissingThenPart: Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: If statement without then part"
Exit Function
End If
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: after If-statement expect a boolean expration"
Exit Function
End If
Case "Cons":
SyntaxValue = ""
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "Chart" Then
SST(0) = isit(SyntaxStart + 3, SyntaxStart + 4)
If SST(0) = "Chart" Then
SyntaxAna = "List"
SyntaxValue = "( " & SSV(SyntaxStart + 2) & " . " & SSV(SyntaxStart + 4) + " )"
GoTo en:
ElseIf SST(0) = "List" Then
SyntaxValue = "( " + SSV(SyntaxStart + 2)
For j = SyntaxStart + 5 To SyntaxStart + 4 + SSB(SBL(BN - 1))
SyntaxValue = SyntaxValue + " " + SSV(j)
Next j
SyntaxAna = "List"
SyntaxValue = SyntaxValue + " )"
GoTo en:
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: after the chart comes another chart or list"
Exit Function
End If
ElseIf SST(0) = "List" Then
Dim TempS3 As String
For i = SyntaxStart + 2 To SyntaxStart + 3 + SSB(SBL(BN - 1))
TempS3 = TempS3 + " " + SSV(i)
Next i
SST(0) = isit(i, i + 1)
If SST(0) = "Chart" Then
SyntaxValue = "( " + TempS3 + " . " + SSV(i + 1) + " )"
ElseIf SST(0) = "List" Then
SyntaxValue = "( " + TempS3 + " "
For j = i + 2 To i + 3 + SSB(SBL(BN))
SyntaxValue = SyntaxValue + " " + SSV(j)
Next j
SyntaxValue = SyntaxValue + " )"
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: after the list comes another chart or list"
Exit Function
End If
Else
SyntaxAna = "List"
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: after cons comes two charts or lists"
Exit Function
End If
GoTo en:
Case "Append"
SyntaxValue = ""
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "List" Then
Dim TempS4 As String
For i = SyntaxStart + 3 To SyntaxStart + 2 + SSB(SBL(BN - 1))
TempS4 = TempS4 + " " + SSV(i)
Next i
SST(0) = isit(i + 1, i + 2)
If SST(0) = "Chart" Then
SyntaxValue = "( " + TempS4 + " . " + SSV(i + 2) + " )"
ElseIf SST(0) = "List" Then
SyntaxValue = "(" + TempS4
For j = i + 3 To i + 3 + SSB(SBL(BN))
SyntaxValue = SyntaxValue + " " + SSV(j)
Next j
SyntaxValue = SyntaxValue + " )"
Else
SyntaxAna = "Error"
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: after append comes a list then a charts or a list"
Exit Function
End If
Else
Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine + "Error: after append comes a list then a charts or a list"
Exit Function
End If
SyntaxAna = "List"
GoTo en:
Case "Equal?":
SST(0) = isit(SyntaxStart + 1, SyntaxStart + 2)
If SST(0) = "List" Then
ElseIf SST(0) = "Chart" Then
If SSV(SyntaxStart + 2) = SSV(SyntaxStart + 4) Then
SyntaxValue = "#t"
Else
SyntaxValue = "#f"
End If
ElseIf SST(0) = "Number" Then
If SSV(SyntaxStart + 1) = SSV(SyntaxStart + 2) Then
SyntaxValue = "#t"
Else
SyntaxValue = "#f"
End If
ElseIf SST(0) = "Varible" Then
Else
End If
SyntaxAna = "Boolean"
GoTo en:
Case "Let-Function"
Case "":
End Select
en:
Syn = Syn - 1
SyntaxValue = Trim(SyntaxValue)
If Syn = 0 Or DebugMode Then Form1.Sheet.Text = Form1.Sheet.Text + vbNewLine & SyntaxValue
If SyntaxAna = "List" Or SyntaxAna = "Chart" Then SyntaxValue = "' " & SyntaxValue
End Function
' This function will check what is the value of the keys thats found in the array
' from the Fist to LaSt ( usally they are X to X + current body length )
' it will depand on syntaxana (int ) if it will face another body
Public Function isit(FiSt As Integer, LaSt As Integer) As String
For K = FiSt To LaSt
Select Case SST(K)
Case "Open-L"
BN = BN + 1
SST(0) = SyntaxAna(K + 1)
isit = SST(0)
If Mid(SSV(K), 1, 1) = "'" Then
SSV(K) = "'"
SST(0) = "Chart"
If SSV(K + 1) = "(" Then SST(0) = "List"
ElseIf Mid(SSV(K), 1, 1) = "#" Then
SSV(K) = SyntaxValue
SST(0) = "Boolean"
Else
SSV(K) = SyntaxValue
SST(0) = GetValue(SyntaxValue)
End If
'isit = SyntaxAna(k + 1)
'SSV(k) = SyntaxValue
'If Mid(SSV(k), 1, 1) = "'" Then SSV(k) = "'"
'SST(0) = GetValue(SyntaxValue)
'BuildBody k + 1, k + SSB(SBL(BN))
Exit Function
Case "Open-R"
isit = "Error: Something is missing"
Case "Quate"
BN = BN + 1
If SST(K + 1) = "Open-L" And Not SST(K + 2) = "Open-R" Then
isit = "List"
ElseIf SST(K + 1) = "Open-L" And SST(K + 2) = "Open-R" Then
isit = "NULL"
Else
isit = "Chart"
End If
Exit Function
Case "Number"
isit = "Number"
Exit Function
Case "Boolean"
isit = "Boolean"
SyntaxValue = SSV(K)
Exit Function
Case "String"
isit = "String"
Exit Function
Case eles: isit = "Error"
End Select
Next K
End Function
' build body is used to rearrange the sst array , when the inner body value is found
' it is replaced by its value and this function will be called to take the rest
' array index into the empty space ( it will calculate the empty space as the last
' body length - 1 ( for the replaced value ) ) ( long note for small function ... funny things can happend ! )
Function BuildBody(FiSt As Integer, LaSt As Integer)
For j = FiSt To SSL(0) - 1
SSV(j) = SSV(j + 1 + (LaSt - FiSt))
SST(j) = SST(j + 1 + (LaSt - FiSt))
Next j
If SSL(0) > FiSt Then SSL(0) = SSL(0) + (FiSt - LaSt - 1)
End Function
Function isNumber(ByVal strString As String) As Boolean
Dim i As Integer
For i = 1 To Len(strString)
If Asc(Mid(strString, i, 1)) < Asc("0") Or Asc(Mid(strString, i, 1)) > Asc("9") Or Asc(Mid(strString, i, 1)) = Asc("-") Then
isNumber = False
Exit Function
End If
Next i
isNumber = True
End Function
as you can see if you don't have a VB6 IDE or not familiar with VB codes you might find it hard to read it in here
any way now i wrote the idea of the code and the code itself, sometimes the idea is right but the code itself is wrong, sometimes your idea is wrong but some how the code is written in a wrong way and it is working (for a god sake advice if this the case delete the code and write another one), i am thankful for your time reading my long post and i would like to hear what do you think, about the idea the principle of the code and the code itself, if you wanna blame me because the code is too long and it should be less by 5 lines because someone wrote it shorter then this by 5 lines, or if you didn't like the idea and think you can say something funny then please send it to me as a private message.
if you think the whole idea is wrong or you didn't like idea itself then feel free to tell us about that, if you have a project and wanna use this idea feel free to do so but please don't just copy the code and say it was your work.
thanks for your time and hope you will like it
This post has been edited by Cookiesliyr: 14 March 2010 - 09:14 AM

New Topic/Question
Reply



MultiQuote






|