AURELSOFT Tuesday, 2017-09-19, 11:26 PM
Welcome Guest | RSS
[ New messages · Members · Forum rules · Search · RSS ]
Page 1 of 11
Forum » Test category » Test forum » Jim Klutho Basic (experimental basic)
Jim Klutho Basic
ZlatkoDate: Sunday, 2017-05-28, 6:52 PM | Message # 1
Sergeant
Group: Administrators
Messages: 21
Reputation: 0
Status: Offline
in attchment is zipped version
Attachments: JimK3.o2bas(27Kb)
 
ZlatkoDate: Sunday, 2017-05-28, 6:53 PM | Message # 2
Sergeant
Group: Administrators
Messages: 21
Reputation: 0
Status: Offline
Here is image of AurelEdit
Attachments: 2649936.png(109Kb)
 
ZlatkoDate: Sunday, 2017-05-28, 7:00 PM | Message # 3
Sergeant
Group: Administrators
Messages: 21
Reputation: 0
Status: Offline
This is improved TOKENIZER

'tokenizer aka lexer
! IsAlpha    (byval in as string) as int
! IsDigit    (byval in as string) as int
! IsEquate   (byval in as string) as int
! IsWhite    (byval in as string) as int
! IsComma    (byval in as string) as int
! IsDelimiter(byval in as string) as int
! IsPlus     (byval in as string) as int
! IsMinus    (byval in as string) as int
! IsMulti    (byval in as string) as int
! IsDevide   (byval in as string) as int
'global vars...
string input ,ch ,nextch, tokBuff, pch
string CRLF = chr(13)+chr(10)
dim pos as int
dim inputLen as int
INT TRUE = 1 ,FALSE = 0
INT tokpos=1
String token,tokList[100]
' input string
input = "def a,b ,a2, b=7,c+5 ,d=3.14 "
inputLen = Len(input)                   ' string length
pos = 1                                 ' start position

'loop trough input string reading each char >>>
WHILE pos <= inputLen
ch=""
ch = mid input,pos,1        'current char
nextch = mid input,pos+1,1  'next char

    'test if is letter
    If IsAlpha(ch) = TRUE
        'print ch + " : IS Alpha"
    token = token + ch ' buffering token string
    End if
    'test if is number
    If IsDigit(ch) = TRUE OR ch="."
        'print ch + " : IS Digit"
    token = token + ch ' buffering token string
    End if
  

'/// if is end of token/ is delimiter ` `,`+ ` -` *`/`%

'push alphanum token into tokenList
IF isDelimiter(nextCh)=TRUE AND ( IsAlpha(ch)=TRUE OR IsDigit(ch)=TRUE )  
    tokList [tokpos]= token           ' push token into tokenList
    tokBuff = tokBuff & token  & CRLF ' push token to tokenBuffer
    tokpos=tokpos+1 : token = ""
   'end if
END IF

If isDelimiter(ch) = TRUE
    If isEquate(ch)=TRUE  ' sym =
     token = ch
     tokList [tokpos]= token          
    tokBuff = tokBuff & token  & CRLF
    tokpos=tokpos+1 : token = ""
    End if
    If isPlus(ch)=TRUE  ' sym +
     token = ch
     tokList [tokpos]= token          
    tokBuff = tokBuff & token  & CRLF
    tokpos=tokpos+1 : token = ""
    End if
    If isMinus(ch)=TRUE  ' sym -
     token = ch
     tokList [tokpos]= token          
    tokBuff = tokBuff & token  & CRLF
    tokpos=tokpos+1 : token = ""
    End if
    If isMulti(ch)=TRUE  ' sym *
     token = ch
     tokList [tokpos]= token         
    tokBuff = tokBuff & token  & CRLF
    tokpos=tokpos+1 : token = ""
    End if
    If isDevide(ch)=TRUE  ' sym /
     token = ch
     tokList [tokpos]= token          
    tokBuff = tokBuff & token  & CRLF
    tokpos=tokpos+1 : token = ""
    End if
End if

'if comment then exit loop
If nextch="'" then EXIT WHILE
 

pch = ch ' set p-last char to current char
pos=pos+1 'move to next char in input string
Wend
'<<<
'show token buffer
print tokBuff

 
' /// LEXER SUBROTINES ////////////////////
Sub IsAlpha(string s) as int
int asci : asci = asc(s)
    select asci
        case 65 to 90 'A->Z
         return TRUE
         case 97 to 122 'a->z
         return TRUE
    end select
return FALSE
End Sub

Sub IsDigit(string s) as INT
int asci : asci = asc(s)
    select asci
        case 48 to 57 '0->9
         return TRUE
    end select
return FALSE
End Sub

Sub isDelimiter(string s) as INT
INT chPos
chPos = INSTR(" ,+-*/^%()<>=:",s)
If chPos > 0
    Return TRUE
End If
Return FALSE
End Sub

Sub IsWhite(string s) as INT
int asci: asci = asc(s)
    select asci
        case 32 ' " "->empty space
         return TRUE
         case 0
         return TRUE
    end select
return FALSE
End Sub

Sub IsComma(string s) as INT
int asci: asci = asc(s)
    select asci
        case 44 ' ","-> comma
         return TRUE
    end select
return FALSE
End Sub

Sub IsEquate(string s) as INT
int asci: asci = asc(s)
    select asci
        case 61 ' "="-> equal
         return TRUE
    end select
return FALSE
End Sub

Sub IsPlus(string s) as INT
int asci: asci = asc(s)
    select asci
        case 43 ' "+"-> plus
         return TRUE
    end select
return FALSE
End Sub

Sub IsMinus(string s) as INT
int asci: asci = asc(s)
    select asci
        case 45 ' "-"-> minus
         return TRUE
    end select
return FALSE
End Sub

Sub IsMulti(string s) as INT
int asci: asci = asc(s)
    select asci
        case 42 ' "*"-> multiply
         return TRUE
    end select
return FALSE
End Sub

Sub IsDevide(string s) as INT
int asci: asci = asc(s)
    select asci
        case 47 ' "/"-> devide
         return TRUE
    end select
return FALSE
End Sub
 
Forum » Test category » Test forum » Jim Klutho Basic (experimental basic)
Page 1 of 11
Search:

Copyright MyCorp © 2017Free web hostinguCoz